Skip to content

Commit b068a53

Browse files
committed
NO-JIRA: use pull_request_target to build PRs from AIPCC bases in rhds/notebooks
1 parent 9af24e7 commit b068a53

File tree

4 files changed

+112
-3
lines changed

4 files changed

+112
-3
lines changed

.github/workflows/build-notebooks-TEMPLATE.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,11 @@ jobs:
281281

282282
# region Image build
283283

284-
- name: Login to quay.io
284+
- name: Login to quay.io/aipcc (if the secret is present)
285+
if: ${{ secrets.AIPCC_QUAY_BOT_USERNAME != '' }}
285286
shell: bash
286287
run: |
287-
echo "${{ secrets.AIPCC_QUAY_BOT_PASSWORD }}" | podman login quay.io -u "${{ secrets.AIPCC_QUAY_BOT_USERNAME }}" --password-stdin
288+
echo "${{ secrets.AIPCC_QUAY_BOT_PASSWORD }}" | podman login quay.io/aipcc -u "${{ secrets.AIPCC_QUAY_BOT_USERNAME }}" --password-stdin
288289
289290
- name: Compute extra podman build args
290291
id: extra-podman-build-args
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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

.github/workflows/build-notebooks-pr-rhel.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ jobs:
3232
steps:
3333

3434
- name: Check permissions and deny untrusted users (this must be done FIRST, for security, before we checkout)
35-
if: ${{ !contains(fromJSON(env.contributors), github.actor) }}
35+
if: |-
36+
github.event_name == 'workflow_dispatch' ||
37+
(
38+
github.event_name == 'pull_request_target' &&
39+
(
40+
github.event.repository.private == true ||
41+
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) ||
42+
contains(fromJSON(env.contributors), github.actor)
43+
)
44+
)
3645
run: |
3746
echo "GitHub user ${{ github.actor }} is not a registered project contributor, not allowed to run actions on RHEL!"
3847
exit 1

.github/workflows/build-notebooks-pr.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
gen:
2323
name: Generate job matrix
2424
runs-on: ubuntu-latest
25+
# rhds/notebooks builds from quay.io/aipcc bases and requires pull_request_target trigger
26+
if: ${{ github.repository != 'red-hat-data-services/notebooks' }}
2527
outputs:
2628
matrix: ${{ steps.gen.outputs.matrix }}
2729
has_jobs: ${{ steps.gen.outputs.has_jobs }}

0 commit comments

Comments
 (0)