Skip to content

Commit d541f02

Browse files
committed
Reduce duplication for the deployment workflow
1 parent d04861f commit d541f02

File tree

2 files changed

+24
-40
lines changed

2 files changed

+24
-40
lines changed

.github/workflows/main.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
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 }}
34
DOCKER_BUILDX_PLATFORMS: linux/amd64,linux/arm64
45

5-
name: Build and deploy latest image
6+
name: Build the container image and eventually deploy it
67

7-
on: [push, pull_request]
8+
on:
9+
push:
10+
pull_request:
11+
release:
12+
types: [created]
813

914
jobs:
1015
build:
@@ -30,10 +35,10 @@ jobs:
3035
file: ./Dockerfile
3136
platforms: ${{ env.DOCKER_BUILDX_PLATFORMS }}
3237
push: false
33-
tags: ${{ env.CONTAINER_IMAGE_TAG }}
38+
tags: ${{ env.CONTAINER_IMAGE_LATEST_TAG }}
3439
deploy:
3540
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') }}
3742
name: Deploy the container image
3843
needs: build
3944
runs-on: ubuntu-20.04
@@ -48,14 +53,24 @@ jobs:
4853
with:
4954
username: ${{ secrets.DOCKERHUB_USERNAME }}
5055
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)
5262
uses: docker/build-push-action@v2
5363
with:
5464
context: .
5565
file: ./Dockerfile
5666
platforms: ${{ env.DOCKER_BUILDX_PLATFORMS }}
5767
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
6072
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 }}

.github/workflows/push-tagged-image.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)