1
1
name : Build images for PRs
2
2
on :
3
- pull_request :
3
+ workflow_run :
4
+ workflows : ["Trigger build images for PRs"]
4
5
types :
5
- - opened
6
- - reopened
7
- - closed
8
- - synchronize
9
- permissions :
10
- pull-requests : read
11
- concurrency :
12
- group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13
- cancel-in-progress : true
6
+ - completed
14
7
env :
15
8
IMAGE_REPO_DSPO : data-science-pipelines-operator
16
- SOURCE_BRANCH : ${{ github.event.pull_request.head.sha }}
17
9
QUAY_ORG : opendatahub
18
10
QUAY_ID : ${{ secrets.QUAY_ID }}
19
11
QUAY_TOKEN : ${{ secrets.QUAY_TOKEN }}
20
- TARGET_IMAGE_TAG : pr-${{ github.event.pull_request.number }}
21
12
22
13
GH_USER_NAME : dsp-developers
23
14
jobs :
15
+ fetch-data :
16
+ name : Fetch workflow payload
17
+ runs-on : ubuntu-latest
18
+ if : >
19
+ github.event.workflow_run.event == 'pull_request' &&
20
+ github.event.workflow_run.conclusion == 'success'
21
+ outputs :
22
+ pr_state : ${{ steps.vars.outputs.pr_state }}
23
+ pr_number : ${{ steps.vars.outputs.pr_number }}
24
+ head_sha : ${{ steps.vars.outputs.head_sha }}
25
+ steps :
26
+ - name : ' Download artifact'
27
+
28
+ with :
29
+ script : |
30
+ var artifacts = await github.actions.listWorkflowRunArtifacts({
31
+ owner: context.repo.owner,
32
+ repo: context.repo.repo,
33
+ run_id: ${{github.event.workflow_run.id }},
34
+ });
35
+ var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
36
+ return artifact.name == "pr"
37
+ })[0];
38
+ var download = await github.actions.downloadArtifact({
39
+ owner: context.repo.owner,
40
+ repo: context.repo.repo,
41
+ artifact_id: matchArtifact.id,
42
+ archive_format: 'zip',
43
+ });
44
+ var fs = require('fs');
45
+ fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
46
+ - run : unzip pr.zip
47
+ - shell : bash
48
+ id : vars
49
+ run : |
50
+ pr_number=$(cat ./pr_number)
51
+ pr_state=$(cat ./pr_state)
52
+ head_sha=$(cat ./head_sha)
53
+ echo "pr_number=${pr_number}" >> $GITHUB_OUTPUT
54
+ echo "pr_state=${pr_state}" >> $GITHUB_OUTPUT
55
+ echo "head_sha=${head_sha}" >> $GITHUB_OUTPUT
56
+
24
57
build-pr-image :
25
- if : github.event.pull_request.state == 'open'
58
+ if : needs.fetch-data.outputs.pr_state == 'open'
26
59
runs-on : ubuntu-latest
60
+ needs : fetch-data
61
+ concurrency :
62
+ group : ${{ github.workflow }}-build-pr-image-${{ needs.fetch-data.outputs.pr_number }}
63
+ cancel-in-progress : true
64
+ env :
65
+ SOURCE_BRANCH : ${{ needs.fetch-data.outputs.head_sha }}
66
+ TARGET_IMAGE_TAG : pr-${{ needs.fetch-data.outputs.pr_number }}
27
67
steps :
28
68
- uses : actions/checkout@v3
29
69
- name : Build Image
33
73
IMAGE_REPO : ${{ env.IMAGE_REPO_DSPO }}
34
74
DOCKERFILE : Dockerfile
35
75
GH_REPO : ${{ github.repository }}
76
+ - name : Echo PR metadata
77
+ shell : bash
78
+ env :
79
+ GH_TOKEN : ${{ secrets.ACCESS_TOKEN }}
80
+ IMG : quay.io/${{ env.QUAY_ORG }}/${{ env.IMAGE_REPO_DSPO }}:${{ env.TARGET_IMAGE_TAG }}
81
+ run : |
82
+ echo ${{ needs.fetch-data.outputs.head_sha }}
83
+ echo ${{ needs.fetch-data.outputs.pr_number }}
84
+ echo ${{ needs.fetch-data.outputs.pr_state }}
36
85
- name : Send comment
37
86
shell : bash
38
87
env :
66
115
cd $(mktemp -d)
67
116
git clone [email protected] :opendatahub-io/data-science-pipelines-operator.git
68
117
cd data-science-pipelines-operator/
69
- git fetch origin pull/${{ github.event.pull_request.number }}/head
118
+ git fetch origin pull/${{ needs.fetch-data.outputs.pr_number }}/head
70
119
git checkout -b pullrequest ${{ env.SOURCE_BRANCH }}
71
120
make deploy IMG="${{ env.IMG }}"
72
121
```
@@ -76,11 +125,17 @@ jobs:
76
125
EOF
77
126
fi
78
127
79
- gh pr comment ${{ github.event.pull_request.number }} --body-file /tmp/body-file.txt
128
+ gh pr comment ${{ needs.fetch-data.outputs.pr_number }} --body-file /tmp/body-file.txt
80
129
81
130
clean-pr-images :
82
- if : github.event.pull_request.state == 'closed'
131
+ if : needs.fetch-data.outputs.pr_state == 'closed'
83
132
runs-on : ubuntu-latest
133
+ needs : fetch-data
134
+ concurrency :
135
+ group : ${{ github.workflow }}-clean-pr-images-${{ needs.fetch-data.outputs.pr_number }}
136
+ cancel-in-progress : true
137
+ env :
138
+ TARGET_IMAGE_TAG : pr-${{ needs.fetch-data.outputs.pr_number }}
84
139
steps :
85
140
- name : Delete PR image
86
141
shell : bash
0 commit comments