From 7acca7bc10bffd551448944e8ce284018a1d7db1 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Tue, 22 Mar 2022 08:56:56 +0000 Subject: [PATCH] fix(ci): docker metadata image tags - Move metata as top step in publish workflow - Simplify `v0.x.x` check - Dynamically determine base branch --- .github/workflows/ci.yml | 63 +++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a8f957f..982b9462 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,12 @@ jobs: env: DOCKER_BUILDKIT: "1" steps: - - uses: actions/checkout@v2.4.0 + - uses: actions/checkout@v3 + + - uses: reviewdog/action-misspell@v1 + with: + locale: "US" + level: error - name: Linting run: docker build --target lint . @@ -84,7 +89,26 @@ jobs: needs: [verify] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.4.0 + - uses: actions/checkout@v3 + + # extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v3 + with: + flavor: | + latest=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} + images: | + qmcgaw/gluetun + qmcgaw/private-internet-access + tags: | + type=ref,event=branch,enable=${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }} + type=ref,event=pr + type=semver,pattern=v{{major}}.{{minor}}.{{patch}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} - uses: docker/setup-qemu-action@v1 - uses: docker/setup-buildx-action@v1 @@ -94,45 +118,12 @@ jobs: username: qmcgaw password: ${{ secrets.DOCKERHUB_PASSWORD }} - - name: Check for semver tag - id: semvercheck - run: | - if [[ ${{ github.ref }} =~ ^refs\/tags\/v0\.[0-9]+\.[0-9]+$ ]]; then - MATCH=true - else - MATCH=false - fi - if [[ ${{ github.ref }} =~ ^refs\/tags\/v[1-9]+\.[0-9]+\.[0-9]+$ ]]; then - MATCH=$MATCH_nonzero - fi - echo ::set-output name=match::$MATCH - - # extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@v3 - with: - flavor: | - latest=${{ github.ref == 'refs/heads/master' }} - images: | - qmcgaw/gluetun - qmcgaw/private-internet-access - tags: | - type=ref,event=branch,enable=${{ github.ref != 'refs/heads/master' }} - type=ref,event=pr - type=ref,event=tag,enable=${{ !startsWith(steps.semvercheck.outputs.match, 'true') }} - type=semver,pattern=v{{major}}.{{minor}}.{{patch}},enable=${{ startsWith(steps.semvercheck.outputs.match, 'true') }} - type=semver,pattern=v{{major}}.{{minor}},enable=${{ startsWith(steps.semvercheck.outputs.match, 'true') }} - type=semver,pattern=v{{major}},enable=${{ startsWith(steps.semvercheck.outputs.match, 'true_nonzero') }} - type=raw,value=latest,enable=${{ !startsWith(steps.semvercheck.outputs.match, 'true') }} - - name: Short commit id: shortcommit run: echo "::set-output name=value::$(git rev-parse --short HEAD)" - name: Build and push final image - uses: docker/build-push-action@v2.7.0 + uses: docker/build-push-action@v2.9.0 with: platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v6,linux/arm/v7,linux/ppc64le labels: ${{ steps.meta.outputs.labels }}