1- name : Docker Build and Push
1+ name : Docker build and push
22
33on :
44 push :
5+ pull_request :
56
67jobs :
7- docker :
8+ docker-build-and-push :
9+ name : Docker build and push
10+
811 runs-on : ubuntu-latest
912
1013 steps :
1114 - uses : actions/checkout@v2
1215
16+ # This is a workaround due to
17+ # https://github.community/t/how-to-use-env-context/16975
18+ # and https://github.com/docker/build-push-action/issues/43
1319 - name : Set environment variables
1420 run : |
15- # These env variables are set here because of
16- # https://github.community/t/how-to-use-env-context/16975
17-
1821 DOCKER_USERNAME=matejak
1922 echo "::set-env name=DOCKER_USERNAME::$DOCKER_USERNAME"
2023
@@ -25,16 +28,36 @@ jobs:
2528 version="${GITHUB_REF#refs/tags/}"
2629 DOCKER_TAGS="latest,$version"
2730 unset version
31+ elif [[ "$GITHUB_REF" = refs/pull/* ]]; then
32+ pr_number="${GITHUB_REF##*refs/pull/}"
33+ pr_number="${pr_number%%/merge*}"
34+ DOCKER_TAGS="pr-$pr_number"
35+ unset pr_number
2836 else
2937 branch="${GITHUB_REF#refs/heads/}"
30- branch="branch- ${branch/\//-}"
31- DOCKER_TAGS="$branch"
38+ branch="${branch/ /\//-}"
39+ DOCKER_TAGS="branch- $branch"
3240 unset branch
3341 fi
3442 echo "::set-env name=DOCKER_TAGS::$DOCKER_TAGS"
3543 echo "The tags were set to '$DOCKER_TAGS'"
3644
37- - uses : docker/build-push-action@v1
45+ # This is a workaround due to
46+ # https://github.com/docker/build-push-action/issues/85
47+ - if : startsWith(github.ref, 'refs/pull/')
48+ name : Docker build
49+ uses : docker/build-push-action@v1
50+ with :
51+ push : false
52+ repository : ${{ env.DOCKER_IMAGE }}
53+ dockerfile : docker/Dockerfile
54+ add_git_labels : true
55+ tags : ${{ env.DOCKER_TAGS }}
56+ tag_with_sha : true
57+
58+ - if : " ! startsWith(github.ref, 'refs/pull/')"
59+ name : Docker build and push
60+ uses : docker/build-push-action@v1
3861 with :
3962 username : ${{ env.DOCKER_USERNAME }}
4063 password : ${{ secrets.DOCKER_PASSWORD }}
4467 tags : ${{ env.DOCKER_TAGS }}
4568 tag_with_sha : true
4669
47- - if : github.ref == 'refs/heads/master'
70+ - if : github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
4871 name : Update Docker Hub Description
4972 uses : peter-evans/dockerhub-description@v2
5073 env :
0 commit comments