Skip to content

Commit 6ccc7a6

Browse files
committed
ci: Automatically push the modified files if static UI files need to be updated
This is to reduce the maintainance overhead. Instead of just warning to regenerate the UI files (which the job already knows about), it makes much sense to just push the changes to the PR.
1 parent 1c6181a commit 6ccc7a6

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

.github/workflows/check-generated-files.yaml

+50-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
name: check-generated-files
22
on:
3-
pull_request:
3+
# pull_request_target needed to be able to commit and push bundle diffs to external fork PRs.
4+
# But we included a manual authorization safeguard to prevent PWN requests. See the 'authorize' job below.
5+
pull_request_target:
46
branches:
57
- main
68

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.number }}
11+
cancel-in-progress: true
12+
713
jobs:
14+
authorize:
15+
# The 'external' environment is configured with the odo-maintainers team as required reviewers.
16+
# All the subsequent jobs in this workflow 'need' this job, which will require manual approval for PRs coming from external forks.
17+
# TODO(rm3l): list of authorized users that do not require manual review comes from the maintainers team and various robot accounts that handle automation in the repo => find a better way not to hardcode this list!
18+
environment:
19+
${{ (github.event.pull_request.head.repo.full_name == github.repository ||
20+
contains(fromJSON('["odo-robot[bot]", "dependabot[bot]", "openshift-ci[bot]", "openshift-merge-robot", "openshift-ci-robot", "feloy", "kadel", "rm3l", "valaparthvi", "ritudes"]'), github.actor)) &&
21+
'internal' || 'external' }}
22+
runs-on: ubuntu-latest
23+
steps:
24+
- run: echo ✓
25+
826
check-ui-static-files:
27+
needs: authorize
928
runs-on: ubuntu-22.04
29+
permissions:
30+
contents: write
31+
pull-requests: write
1032
steps:
1133
- name: Checkout
1234
uses: actions/checkout@v4
35+
with:
36+
repository: ${{github.event.pull_request.head.repo.full_name}}
37+
ref: ${{ github.event.pull_request.head.ref }}
1338

1439
- name: Generate static files for UI
1540
run: make ui-static
@@ -22,7 +47,28 @@ jobs:
2247
id: verify-changed-files
2348

2449
- name: Some files have changed
25-
if: steps.verify-changed-files.outputs.files_changed == 'true'
50+
if: ${{ !cancelled() && steps.verify-changed-files.outputs.files_changed == 'true' }}
2651
run: |
27-
echo "::error Changed files: ${{ steps.verify-changed-files.outputs.changed_files }} -- Please regenerate with make ui-static / make prebuild"
28-
exit 1
52+
echo "::warning Changed files: ${{ steps.verify-changed-files.outputs.changed_files }} -- Regenerating with make ui-static / make prebuild"
53+
git config user.name 'github-actions[bot]'
54+
git config user.email 'github-actions[bot]@users.noreply.github.com'
55+
git fetch --prune
56+
git pull --rebase --autostash
57+
git add -A .
58+
git commit \
59+
-m "Regenerate static UI files" \
60+
-m "Co-authored-by: $GITHUB_ACTOR <[email protected]>"
61+
git push
62+
63+
- name: Comment on PR if bundle manifests were updated
64+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
65+
if: ${{ !cancelled() && steps.verify-changed-files.outputs.files_changed == 'true' }}
66+
continue-on-error: true
67+
with:
68+
script: |
69+
await github.rest.issues.createComment({
70+
issue_number: context.issue.number,
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
body: '⚠️ <b>Static UI files regenerated!</b><br/><br/>Those changes should have been pushed automatically to your PR branch.'
74+
})

0 commit comments

Comments
 (0)