diff --git a/.github/workflows/verify-secrets.yml b/.github/workflows/verify-secrets.yml new file mode 100644 index 0000000..5b719ed --- /dev/null +++ b/.github/workflows/verify-secrets.yml @@ -0,0 +1,92 @@ +name: verify-secrets + +# Manual diagnostic for the two release secrets, so a broken credential is found +# here instead of half-way through a release (where the packaging job would push +# nothing and the failure would only show up as a missing formula/package). +# +# gh workflow run verify-secrets.yml +# gh run watch +# +# Each job is a no-op (with a ::warning::) when its secret is unset, and fails +# loudly when the secret is set but the credential does not work. +# +# - HOMEBREW_TAP_TOKEN: a fine-grained PAT with `Contents: Read and write` on +# zgs225/homebrew-tap only. Verified with a read (`git ls-remote`) and a write +# (a throwaway branch that is deleted again in the same run). +# - AUR_SSH_KEY: the private half of the key whose public half is registered at +# https://aur.archlinux.org/account. Verified by the ssh welcome banner +# (`Welcome to AUR, !`); it does not push anything. +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + tap: + name: homebrew tap token + runs-on: ubuntu-latest + steps: + - name: not configured + if: secrets.HOMEBREW_TAP_TOKEN == '' + run: echo "::warning::HOMEBREW_TAP_TOKEN is not set — the packaging job will only print manual instructions" + + - name: read access + if: secrets.HOMEBREW_TAP_TOKEN != '' + env: + HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} + run: | + remote="https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/zgs225/homebrew-tap.git" + if ! git ls-remote "$remote" HEAD >/dev/null 2>&1; then + echo "::error::cannot read zgs225/homebrew-tap with HOMEBREW_TAP_TOKEN (expired, wrong repo scope, or missing Contents: Read)" + exit 1 + fi + echo "read ok: token can see zgs225/homebrew-tap" + + - name: write access (throwaway branch) + if: secrets.HOMEBREW_TAP_TOKEN != '' + env: + HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} + run: | + branch="verify-secrets-${GITHUB_RUN_ID}" + remote="https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/zgs225/homebrew-tap.git" + git clone --quiet "$remote" tap + cd tap + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git checkout --quiet -b "$branch" + date -u +"%Y-%m-%dT%H:%M:%SZ" > .verify-probe + git add .verify-probe + git commit --quiet -m "chore: verify-secrets probe ${GITHUB_RUN_ID}" + if ! git push --quiet origin "HEAD:${branch}"; then + echo "::error::HOMEBREW_TAP_TOKEN can read but not write zgs225/homebrew-tap — it needs 'Contents: Read and write'" + exit 1 + fi + echo "write ok: pushed ${branch}" + git push --quiet origin --delete "$branch" + echo "cleanup ok: deleted ${branch} (the tap is back to its previous state)" + + aur: + name: aur ssh key + runs-on: ubuntu-latest + steps: + - name: not configured + if: secrets.AUR_SSH_KEY == '' + run: echo "::warning::AUR_SSH_KEY is not set — the packaging job will only print manual instructions for pi2d-bin" + + - name: key authenticates + if: secrets.AUR_SSH_KEY != '' + env: + AUR_SSH_KEY: ${{ secrets.AUR_SSH_KEY }} + run: | + mkdir -p ~/.ssh + printf '%s\n' "$AUR_SSH_KEY" > ~/.ssh/aur_ed25519 + chmod 600 ~/.ssh/aur_ed25519 + ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts 2>/dev/null || true + banner="$(ssh -i ~/.ssh/aur_ed25519 -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -T aur@aur.archlinux.org 2>&1 || true)" + echo "$banner" + if ! printf '%s' "$banner" | grep -qi "welcome to AUR"; then + echo "::error::AUR_SSH_KEY does not authenticate — is the matching public key uploaded at https://aur.archlinux.org/account ?" + exit 1 + fi + echo "auth ok: key is registered on AUR"