1
1
name : Rebuild and publish new ubcdsci/intro-to-ds image on DockerHub
2
2
on :
3
- push :
4
- branches :
5
- - main
3
+ pull_request :
4
+ types : [opened, synchronize]
6
5
paths :
7
6
- Dockerfile
8
7
jobs :
@@ -11,12 +10,30 @@ jobs:
11
10
permissions :
12
11
contents : write
13
12
steps :
14
- - name : Checkout main
13
+ - name : Checkout PR branch
15
14
uses : actions/checkout@v3
16
15
with :
17
16
fetch-depth : ' 0'
18
- ref : ' main'
17
+ ref : ${{ github.head_ref }}
18
+ - name : Check if Dockerfile needs to be rebuilt
19
+ id : check-stale
20
+ run : |
21
+ echo "GitHub PR action type: ${{ github.event.action }}"
22
+ echo "Checking if the PR modifies the Dockerfile"
23
+ if [[ ${{ github.event.action }} == 'opened' ]]; then
24
+ echo "PR just opened, and it edits the Dockerfile, so rebuilding the image."
25
+ echo "stale_dockerfile=true" >> "$GITHUB_OUTPUT"
26
+ else
27
+ if git diff --quiet ${{ github.event.before }} ${{ github.event.after }} Dockerfile; then
28
+ echo "PR synchronized, but Dockerfile was not edited. Not rebuilding the image."
29
+ echo "stale_dockerfile=false" >> "$GITHUB_OUTPUT"
30
+ else
31
+ echo "PR synchronized, and Dockerfile was edited, so rebuilding the image."
32
+ echo "stale_dockerfile=true" >> "$GITHUB_OUTPUT"
33
+ fi
34
+ fi
19
35
- name : Rebuild and publish image
36
+ if : ${{steps.check-stale.outputs.stale_dockerfile == true }}
20
37
id : rebuild
21
38
uses : elgohr/Publish-Docker-Github-Action@v5
22
39
with :
@@ -26,33 +43,37 @@ jobs:
26
43
dockerfile : Dockerfile
27
44
snapshot : true
28
45
- name : Update build_html.sh script
46
+ if : ${{steps.check-stale.outputs.stale_dockerfile == true }}
29
47
run : |
30
48
git config --local user.email "[email protected] "
31
49
git config --local user.name "GitHub Action"
32
- git pull origin main
50
+ git pull origin ${{ github.head_ref }}
33
51
sed 's/ubcdsci\/intro-to-ds:[[:alnum:]]\+/ubcdsci\/intro-to-ds:${{ steps.rebuild.outputs.snapshot-tag }}/g' build_html.sh > build_html.tmp && mv build_html.tmp build_html.sh
34
52
chmod u+x build_html.sh
35
53
git add build_html.sh
36
54
git commit -m "update build_html.sh script with new docker image"
37
55
- name : Update build_pdf.sh script
56
+ if : ${{steps.check-stale.outputs.stale_dockerfile == true }}
38
57
run : |
39
58
git config --local user.email "[email protected] "
40
59
git config --local user.name "GitHub Action"
41
- git pull origin main
60
+ git pull origin ${{ github.head_ref }}
42
61
sed 's/ubcdsci\/intro-to-ds:[[:alnum:]]\+/ubcdsci\/intro-to-ds:${{ steps.rebuild.outputs.snapshot-tag }}/g' build_pdf.sh > build_pdf.tmp && mv build_pdf.tmp build_pdf.sh
43
62
chmod u+x build_pdf.sh
44
63
git add build_pdf.sh
45
64
git commit -m "update build_pdf.sh script with new docker image"
46
65
- name : Update docker-compose.yml script
66
+ if : ${{steps.check-stale.outputs.stale_dockerfile == true }}
47
67
run : |
48
68
git config --local user.email "[email protected] "
49
69
git config --local user.name "GitHub Action"
50
- git pull origin main
70
+ git pull origin ${{ github.head_ref }}
51
71
sed 's/ubcdsci\/intro-to-ds:[[:alnum:]]\+/ubcdsci\/intro-to-ds:${{ steps.rebuild.outputs.snapshot-tag }}/g' docker-compose.yml > docker-compose.tmp && mv docker-compose.tmp docker-compose.yml
52
72
git add docker-compose.yml
53
73
git commit -m "update docker-compose.yml script with new docker image"
54
74
- name : Push changes to build scripts
75
+ if : ${{steps.check-stale.outputs.stale_dockerfile == true }}
55
76
uses : ad-m/github-push-action@master
56
77
with :
57
78
github_token : ${{ secrets.GITHUB_TOKEN }}
58
- branch : ' main '
79
+ branch : ${{ github.head_ref }}
0 commit comments