Files
pi2d/.github/workflows/verify-secrets.yml
T

93 lines
4.0 KiB
YAML

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, <user>!`); it does not push anything.
on:
workflow_dispatch:
permissions:
contents: read
jobs:
tap:
name: homebrew tap token
runs-on: ubuntu-latest
# `secrets` is not a valid context inside `if:` (the parser rejects the whole
# workflow); map it to env at job level and test the env var instead.
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
steps:
- name: not configured
if: env.HOMEBREW_TAP_TOKEN == ''
run: echo "::warning::HOMEBREW_TAP_TOKEN is not set — the packaging job will only print manual instructions"
- name: read access
if: env.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: env.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
env:
AUR_SSH_KEY: ${{ secrets.AUR_SSH_KEY }}
steps:
- name: not configured
if: env.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: env.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"