2121 - ' uv.lock'
2222 - ' .ruff.toml'
2323 - ' .github/workflows/ci-quality.yml'
24+ # pull_request_target is needed only for the auto-format-suggest job to call
25+ # the PR Reviews API on fork PRs. All other jobs gate on event_name to avoid
26+ # double execution.
27+ pull_request_target :
28+ branches : [ main, develop ]
29+ paths :
30+ - ' src/**'
31+ - ' tests/**'
32+ - ' pyproject.toml'
33+ - ' requirements*.txt'
34+ - ' uv.lock'
35+ - ' .ruff.toml'
36+ - ' .github/workflows/ci-quality.yml'
37+
38+ # Cancel in-progress runs when a new push arrives on the same branch/ref.
39+ # The auto-format job is exempted via its own job-level concurrency block
40+ # (cancel-in-progress: false) because it pushes a commit back to the branch —
41+ # cancelling it mid-push could leave the branch in a partially formatted state.
42+ concurrency :
43+ group : ci-${{ github.workflow }}-${{ github.ref }}
44+ cancel-in-progress : true
2445
2546permissions :
2647 contents : read
3253
3354 quality-check :
3455 name : Quality Standards
56+ # Skip on pull_request_target — only auto-format-suggest needs that event.
57+ if : github.event_name != 'pull_request_target'
3558 runs-on : ubuntu-latest
3659 needs : config
3760 permissions :
4568 TESTING : ${{ needs.config.outputs.testing-flag }}
4669
4770 steps :
48- - uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
71+ - uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
4972 with :
5073 fetch-depth : 0
5174
6588
6689 setup-cache :
6790 name : Setup Cache
91+ # Runs on both pull_request and pull_request_target — auto-format-suggest
92+ # depends on it and needs to run on pull_request_target for fork PRs.
6893 needs : config
6994 uses : ./.github/workflows/cache-management.yml
7095 with :
@@ -73,18 +98,40 @@ jobs:
7398 python-version : ${{ needs.config.outputs.default-python-version }}
7499
75100 auto-format :
76- name : Auto-Format Code
77- if : github.event_name == 'pull_request'
101+ name : Auto-Format Code
102+ # Same-repo PRs only. Fork PRs handled by auto-format-suggest below.
103+ # Bot-actor guard prevents the job re-triggering on its own push.
104+ if : |
105+ github.event_name == 'pull_request'
106+ && github.event.pull_request.head.repo.full_name == github.repository
107+ && github.actor != 'open-resource-broker-cicd[bot]'
78108 runs-on : ubuntu-latest
79109 needs : [config, setup-cache]
110+ # Override the workflow-level concurrency so this job is never cancelled
111+ # mid-run. If it were interrupted after `ruff` rewrites files but before
112+ # `git push`, the PR branch would be left in a half-formatted state.
113+ concurrency :
114+ group : ci-auto-format-${{ github.ref }}
115+ cancel-in-progress : false
80116 permissions :
81117 contents : write
82118 steps :
83119 - name : Checkout code
84- uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
120+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
85121 with :
86- token : ${{ secrets.GITHUB_TOKEN }}
87122 ref : ${{ github.head_ref }}
123+ # See semantic-release.yml for the rationale - the App-token URL
124+ # set by the composite below must be the only credential source
125+ # so the auto-format push lands as the ORB CICD App rather than
126+ # falling back to github-actions[bot] via the persisted extraheader.
127+ persist-credentials : false
128+
129+ - name : ORB CICD App token
130+ id : cicd
131+ uses : ./.github/actions/orb-cicd-app-token
132+ with :
133+ app-id : ${{ secrets.GH_APP_ID }}
134+ private-key : ${{ secrets.GH_APP_PRIVATE_KEY }}
88135
89136 - name : Setup UV with cache
90137 uses : ./.github/actions/setup-uv-cached
@@ -97,26 +144,66 @@ jobs:
97144
98145 - name : Commit formatting changes
99146 env :
100- GIT_AUTHOR_NAME : github-actions[bot]
101- GIT_AUTHOR_EMAIL : github-actions[bot]@users.noreply.github.com
102- GIT_COMMITTER_NAME : github-actions[bot]
103- GIT_COMMITTER_EMAIL : github-actions[bot]@users.noreply.github.com
147+ GIT_AUTHOR_NAME : ${{ steps.cicd.outputs.committer-name }}
148+ GIT_AUTHOR_EMAIL : ${{ steps.cicd.outputs.committer-email }}
149+ GIT_COMMITTER_NAME : ${{ steps.cicd.outputs.committer-name }}
150+ GIT_COMMITTER_EMAIL : ${{ steps.cicd.outputs.committer-email }}
104151 run : |
105152 git add .
106153 if ! git diff --staged --quiet; then
107- git commit -m "style: auto-format code with ruff [skip ci] "
154+ git commit -m "style: auto-format code with ruff"
108155 git push
109156 fi
110157
158+ auto-format-suggest :
159+ name : Auto-Format Suggestions
160+ # Fork PRs: post formatted changes as PR review suggestions for the
161+ # contributor to apply via the GitHub UI's "Commit suggestion" button.
162+ # Uses pull_request_target so the GITHUB_TOKEN can call the PR Reviews API
163+ # (POST /pulls/{id}/reviews) — pull_request fork-PR tokens cannot.
164+ # The workflow file is evaluated at the base ref (safe); only the PR head
165+ # code is checked out into a non-elevated working tree for formatting.
166+ if : github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository
167+ runs-on : ubuntu-latest
168+ needs : [config, setup-cache]
169+ permissions :
170+ contents : read
171+ pull-requests : write
172+ steps :
173+ - name : Checkout PR head
174+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
175+ with :
176+ ref : ${{ github.event.pull_request.head.sha }}
177+ # No token here — formatter does not need write access; this prevents
178+ # untrusted PR code from authenticating with elevated permissions.
179+ persist-credentials : false
180+
181+ - name : Setup UV with cache
182+ uses : ./.github/actions/setup-uv-cached
183+ with :
184+ cache-key : ${{ needs.setup-cache.outputs.cache-key }}
185+ fail-on-cache-miss : false
186+
187+ - name : Run formatter
188+ run : make format-fix
189+
190+ - name : Post review suggestions
191+ uses : reviewdog/action-suggester@2558ba17e65a9039e73764a73009fc05fef28a46 # v1.24.3
192+ with :
193+ tool_name : ruff
194+ level : warning
195+ fail_on_error : false
196+
111197 lint-ruff :
112198 name : Ruff (Code Quality)
199+ if : github.event_name != 'pull_request_target'
113200 runs-on : ubuntu-latest
114201 needs : [config, setup-cache]
115202 permissions :
116203 contents : read
117204 steps :
118205 - name : Checkout code
119- uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
206+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
120207
121208 - name : Setup UV with cache
122209 uses : ./.github/actions/setup-uv-cached
@@ -129,13 +216,14 @@ jobs:
129216
130217 lint-ruff-optional :
131218 name : Ruff (Extended Checks)
219+ if : github.event_name != 'pull_request_target'
132220 runs-on : ubuntu-latest
133221 needs : [config, setup-cache, lint-ruff]
134222 permissions :
135223 contents : read
136224 steps :
137225 - name : Checkout code
138- uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
226+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
139227
140228 - name : Setup UV with cache
141229 uses : ./.github/actions/setup-uv-cached
@@ -149,13 +237,14 @@ jobs:
149237
150238 lint-pyright :
151239 name : Type Checking (pyright)
240+ if : github.event_name != 'pull_request_target'
152241 runs-on : ubuntu-latest
153242 needs : [config, setup-cache, lint-ruff]
154243 permissions :
155244 contents : read
156245 steps :
157246 - name : Checkout code
158- uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
247+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
159248
160249 - name : Setup UV with cache
161250 uses : ./.github/actions/setup-uv-cached
@@ -169,6 +258,7 @@ jobs:
169258
170259 arch-validation :
171260 name : Architecture Validation
261+ if : github.event_name != 'pull_request_target'
172262 runs-on : ubuntu-latest
173263 needs : [config, setup-cache, lint-ruff]
174264 permissions :
@@ -187,7 +277,7 @@ jobs:
187277 description : " File Size Compliance"
188278 steps :
189279 - name : Checkout code
190- uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
280+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
191281
192282 - name : Setup UV with cache
193283 uses : ./.github/actions/setup-uv-cached
0 commit comments