From dbf2025473e1c8f8b169f03cbdc00f8921a26eb2 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Sat, 7 Nov 2026 13:42:57 +0100 Subject: [PATCH] Simplify deploy SSH and git authentication - Drop the SSH host key fingerprint check (SSH_FINGERPRINT) - Use the gitea.* context instead of the github.* alias - Fetch with the job token embedded in the URL instead of an auth header; the origin remote keeps the token-free URL Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/ci.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 8896d04..0a36b1c 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -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 # 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_PORT optional, default 22 # 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 # PHP_BIN optional, PHP CLI binary (default: auto-detect, must be >= 8.4) # COMPOSER_BIN optional, composer command (default: auto-detect, else composer.phar @@ -57,7 +56,7 @@ jobs: deploy: needs: test # 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 concurrency: group: deploy-production @@ -71,15 +70,15 @@ jobs: username: ${{ vars.SSH_USER }} key: ${{ secrets.SSH_KEY }} password: ${{ secrets.SSH_PASSWORD }} - fingerprint: ${{ vars.SSH_FINGERPRINT }} script_stop: true script: | set -eu DEPLOY_PATH="${{ vars.DEPLOY_PATH }}" PHP="${{ vars.PHP_BIN }}" COMPOSER="${{ vars.COMPOSER_BIN }}" - REPO_URL="${{ github.server_url }}/${{ github.repository }}.git" - GIT_AUTH="Authorization: Basic $(printf 'oauth2:%s' '${{ github.token }}' | base64 | tr -d '\n')" + REPO_URL="${{ gitea.server_url }}/${{ gitea.repository }}.git" + # 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 echo "DEPLOY_PATH is not set or does not exist: '$DEPLOY_PATH'" >&2 @@ -132,7 +131,7 @@ jobs: git remote add origin "$REPO_URL" fi 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 echo "Deployed commit: $(git rev-parse --short HEAD)"