diff --git a/.github/workflows/github_tag_and_release.yml b/.github/workflows/github_tag_and_release.yml index 0768479..172c230 100644 --- a/.github/workflows/github_tag_and_release.yml +++ b/.github/workflows/github_tag_and_release.yml @@ -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/semver-release-action@v1.3.2 - 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/goreleaser-action@v5.0.0 - 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 + + 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/semver-release-action@v1.3.2 + 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/goreleaser-action@v5.0.0 + 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 }},${{env.docker_repo}}:latest + 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 + # (it is important to have this check to catch any regression, e.g. if we move to a different way of releasing) + 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. ') + \ No newline at end of file