Skip to content

Commit

Permalink
Fix bug where Docker image was not tagged latest
Browse files Browse the repository at this point in the history
The bug was inadvertently introduced by #405, when we migrated to a
later version of the [Docker `build-push-action`][1].

[1]: https://github.com/docker/build-push-action

Fixes #419
  • Loading branch information
johnboyes authored Jan 19, 2024
1 parent 3153290 commit e7aa331
Showing 1 changed file with 94 additions and 92 deletions.
186 changes: 94 additions & 92 deletions .github/workflows/github_tag_and_release.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,95 @@
---
name: Release

on: # yamllint disable-line rule:truthy
pull_request_target:
types:
- closed

env:
docker_repo: agilepathway/pull-request-label-checker

jobs:

tag:
name: Tag semantic version
runs-on: ubuntu-22.04
outputs:
semver: ${{ steps.tag.outputs.tag }}
steps:
- name: Tag
uses: K-Phoen/[email protected]
id: tag
with:
release_branch: master
release_strategy: tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
needs: tag
name: Create GitHub Release
runs-on: ubuntu-22.04
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21.5'
-
name: Run GoReleaser
uses: goreleaser/[email protected]
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build_and_push_docker_image:
needs: tag
name: Build and push image
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
tags: ${{env.docker_repo}}:${{ needs.tag.outputs.semver }}
platforms: linux/amd64,linux/arm64
push: true

check_latest_tag:
needs: [tag, build_and_push_docker_image]
runs-on: ubuntu-22.04
steps:

- name: Check Docker image for new release is tagged latest
id: check_docker_image_tagged_latest
# yamllint disable rule:line-length
run: |
docker pull ${{env.docker_repo}}:${{ needs.tag.outputs.semver }}
echo "IS_LATEST_TAGGED_CORRECTLY=$(docker image inspect ${{env.docker_repo}}:${{ needs.tag.outputs.semver }} | jq -r '.[] | (.RepoTags) | any( . == "${{env.docker_repo}}:latest") ')" >> "$GITHUB_OUTPUT"
# yamllint enable rule:line-length

- name: Fail if latest is not tagged correctly
if: ${{ steps.check_docker_image_tagged_latest.outputs.IS_LATEST_TAGGED_CORRECTLY == 'false' }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('The newly released Docker image ${{ needs.tag.outputs.semver }} is not tagged latest. ')
name: Release

Check failure on line 2 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L2

[error] wrong indentation: expected 0 but found 2 (indentation)
Raw output
./.github/workflows/github_tag_and_release.yml:2:3: [error] wrong indentation: expected 0 but found 2 (indentation)

Check failure on line 3 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L3

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:3:1: [error] trailing spaces (trailing-spaces)
on: # yamllint disable-line rule:truthy
pull_request_target:
types:
- closed

Check failure on line 8 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L8

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:8:1: [error] trailing spaces (trailing-spaces)
env:
docker_repo: agilepathway/pull-request-label-checker

Check failure on line 11 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L11

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:11:1: [error] trailing spaces (trailing-spaces)
jobs:

Check failure on line 13 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L13

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:13:1: [error] trailing spaces (trailing-spaces)
tag:
name: Tag semantic version
runs-on: ubuntu-22.04
outputs:
semver: ${{ steps.tag.outputs.tag }}
steps:
- name: Tag
uses: K-Phoen/[email protected]
id: tag
with:
release_branch: master
release_strategy: tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Check failure on line 28 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L28

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:28:1: [error] trailing spaces (trailing-spaces)
release:
needs: tag
name: Create GitHub Release
runs-on: ubuntu-22.04
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21.5'
-
name: Run GoReleaser
uses: goreleaser/[email protected]
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Check failure on line 52 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L52

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:52:1: [error] trailing spaces (trailing-spaces)
build_and_push_docker_image:
needs: tag
name: Build and push image
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
tags: ${{env.docker_repo}}:${{ needs.tag.outputs.semver }},${{env.docker_repo}}:latest
platforms: linux/amd64,linux/arm64
push: true

Check failure on line 74 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L74

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:74:1: [error] trailing spaces (trailing-spaces)
check_latest_tag:
needs: [tag, build_and_push_docker_image]
runs-on: ubuntu-22.04
steps:

Check failure on line 79 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L79

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:79:1: [error] trailing spaces (trailing-spaces)
- name: Check Docker image for new release is tagged latest
# (it is important to have this check to catch any regression, e.g. if we move to a different way of releasing)

Check failure on line 81 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L81

[warning] line too long (121 > 120 characters) (line-length)
Raw output
./.github/workflows/github_tag_and_release.yml:81:121: [warning] line too long (121 > 120 characters) (line-length)
id: check_docker_image_tagged_latest
# yamllint disable rule:line-length
run: |
docker pull ${{env.docker_repo}}:${{ needs.tag.outputs.semver }}
echo "IS_LATEST_TAGGED_CORRECTLY=$(docker image inspect ${{env.docker_repo}}:${{ needs.tag.outputs.semver }} | jq -r '.[] | (.RepoTags) | any( . == "${{env.docker_repo}}:latest") ')" >> "$GITHUB_OUTPUT"
# yamllint enable rule:line-length

Check failure on line 88 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L88

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:88:1: [error] trailing spaces (trailing-spaces)
- name: Fail if latest is not tagged correctly
if: ${{ steps.check_docker_image_tagged_latest.outputs.IS_LATEST_TAGGED_CORRECTLY == 'false' }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('The newly released Docker image ${{ needs.tag.outputs.semver }} is not tagged latest. ')

Check failure on line 95 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L95

[error] no new line character at the end of file (new-line-at-end-of-file)
Raw output
./.github/workflows/github_tag_and_release.yml:95:3: [error] no new line character at the end of file (new-line-at-end-of-file)

Check failure on line 95 in .github/workflows/github_tag_and_release.yml

View workflow job for this annotation

GitHub Actions / yamllint

[yamllint] .github/workflows/github_tag_and_release.yml#L95

[error] trailing spaces (trailing-spaces)
Raw output
./.github/workflows/github_tag_and_release.yml:95:1: [error] trailing spaces (trailing-spaces)

0 comments on commit e7aa331

Please sign in to comment.