Simplify deploy SSH and git authentication #1
@@ -1,4 +1,4 @@
|
|||||||
# CI + Deployment (Gitea Actions, GitHub Actions compatible).
|
# CI + Deployment (Gitea Actions; `gitea.*` is Gitea's name for the GitHub-compatible `github.*` context).
|
||||||
#
|
#
|
||||||
# - test: runs on every push to any branch. Its commit status is what the branch
|
# - test: runs on every push to any branch. Its commit status is what the branch
|
||||||
# protection of main requires, so a PR can only be merged once the tests are green.
|
# protection of main requires, so a PR can only be merged once the tests are green.
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
# SSH_HOST e.g. plenario.gnilebein.de
|
# SSH_HOST e.g. plenario.gnilebein.de
|
||||||
# SSH_PORT optional, default 22
|
# SSH_PORT optional, default 22
|
||||||
# SSH_USER e.g. gnilebein.de
|
# SSH_USER e.g. gnilebein.de
|
||||||
# SSH_FINGERPRINT optional but recommended: SHA256 host key fingerprint (ssh-keygen -lf)
|
|
||||||
# DEPLOY_PATH e.g. /home/gnilebein.de/domains/plenario.gnilebein.de/public_html
|
# DEPLOY_PATH e.g. /home/gnilebein.de/domains/plenario.gnilebein.de/public_html
|
||||||
# PHP_BIN optional, PHP CLI binary (default: auto-detect, must be >= 8.4)
|
# PHP_BIN optional, PHP CLI binary (default: auto-detect, must be >= 8.4)
|
||||||
# COMPOSER_BIN optional, composer command (default: auto-detect, else composer.phar
|
# COMPOSER_BIN optional, composer command (default: auto-detect, else composer.phar
|
||||||
@@ -57,7 +56,7 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
needs: test
|
needs: test
|
||||||
# Deactivated until the repository variable DEPLOY_ENABLED is "true".
|
# Deactivated until the repository variable DEPLOY_ENABLED is "true".
|
||||||
if: vars.DEPLOY_ENABLED == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: vars.DEPLOY_ENABLED == 'true' && gitea.event_name == 'push' && gitea.ref == 'refs/heads/main'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
concurrency:
|
concurrency:
|
||||||
group: deploy-production
|
group: deploy-production
|
||||||
@@ -71,15 +70,15 @@ jobs:
|
|||||||
username: ${{ vars.SSH_USER }}
|
username: ${{ vars.SSH_USER }}
|
||||||
key: ${{ secrets.SSH_KEY }}
|
key: ${{ secrets.SSH_KEY }}
|
||||||
password: ${{ secrets.SSH_PASSWORD }}
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
fingerprint: ${{ vars.SSH_FINGERPRINT }}
|
|
||||||
script_stop: true
|
script_stop: true
|
||||||
script: |
|
script: |
|
||||||
set -eu
|
set -eu
|
||||||
DEPLOY_PATH="${{ vars.DEPLOY_PATH }}"
|
DEPLOY_PATH="${{ vars.DEPLOY_PATH }}"
|
||||||
PHP="${{ vars.PHP_BIN }}"
|
PHP="${{ vars.PHP_BIN }}"
|
||||||
COMPOSER="${{ vars.COMPOSER_BIN }}"
|
COMPOSER="${{ vars.COMPOSER_BIN }}"
|
||||||
REPO_URL="${{ github.server_url }}/${{ github.repository }}.git"
|
REPO_URL="${{ gitea.server_url }}/${{ gitea.repository }}.git"
|
||||||
GIT_AUTH="Authorization: Basic $(printf 'oauth2:%s' '${{ github.token }}' | base64 | tr -d '\n')"
|
# Same URL with the job token as credentials; only passed to fetch, never stored in .git/config.
|
||||||
|
FETCH_URL="${REPO_URL%%://*}://oauth2:${{ gitea.token }}@${REPO_URL#*://}"
|
||||||
|
|
||||||
if [ -z "$DEPLOY_PATH" ] || [ ! -d "$DEPLOY_PATH" ]; then
|
if [ -z "$DEPLOY_PATH" ] || [ ! -d "$DEPLOY_PATH" ]; then
|
||||||
echo "DEPLOY_PATH is not set or does not exist: '$DEPLOY_PATH'" >&2
|
echo "DEPLOY_PATH is not set or does not exist: '$DEPLOY_PATH'" >&2
|
||||||
@@ -132,7 +131,7 @@ jobs:
|
|||||||
git remote add origin "$REPO_URL"
|
git remote add origin "$REPO_URL"
|
||||||
fi
|
fi
|
||||||
git remote set-url origin "$REPO_URL"
|
git remote set-url origin "$REPO_URL"
|
||||||
git -c "http.extraHeader=$GIT_AUTH" fetch --quiet origin '+refs/heads/main:refs/remotes/origin/main'
|
git fetch --quiet "$FETCH_URL" '+refs/heads/main:refs/remotes/origin/main'
|
||||||
git reset --hard origin/main
|
git reset --hard origin/main
|
||||||
echo "Deployed commit: $(git rev-parse --short HEAD)"
|
echo "Deployed commit: $(git rev-parse --short HEAD)"
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user