Skip to content

Commit 347f208

Browse files
Artur-claude
andcommitted
feat: use PAT token to retrigger workflow after formatter commits
- Require VAADIN_BOT_TOKEN secret for formatter workflow - Use PAT instead of GITHUB_TOKEN to push commits (enables workflow triggers) - Fail build if token is not configured - Stop workflow after formatter commits (new workflow will be triggered) - On second run, formatter detects bot commit and skips, validation proceeds - Revert new_sha passing logic (not needed with PAT approach) To set up: 1. Create GitHub PAT with repo and workflow permissions 2. Add as repository secret named VAADIN_BOT_TOKEN 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 784d2ae commit 347f208

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

.github/workflows/validation.yml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ jobs:
2929
timeout-minutes: 120
3030
outputs:
3131
changes_committed: ${{ steps.commit-changes.outputs.changes_committed }}
32-
new_sha: ${{ steps.commit-changes.outputs.new_sha }}
3332

3433
steps:
34+
- name: Check for required token
35+
run: |
36+
if [ -z "${{ secrets.VAADIN_BOT_TOKEN }}" ]; then
37+
echo "::error::VAADIN_BOT_TOKEN secret is required for formatter to trigger workflows after committing changes"
38+
exit 1
39+
fi
40+
3541
- name: Checkout code
3642
uses: actions/checkout@v4
3743
with:
3844
ref: ${{ github.event.pull_request.head.ref }}
3945
repository: ${{ github.event.pull_request.head.repo.full_name }}
40-
token: ${{ secrets.GITHUB_TOKEN }}
46+
token: ${{ secrets.VAADIN_BOT_TOKEN }}
4147
fetch-depth: 2
4248

4349
- name: Check if last commit was from formatter bot
@@ -93,14 +99,10 @@ jobs:
9399
git add -u
94100
git commit -m "chore: apply code formatting with spotless"
95101
96-
# Get the new commit SHA
97-
NEW_SHA=$(git rev-parse HEAD)
98-
echo "new_sha=$NEW_SHA" >> $GITHUB_OUTPUT
99-
100102
git push
101103
102104
echo "changes_committed=true" >> $GITHUB_OUTPUT
103-
echo "✅ Formatting changes committed and pushed. Continuing with validation on formatted code." >> $GITHUB_STEP_SUMMARY
105+
echo "✅ Formatting changes committed and pushed. Workflow will retrigger automatically." >> $GITHUB_STEP_SUMMARY
104106
105107
- name: Generate diff for artifact
106108
if: steps.formatter.outputs.modified != '0'
@@ -156,9 +158,15 @@ jobs:
156158
comment_id: ${{ steps.find-comment.outputs.comment-id }}
157159
})
158160
161+
- name: Stop workflow if changes were committed
162+
if: steps.commit-changes.outputs.changes_committed == 'true'
163+
run: |
164+
echo "::notice::Formatting changes committed. Stopping this workflow run. A new workflow will be triggered automatically."
165+
exit 1
166+
159167
build:
160168
needs: [check-permissions, formatter]
161-
if: always() && needs.check-permissions.result == 'success' && (needs.formatter.result == 'success' || needs.formatter.result == 'skipped')
169+
if: always() && needs.check-permissions.result == 'success' && needs.formatter.result == 'success'
162170
timeout-minutes: 30
163171
runs-on: ubuntu-24.04
164172
outputs:
@@ -173,7 +181,7 @@ jobs:
173181
| tee -a $GITHUB_STEP_SUMMARY && exit 1 || exit 0
174182
- uses: actions/checkout@v4
175183
with:
176-
ref: ${{ needs.formatter.outputs.new_sha || env.HEAD_SHA }}
184+
ref: ${{env.HEAD_SHA}}
177185
- uses: actions/setup-node@v4
178186
with:
179187
node-version: '24.9.0'
@@ -212,7 +220,7 @@ jobs:
212220
name: saved-workspace
213221
path: workspace.tar
214222
unit-tests:
215-
needs: [build, formatter]
223+
needs: build
216224
timeout-minutes: 30
217225
strategy:
218226
fail-fast: false
@@ -221,7 +229,7 @@ jobs:
221229
steps:
222230
- uses: actions/checkout@v4
223231
with:
224-
ref: ${{ needs.formatter.outputs.new_sha || env.HEAD_SHA }}
232+
ref: ${{env.HEAD_SHA}}
225233
- name: Set up JDK 21
226234
uses: actions/setup-java@v4
227235
with:
@@ -278,7 +286,7 @@ jobs:
278286
name: tests-output-unit-${{ matrix.current }}
279287
path: tests-report-*.tgz
280288
it-tests:
281-
needs: [build, formatter]
289+
needs: build
282290
timeout-minutes: 30
283291
strategy:
284292
fail-fast: false
@@ -287,7 +295,7 @@ jobs:
287295
steps:
288296
- uses: actions/checkout@v4
289297
with:
290-
ref: ${{ needs.formatter.outputs.new_sha || env.HEAD_SHA }}
298+
ref: ${{env.HEAD_SHA}}
291299
- uses: actions/setup-node@v4
292300
with:
293301
node-version: '24.9.0'
@@ -367,7 +375,7 @@ jobs:
367375
checks: write
368376
pull-requests: write
369377
if: ${{ failure() || success() }}
370-
needs: [unit-tests, it-tests, formatter]
378+
needs: [unit-tests, it-tests]
371379
runs-on: ubuntu-24.04
372380
steps:
373381
- name: Merge Artifacts
@@ -377,7 +385,7 @@ jobs:
377385
pattern: tests-output-*
378386
- uses: actions/checkout@v4
379387
with:
380-
ref: ${{ needs.formatter.outputs.new_sha || env.HEAD_SHA }}
388+
ref: ${{env.HEAD_SHA}}
381389
- uses: actions/download-artifact@v4
382390
with:
383391
name: tests-output

0 commit comments

Comments
 (0)