From edb3706fb0c315b5072b79cd4b2f15071a9cc855 Mon Sep 17 00:00:00 2001 From: Amp Date: Wed, 11 Nov 2026 00:25:11 +0000 Subject: [PATCH] ci: isolate metadata push credentials Co-authored-by: Travis Lyons --- .github/workflows/publish.yml | 48 +++++++----- .github/workflows/update-package-metadata.yml | 74 +++++++++++++++++-- 2 files changed, 95 insertions(+), 27 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e7f5b34..c87c7cc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,6 +30,7 @@ jobs: runs-on: ubuntu-latest outputs: packages: ${{ steps.plan.outputs.packages }} + current: ${{ steps.current.outputs.current }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -47,6 +48,7 @@ jobs: require-base: 'true' - name: Confirm main is current + id: current env: GITHUB_TOKEN: ${{ github.token }} shell: bash @@ -55,14 +57,16 @@ jobs: head_sha=$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/heads/main" --jq .object.sha) if [[ "$head_sha" != "$GITHUB_SHA" ]]; then - echo "Refusing to publish superseded commit $GITHUB_SHA; main is at $head_sha" >&2 - exit 1 + echo "::notice::Skipping superseded commit $GITHUB_SHA; main is at $head_sha" + echo 'current=false' >> "$GITHUB_OUTPUT" + exit 0 fi + echo 'current=true' >> "$GITHUB_OUTPUT" build: name: Build (${{ matrix.package }}) needs: plan - if: needs.plan.outputs.packages != '[]' + if: needs.plan.outputs.current == 'true' && needs.plan.outputs.packages != '[]' strategy: fail-fast: false max-parallel: 4 @@ -133,7 +137,7 @@ jobs: publish: name: Publish (${{ matrix.package }}) needs: [plan, build] - if: needs.plan.outputs.packages != '[]' + if: needs.plan.outputs.current == 'true' && needs.plan.outputs.packages != '[]' strategy: fail-fast: false max-parallel: 4 @@ -145,13 +149,33 @@ jobs: contents: read environment: packages.trly.dev steps: + # Re-checked here, not just in plan: the build runs between the two jobs, + # so the plan-time check no longer covers the moment of the write. + - name: Confirm main is current + id: current + env: + GITHUB_TOKEN: ${{ github.token }} + shell: bash + run: | + set -euo pipefail + + head_sha=$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/heads/main" --jq .object.sha) + if [[ "$head_sha" != "$GITHUB_SHA" ]]; then + echo "::notice::Skipping superseded commit $GITHUB_SHA; main is at $head_sha" + echo 'current=false' >> "$GITHUB_OUTPUT" + exit 0 + fi + echo 'current=true' >> "$GITHUB_OUTPUT" + - name: Download package archive + if: steps.current.outputs.current == 'true' uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: package-${{ matrix.package }} path: ${{ runner.temp }}/packages/${{ matrix.package }} - name: Install pkgdepot + if: steps.current.outputs.current == 'true' env: PKGDEPOT_VERSION: 0.2.1 PKGDEPOT_SHA256: 441ff17351e6ab06c1e59b07353976080d570bb5359cdc3a76ea1f81dd13d7eb @@ -168,22 +192,8 @@ jobs: tar --extract --gzip --file "$archive" --directory "$install_dir" pkgdepot printf '%s\n' "$install_dir" >> "$GITHUB_PATH" - # Re-checked here, not just in plan: the build runs between the two jobs, - # so the plan-time check no longer covers the moment of the write. - - name: Confirm main is current - env: - GITHUB_TOKEN: ${{ github.token }} - shell: bash - run: | - set -euo pipefail - - head_sha=$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/heads/main" --jq .object.sha) - if [[ "$head_sha" != "$GITHUB_SHA" ]]; then - echo "Refusing to publish superseded commit $GITHUB_SHA; main is at $head_sha" >&2 - exit 1 - fi - - name: Publish package archives + if: steps.current.outputs.current == 'true' env: PKGDEPOT_URL: https://packages.trly.dev PKGDEPOT_OAUTH_ISSUER: https://id.trly.dev diff --git a/.github/workflows/update-package-metadata.yml b/.github/workflows/update-package-metadata.yml index e035fbd..561093d 100644 --- a/.github/workflows/update-package-metadata.yml +++ b/.github/workflows/update-package-metadata.yml @@ -29,6 +29,8 @@ jobs: runs-on: ubuntu-latest container: image: archlinux:base-devel@sha256:767de6eaa40dcfeda5263a48737ea03a782caabdf3a403b6e6a203c7fd333681 + outputs: + created: ${{ steps.stage_updated_metadata.outputs.created }} permissions: contents: read steps: @@ -83,27 +85,80 @@ jobs: ) done - - name: Commit updated metadata - id: commit_updated_metadata + - name: Stage updated metadata + id: stage_updated_metadata shell: bash run: | set -euo pipefail echo 'created=false' >> "$GITHUB_OUTPUT" - git config user.name 'renovate[bot]' - git config user.email '29139614+renovate[bot]@users.noreply.github.com' git add -- '*/PKGBUILD' '*/.SRCINFO' if git diff --cached --quiet; then echo 'Package metadata is already current.' exit 0 fi - git commit -m 'chore: update package metadata' + + while IFS= read -r path; do + if [[ ! $path =~ ^[a-z0-9][a-z0-9@._+-]*/(PKGBUILD|\.SRCINFO)$ ]]; then + echo "Refusing to export unexpected changed path: $path" >&2 + exit 1 + fi + done < <(git diff --cached --name-only) + + git diff --cached --binary > "$RUNNER_TEMP/metadata.patch" echo 'created=true' >> "$GITHUB_OUTPUT" + - name: Upload updated metadata + if: steps.stage_updated_metadata.outputs.created == 'true' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: package-metadata-${{ github.run_id }} + path: ${{ runner.temp }}/metadata.patch + if-no-files-found: error + retention-days: 1 + + push: + name: Commit updated metadata + needs: update + if: needs.update.outputs.created == 'true' + runs-on: ubuntu-latest + container: + image: archlinux:base-devel@sha256:767de6eaa40dcfeda5263a48737ea03a782caabdf3a403b6e6a203c7fd333681 + permissions: + contents: read + steps: + - name: Install tools + run: pacman -Syu --noconfirm --needed git github-cli + + - name: Check out Renovate branch + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + + - name: Download updated metadata + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: package-metadata-${{ github.run_id }} + path: ${{ runner.temp }}/metadata + + - name: Apply updated metadata + shell: bash + run: | + set -euo pipefail + + git apply --index "$RUNNER_TEMP/metadata/metadata.patch" + while IFS= read -r path; do + if [[ ! $path =~ ^[a-z0-9][a-z0-9@._+-]*/(PKGBUILD|\.SRCINFO)$ ]]; then + echo "Refusing to commit unexpected changed path: $path" >&2 + exit 1 + fi + done < <(git diff --cached --name-only) + # GITHUB_TOKEN commits do not trigger another workflow run, so the - # narrowly scoped PAT is used only for this final push. - - name: Push updated metadata - if: steps.commit_updated_metadata.outputs.created == 'true' + # narrowly scoped PAT is used only in this isolated push job. + - name: Commit and push updated metadata env: GITHUB_TOKEN: ${{ github.token }} METADATA_PUSH_TOKEN: ${{ secrets.METADATA_PUSH_TOKEN }} @@ -113,6 +168,9 @@ jobs: run: | set -euo pipefail + git config user.name 'renovate[bot]' + git config user.email '29139614+renovate[bot]@users.noreply.github.com' + current_head_sha=$(gh api \ "repos/${GITHUB_REPOSITORY}/git/ref/heads/${GITHUB_HEAD_REF}" \ --jq .object.sha)