|
| 1 | +# Copyright 2024 The Janus IDP Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: PR Bundle Manifests Validator |
| 16 | + |
| 17 | +on: |
| 18 | + # pull_request_target needed to be able to commit and push bundle diffs to external fork PRs. |
| 19 | + # But we included a manual authorization safeguard to prevent PWN requests. See the 'authorize' job below. |
| 20 | + pull_request_target: |
| 21 | + branches: |
| 22 | + - main |
| 23 | + - rhdh-1.[0-9]+ |
| 24 | + - 1.[0-9]+.x |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.event.number }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +jobs: |
| 31 | + authorize: |
| 32 | + # The 'external' environment is configured with the maintainers team as required reviewers. |
| 33 | + # All the subsequent jobs in this workflow 'need' this job, which will require manual approval for PRs coming from external forks. |
| 34 | + # see list of approvers in OWNERS file |
| 35 | + environment: |
| 36 | + ${{ (github.event.pull_request.head.repo.full_name == github.repository || |
| 37 | + contains(fromJSON('["gazarenkov","jianrongzhang89","kadel","nickboldt","rm3l"]'), github.actor)) && 'internal' || 'external' }} |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: approved |
| 41 | + run: echo "✓" |
| 42 | + |
| 43 | + pr-bundle-diff-checks: |
| 44 | + name: PR Bundle Diff |
| 45 | + runs-on: ubuntu-latest |
| 46 | + needs: authorize |
| 47 | + permissions: |
| 48 | + contents: read |
| 49 | + pull-requests: write |
| 50 | + steps: |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + fetch-depth: 0 |
| 55 | + repository: ${{github.event.pull_request.head.repo.full_name}} |
| 56 | + ref: ${{ github.event.pull_request.head.ref }} |
| 57 | + |
| 58 | + - name: Setup Go |
| 59 | + uses: actions/setup-go@v5 |
| 60 | + with: |
| 61 | + go-version-file: 'go.mod' |
| 62 | + |
| 63 | + - name: Check for outdated bundle |
| 64 | + id: bundle-diff-checker |
| 65 | + run: | |
| 66 | + make bundle |
| 67 | + git status --porcelain |
| 68 | + # Since operator-sdk 1.26.0, `make bundle` changes the `createdAt` field from the bundle every time we run it. |
| 69 | + # The `git diff` below checks if only the createdAt field has changed. If is the only change, it is ignored. |
| 70 | + # Inspired from https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1415350333 |
| 71 | + echo "MANIFESTS_CHANGED=$(if git diff --quiet -I'^ createdAt: ' bundle; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + - name: Commit any manifest changes |
| 74 | + if: ${{ steps.bundle-diff-checker.outputs.MANIFESTS_CHANGED == 'true' }} |
| 75 | + run: | |
| 76 | + git config user.name 'github-actions[bot]' |
| 77 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 78 | + git fetch --prune |
| 79 | + git pull --rebase --autostash |
| 80 | + git add -A . |
| 81 | + git commit \ |
| 82 | + -m "Regenerate bundle manifests" \ |
| 83 | + -m "Co-authored-by: $GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" |
| 84 | + git push |
| 85 | +
|
| 86 | + - name: Comment on PR if bundle manifests were updated |
| 87 | + uses: actions/github-script@v7 |
| 88 | + if: ${{ !cancelled() && steps.bundle-diff-checker.outputs.MANIFESTS_CHANGED == 'true' }} |
| 89 | + continue-on-error: true |
| 90 | + with: |
| 91 | + script: | |
| 92 | + await github.rest.issues.createComment({ |
| 93 | + issue_number: context.issue.number, |
| 94 | + owner: context.repo.owner, |
| 95 | + repo: context.repo.repo, |
| 96 | + body: '⚠️ <b>Files changed in bundle generation<b>!<br/><br/>Those changes to the operator bundle manifests should have been pushed automatically to your PR branch.<br/>You might also need to manually update the [`.rhdh/bundle/manifests/rhdh-operator.csv.yaml`](.rhdh/bundle/manifests/rhdh-operator.csv.yaml) CSV file accordingly.' |
| 97 | + }) |
0 commit comments