1
1
env :
2
- CONTAINER_IMAGE_TAG : githubchangeloggenerator/github-changelog-generator:latest
2
+ CONTAINER_IMAGE_LATEST_TAG : githubchangeloggenerator/github-changelog-generator:latest
3
+ CONTAINER_IMAGE_RELEASE_TAG : githubchangeloggenerator/github-changelog-generator:${{ github.event.release.tag_name }}
3
4
DOCKER_BUILDX_PLATFORMS : linux/amd64,linux/arm64
4
5
5
- name : Build and deploy latest image
6
+ name : Build the container image and eventually deploy it
6
7
7
- on : [push, pull_request]
8
+ on :
9
+ push :
10
+ pull_request :
11
+ release :
12
+ types : [created]
8
13
9
14
jobs :
10
15
build :
@@ -30,10 +35,10 @@ jobs:
30
35
file : ./Dockerfile
31
36
platforms : ${{ env.DOCKER_BUILDX_PLATFORMS }}
32
37
push : false
33
- tags : ${{ env.CONTAINER_IMAGE_TAG }}
38
+ tags : ${{ env.CONTAINER_IMAGE_LATEST_TAG }}
34
39
deploy :
35
40
environment : Docker Hub
36
- if : ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
41
+ if : ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master') || (github.event_name == 'release' && github.event.action == 'created') }}
37
42
name : Deploy the container image
38
43
needs : build
39
44
runs-on : ubuntu-20.04
@@ -48,14 +53,24 @@ jobs:
48
53
with :
49
54
username : ${{ secrets.DOCKERHUB_USERNAME }}
50
55
password : ${{ secrets.DOCKERHUB_TOKEN }}
51
- - name : Build the contaiiner image for all the platforms and eventually push to Docker Hub (latest)
56
+ # This is to avoid duplicating the image building step
57
+ - if : ${{ github.event_name != 'release' }}
58
+ name : Set the CONTAINER_IMAGE_RELEASE_TAG environment variable
59
+ run : |
60
+ echo "CONTAINER_IMAGE_RELEASE_TAG=$CONTAINER_IMAGE_RELEASE_TAGlatest" >> $GITHUB_ENV
61
+ - name : Build the container image for all the platforms and eventually push to Docker Hub (latest)
52
62
uses : docker/build-push-action@v2
53
63
with :
54
64
context : .
55
65
file : ./Dockerfile
56
66
platforms : ${{ env.DOCKER_BUILDX_PLATFORMS }}
57
67
push : true
58
- tags : ${{ env.CONTAINER_IMAGE_TAG }}
59
- - name : Test the container image
68
+ tags :
69
+ - ${{ env.CONTAINER_IMAGE_LATEST_TAG }}
70
+ - ${{ env.CONTAINER_IMAGE_RELEASE_TAG }}
71
+ - name : Test the latest container image
60
72
shell : bash
61
- run : docker run ${{ env.CONTAINER_IMAGE_TAG }}
73
+ run : docker run ${{ env.CONTAINER_IMAGE_LATEST_TAG }}
74
+ - name : Test the release container image
75
+ shell : bash
76
+ run : docker run ${{ env.CONTAINER_IMAGE_RELEASE_TAG }}
0 commit comments