diff --git a/.github/workflows/fleet-sync.yml b/.github/workflows/fleet-sync.yml index cf888df..9959969 100644 --- a/.github/workflows/fleet-sync.yml +++ b/.github/workflows/fleet-sync.yml @@ -24,8 +24,9 @@ name: fleet-sync # sync-fanout.yml — see GITHUB-APP-AUTH.md). That is a non-GITHUB_TOKEN identity, so the PR's # checks run and it can actually be merged. (A legacy FLEET_SYNC_TOKEN PAT used to sit between # the two; it was deleted when G2 finished — dotfiles-core #683/#819 — so that rung is gone.) -# If the App is NOT configured we fall back to GITHUB_TOKEN — the PR still opens (no hard failure), -# it just won't auto-trigger CI until a human nudges it, exactly the old behaviour. +# If the App is NOT configured we fall back to GITHUB_TOKEN — the PR still opens, it just won't +# auto-trigger CI until a human nudges it — and the metrics job's last step then fails the run, +# so a missing install or un-shared key is a red run rather than a quietly BLOCKED PR. # create-github-app-token is GitHub's own action, SHA-pinned (no untrusted marketplace action). # A fixed branch keeps it idempotent (update, don't stack). @@ -356,7 +357,7 @@ jobs: # Presence flag for the App private key (value is 'true'/'false', never the key): # secrets can't be tested in a step `if:`, but an env derived from a secret comparison # can. Gates the mint on the key ACTUALLY being present so a partial App setup (the - # FLEET_APP_ID variable set org-wide but the key not scoped here) falls back cleanly. + # FLEET_APP_CLIENT_ID variable set org-wide but the key not scoped here) falls back cleanly. HAS_APP_KEY: ${{ secrets.FLEET_APP_PRIVATE_KEY != '' }} steps: # Check the site into a subdir so the rest of the fleet can sit beside it as @@ -368,16 +369,19 @@ jobs: path: dotfiles-web persist-credentials: false # Mint a short-lived, repo-scoped installation token IF the fleet App is configured - # (the FLEET_APP_ID variable is set and its private key is present). continue-on-error + # (the FLEET_APP_CLIENT_ID variable is set and its private key is present). continue-on-error # so a repo the App isn't installed on falls through to the PAT / GITHUB_TOKEN chain # below instead of failing the run. - name: Mint a scoped installation token (if the fleet App is configured) id: app - if: vars.FLEET_APP_ID != '' && env.HAS_APP_KEY == 'true' + if: vars.FLEET_APP_CLIENT_ID != '' && env.HAS_APP_KEY == 'true' continue-on-error: true uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 with: - app-id: ${{ vars.FLEET_APP_ID }} + # client-id, not the deprecated app-id: FLEET_APP_ID is retired org-wide + # (dotfiles-core#831) and every other consumer moved off it. The variable holds + # the App's Client ID, a different value from its App ID. + client-id: ${{ vars.FLEET_APP_CLIENT_ID }} private-key: ${{ secrets.FLEET_APP_PRIVATE_KEY }} owner: ${{ github.repository_owner }} repositories: ${{ github.event.repository.name }} @@ -522,3 +526,26 @@ jobs: with: path: .fleet-swept key: fleet-swept-${{ needs.precheck.outputs.fingerprint }} + + # LAST, after the swept marker is saved: the mint above is continue-on-error and the PR + # step falls back to GITHUB_TOKEN, so a repo the App cannot reach, or one the org never + # shared FLEET_APP_PRIVATE_KEY with, used to leave this job GREEN while its refresh PR + # sat BLOCKED. Failing here, not before the PR step, keeps the PR (it can be nudged by + # hand), and coming after the marker keeps the hourly poll from re-running a red sweep + # on a fleet state it has already seen. Canonical repo only: a fork has no App and no + # key, and its runs must not go red for that. Same step as dotfiles-core's, + # dotfiles-nvim's and dotfiles-Windows' self-PR bots (dotfiles-core's + # GITHUB-APP-AUTH.md, "A self-PR repo has a third registration"). + - name: Fail if no App token was minted + if: github.repository_owner == 'dotgibson' && steps.app.outputs.token == '' + env: + MINT: ${{ steps.app.outcome }} + HAS_CLIENT_ID: ${{ vars.FLEET_APP_CLIENT_ID != '' }} + run: | + if [ "$HAS_APP_KEY" != true ] || [ "$HAS_CLIENT_ID" != true ]; then + why="FLEET_APP_PRIVATE_KEY visible: $HAS_APP_KEY, FLEET_APP_CLIENT_ID visible: $HAS_CLIENT_ID — share the org secret/variable with ${GITHUB_REPOSITORY}" + else + why="the mint ran and ended '${MINT:-unknown}' — is dotgibson-fleet-sync installed on ${GITHUB_REPOSITORY}?" + fi + echo "::error title=PR not App-authored::No App token was minted, so any refresh PR this run opened is GITHUB_TOKEN-authored and its CI will not start: $why" + exit 1