|
| 1 | +--- |
| 2 | +"name": "Build Notebooks (pr, AIPCC bases)" |
| 3 | +"on": |
| 4 | + "pull_request_target": |
| 5 | + "paths-ignore": |
| 6 | + # Don't build images if the only thing that changed is image digests in manifests |
| 7 | + - manifests/base/params-latest.env |
| 8 | + - manifests/base/params.env |
| 9 | + # In fact, skip the build if there are only changes in manifests and nowhere else |
| 10 | + - manifests/** |
| 11 | + |
| 12 | +# BEWARE: This GitHub Actions workflow runs on pull_request_target, meaning it has access to our secrets |
| 13 | +# see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-secrets |
| 14 | +# and https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + packages: read |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: ${{ format('build-notebooks-pr-{0}', github.event.pull_request.number) }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +env: |
| 25 | + # language=json |
| 26 | + contributors: | |
| 27 | + ["atheo89", "andyatmiami", "caponetto", "daniellutz", "dibryant", "harshad16", "jesuino", "jiridanek", "jstourac", "paulovmr", "Fiona-Waters", "grdryn", "kryanbeane", "mtchoum1", "obrown1205", "dependabot[bot]", "ide-developer"] |
| 28 | +
|
| 29 | +jobs: |
| 30 | + gen: |
| 31 | + name: Generate job matrix |
| 32 | + runs-on: ubuntu-latest |
| 33 | + # rhds/notebooks builds from AIPCC bases and requires pull_request_target trigger |
| 34 | + if: ${{ github.repository == 'red-hat-data-services/notebooks' }} |
| 35 | + outputs: |
| 36 | + matrix: ${{ steps.gen.outputs.matrix }} |
| 37 | + has_jobs: ${{ steps.gen.outputs.has_jobs }} |
| 38 | + steps: |
| 39 | + |
| 40 | + - name: Check permissions and deny untrusted users (this must be done FIRST, for security, before we checkout) |
| 41 | + if: |- |
| 42 | + github.event_name == 'workflow_dispatch' || |
| 43 | + ( |
| 44 | + github.event_name == 'pull_request_target' && |
| 45 | + ( |
| 46 | + github.event.repository.private == true || |
| 47 | + contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) || |
| 48 | + contains(fromJSON(env.contributors), github.actor) |
| 49 | + ) |
| 50 | + ) |
| 51 | + run: | |
| 52 | + echo "GitHub user ${{ github.actor }} is not a registered project contributor, not allowed to run actions requiring secrets!" |
| 53 | + exit 1 |
| 54 | +
|
| 55 | + # Here we are checking out the pull request, so that we can build from the new code |
| 56 | + # We can do this because we already checked that the submitting user is a contributor |
| 57 | + - uses: actions/checkout@v5 |
| 58 | + if: ${{ github.event_name == 'pull_request_target' }} |
| 59 | + with: |
| 60 | + ref: "refs/pull/${{ github.event.number }}/merge" |
| 61 | + - uses: actions/checkout@v5 |
| 62 | + if: ${{ github.event_name != 'pull_request_target' }} |
| 63 | + |
| 64 | + - uses: actions/setup-go@v5 |
| 65 | + with: |
| 66 | + cache-dependency-path: "**/*.sum" |
| 67 | + |
| 68 | + - name: Determine targets to build based on changed files |
| 69 | + if: ${{ github.event_name == 'pull_request_target' }} |
| 70 | + run: | |
| 71 | + set -x |
| 72 | + git fetch --no-tags origin 'pull/${{ github.event.pull_request.number }}/head:${{ github.event.pull_request.head.ref }}' |
| 73 | + git fetch --no-tags origin '+refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}' |
| 74 | + python3 ci/cached-builds/gen_gha_matrix_jobs.py \ |
| 75 | + --from-ref 'origin/${{ github.event.pull_request.base.ref }}' \ |
| 76 | + --to-ref '${{ github.event.pull_request.head.ref }}' \ |
| 77 | + --rhel-images exclude \ |
| 78 | + --s390x-images include |
| 79 | + id: gen |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + shell: bash |
| 83 | + |
| 84 | + build: |
| 85 | + needs: ["gen"] |
| 86 | + strategy: |
| 87 | + fail-fast: false |
| 88 | + matrix: "${{ fromJson(needs.gen.outputs.matrix) }}" |
| 89 | + uses: ./.github/workflows/build-notebooks-TEMPLATE.yaml |
| 90 | + if: ${{ fromJson(needs.gen.outputs.has_jobs) }} |
| 91 | + with: |
| 92 | + target: "${{ matrix.target }}" |
| 93 | + python: "${{ matrix.python }}" |
| 94 | + github: "${{ toJSON(github) }}" |
| 95 | + platform: "${{ matrix.platform }}" |
| 96 | + subscription: "${{ matrix.subscription }}" |
| 97 | + secrets: inherit |
0 commit comments