|
1 | 1 | name: check-generated-files
|
2 | 2 | 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: |
4 | 6 | branches:
|
5 | 7 | - main
|
6 | 8 |
|
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.event.number }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
7 | 13 | 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 | + |
8 | 26 | check-ui-static-files:
|
| 27 | + needs: authorize |
9 | 28 | runs-on: ubuntu-22.04
|
| 29 | + permissions: |
| 30 | + contents: write |
| 31 | + pull-requests: write |
10 | 32 | steps:
|
11 | 33 | - name: Checkout
|
12 | 34 | uses: actions/checkout@v4
|
| 35 | + with: |
| 36 | + repository: ${{github.event.pull_request.head.repo.full_name}} |
| 37 | + ref: ${{ github.event.pull_request.head.ref }} |
13 | 38 |
|
14 | 39 | - name: Generate static files for UI
|
15 | 40 | run: make ui-static
|
|
22 | 47 | id: verify-changed-files
|
23 | 48 |
|
24 | 49 | - 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' }} |
26 | 51 | 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