Skip to content

Commit 3e153a5

Browse files
committed
Add gh action to build pr images.
Signed-off-by: Humair Khan <[email protected]>
1 parent ec8ac48 commit 3e153a5

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

.github/workflows/build-prs.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Build images for PRs
2+
on:
3+
pull_request:
4+
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
14+
env:
15+
IMAGE_REPO_DSPO: data-science-pipelines-operator
16+
SOURCE_BRANCH: ${{ github.event.pull_request.head.sha }}
17+
QUAY_ORG: opendatahub
18+
QUAY_ID: ${{ secrets.QUAY_ID }}
19+
QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }}
20+
TARGET_IMAGE_TAG: pr-${{ github.event.pull_request.number }}
21+
jobs:
22+
build-pr-image:
23+
if: github.event.pull_request.state == 'open'
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
- uses: ./.github/actions/build
28+
with:
29+
OVERWRITE: true
30+
IMAGE_REPO: ${{ env.IMAGE_REPO_DSPO }}
31+
DOCKERFILE: Dockerfile
32+
GH_REPO: ${{ github.repository }}
33+
- name: Post build
34+
shell: bash
35+
env:
36+
GH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
37+
IMG: quay.io/${{ env.QUAY_ORG }}/data-science-pipelines-operator:${{ env.TARGET_IMAGE_TAG }}
38+
run: |
39+
git config user.email "[email protected]"
40+
git config user.name "dsp-developers"
41+
42+
action=${{ github.event.action }}
43+
44+
if [[ "$action" == "synchronize" ]]; then
45+
echo "Change to PR detected. A new PR build was completed." >> /tmp/body-file.txt
46+
fi
47+
48+
if [[ "$action" == "reopened" ]]; then
49+
echo "PR was re-opened." >> /tmp/body-file.txt
50+
fi
51+
52+
cat <<"EOF" >> /tmp/body-file.txt
53+
A new image has been built to help with testing out this PR: `${{ env.IMG }}`
54+
EOF
55+
56+
if [[ "$action" == "opened" || "$action" == "reopened" ]]; then
57+
cat <<"EOF" >> /tmp/body-file.txt
58+
An OCP cluster where you are logged in as cluster admin is required.
59+
60+
To use this image run the following:
61+
62+
```bash
63+
cd $(mktemp -d)
64+
git clone [email protected]:opendatahub-io/data-science-pipelines-operator.git
65+
cd data-science-pipelines-operator/
66+
git fetch origin pull/${{ github.event.pull_request.number }}/head
67+
git checkout -b pullrequest ${{ env.SOURCE_BRANCH }}
68+
make deploy IMG="${{ env.IMG }}"
69+
```
70+
71+
More instructions [here](https://github.com/opendatahub-io/data-science-pipelines-operator#deploy-dsp-instance) on how to deploy and test a Data Science Pipelines Application.
72+
73+
EOF
74+
fi
75+
76+
gh pr comment ${{ github.event.pull_request.number }} --body-file /tmp/body-file.txt
77+
78+
clean-pr-images:
79+
if: github.event.pull_request.state == 'closed'
80+
runs-on: ubuntu-latest
81+
steps:
82+
- name: Delete PR image
83+
shell: bash
84+
run: |
85+
tag=$(curl --request GET 'https://quay.io/api/v1/repository/${{ env.QUAY_ORG }}/${{ env.IMAGE_REPO_DSPO }}/tag/?specificTag=${{ env.TARGET_IMAGE_TAG }}')
86+
exists=$(echo ${tag} | yq .tags - | yq any)
87+
IMAGE=quay.io/${{ env.QUAY_ORG }}/${{ env.IMAGE_REPO_DSPO }}:${{ env.TARGET_IMAGE_TAG }}
88+
if [[ "$exists" == "true" ]]; then
89+
echo "PR Closed deleting image...${{ env.IMAGE }}."
90+
skopeo delete --creds ${{ env.QUAY_ID }}:${{ env.QUAY_TOKEN }} docker://${IMAGE}
91+
else
92+
echo "Deletion of image ${IMAGE} skipped because image already does not exist."
93+
fi

0 commit comments

Comments
 (0)