From 96e52f21550839bc0025d24996429f9180c643c3 Mon Sep 17 00:00:00 2001 From: Nikolai Ovtsinnikov Date: Wed, 12 Mar 2025 21:04:59 +0200 Subject: [PATCH] docker-latest workflow updates. Release workflow refactor, add latest tag on release --- .github/workflows/docker-latest.yml | 46 +++++++++++++++++++++++++---- .github/workflows/release.yaml | 7 ++--- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-latest.yml b/.github/workflows/docker-latest.yml index ab55b2b7..5b04971d 100644 --- a/.github/workflows/docker-latest.yml +++ b/.github/workflows/docker-latest.yml @@ -8,8 +8,33 @@ on: push: branches: - master + jobs: + check_commit: + runs-on: ubuntu-latest + outputs: + should_run: ${{ steps.check_commit_message.outputs.should_run }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Check commit message + id: check_commit_message + run: | + COMMIT_MSG=$(git log -1 --pretty=%s) + if [[ "$COMMIT_MSG" == chore* ]]; then + echo "should_run=false" >> $GITHUB_OUTPUT + echo "Skipping workflow for commit: $COMMIT_MSG" + else + echo "should_run=true" >> $GITHUB_OUTPUT + echo "Running workflow for commit: $COMMIT_MSG" + fi + docker: + needs: check_commit + if: ${{ needs.check_commit.outputs.should_run == 'true' }} runs-on: ubuntu-latest steps: - name: Checkout @@ -33,11 +58,22 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v5 + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + latest=false + tags: | + type=raw,value=latest + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + id: push with: context: . - platforms: ${{ steps.buildx.outputs.platforms }} push: true - tags: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + platforms: ${{ steps.buildx.outputs.platforms }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e5317a9a..04b7c24a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -29,11 +29,11 @@ jobs: package-name: ${{env.NPM_MODULE_NAME}} pull-request-title-pattern: 'chore${scope}: release ${version} [skip-ci]' # The logic below handles the npm publication: - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 # these if statements ensure that a publication only occurs when # a new release is created: if: ${{ steps.release.outputs.release_created }} - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v3 with: node-version: 18 registry-url: 'https://registry.npmjs.org' @@ -88,7 +88,7 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} flavor: | - latest=false + latest=auto tags: | type=semver,pattern={{version}},value=v${{needs.release_please.outputs.major}}.${{needs.release_please.outputs.minor}}.${{needs.release_please.outputs.patch}} type=semver,pattern={{major}}.{{minor}},value=v${{needs.release_please.outputs.major}}.${{needs.release_please.outputs.minor}}.${{needs.release_please.outputs.patch}} @@ -109,5 +109,4 @@ jobs: with: subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} subject-digest: ${{ steps.push.outputs.digest }} - push-to-registry: true github-token: ${{ secrets.GITHUB_TOKEN }}