Skip to content

Commit 6251b62

Browse files
oblomov-devclaude
andauthored
check-abap2UI5: only a push to main gets a token that can write (#98)
The workflow granted contents: write to every run, pull requests included, for the one step that publishes the badges - a step that already skipped itself on a pull request. The publish is its own job now (`badges`, needs the gate job, runs on a push to main only, the one job with contents: write); the gate job hands it the badge files as an artifact, and the workflow default is contents: read. Claude-Session: https://claude.ai/code/session_01Te3BRpRpxNhZAYnrQL6Gdt Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9e73a81 commit 6251b62

1 file changed

Lines changed: 42 additions & 15 deletions

File tree

‎.github/workflows/check-abap2UI5.yaml‎

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ on:
2626
push:
2727
branches: [main]
2828

29-
# contents: write is for the badge commit at the end of the job, and for
30-
# nothing else.
29+
# Read-only for every job; the `badges` job alone raises contents: write, and
30+
# it runs only on a push to main.
3131
permissions:
32-
contents: write
32+
contents: read
3333

3434
concurrency:
3535
group: check-abap2UI5-${{ github.ref }}
@@ -50,19 +50,46 @@ jobs:
5050
- run: npx playwright install chromium --with-deps
5151
- run: npx abap2ui5lint
5252

53-
# The gate above rewrote .github/badges/ (abap2ui5lint.jsonc "badge"), and
54-
# this step publishes those two files to the `badges` branch - an
55-
# orphan branch that holds nothing else and is what the README badges
56-
# read. Only on main: main is protected and github-actions[bot] cannot
57-
# bypass that, and the old way round - committing the badges onto the
58-
# pull request branch - started a second set of runs on that commit which
59-
# waited for a maintainer's approval and left the pull request blocked.
60-
# A pull request run publishes nothing; the run on main after the merge
61-
# does. Only after a green gate, as before. A failed push (a ruleset on
62-
# the branch) is a warning: the README then keeps showing the previous
63-
# state rather than a wrong one.
53+
# The badge files this run wrote go to the `badges` job below, which is
54+
# the one job allowed to write to the repository - only on a push to
55+
# main, and only after a green gate (the job needs this one).
56+
- name: Hand the badges to the badges job
57+
if: success() && github.event_name == 'push' && github.ref == 'refs/heads/main'
58+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
59+
with:
60+
name: badges
61+
path: .github/badges/*.json
62+
if-no-files-found: warn
63+
retention-days: 1
64+
include-hidden-files: true
65+
66+
# Publishes the two badge files to the `badges` branch - an orphan branch
67+
# that holds nothing else and is what the README badges read. Its own job,
68+
# and the only one with contents: write: a pull request run never gets a
69+
# token that can write to the repository, not even in a job whose steps
70+
# would skip the push. Only on main: main is protected and
71+
# github-actions[bot] cannot bypass that, and the old way round -
72+
# committing the badges onto the pull request branch - started a second set
73+
# of runs on that commit which waited for a maintainer's approval and left
74+
# the pull request blocked. A failed push (a ruleset on the branch) is a
75+
# warning: the README then keeps showing the previous state rather than a
76+
# wrong one.
77+
badges:
78+
needs: check-abap2UI5
79+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
80+
runs-on: ubuntu-latest
81+
timeout-minutes: 5
82+
permissions:
83+
contents: write
84+
steps:
85+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
86+
# no artifact when the gate wrote no badge files - the step below says so
87+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
88+
continue-on-error: true
89+
with:
90+
name: badges
91+
path: .github/badges
6492
- name: Publish the badges
65-
if: success() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
6693
run: |
6794
ls .github/badges/*.json >/dev/null 2>&1 || { echo "::warning::The gate wrote no badge files - nothing to publish."; exit 0; }
6895
dir="$RUNNER_TEMP/badges"

0 commit comments

Comments
 (0)