Docker Hub Release #243
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Hub Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| use-main: | |
| description: 'Checkout the main branch inside the workflow' | |
| required: true | |
| default: false | |
| type: boolean | |
| jobs: | |
| check-trigger: | |
| name: Check Trigger | |
| runs-on: ubuntu-latest | |
| outputs: | |
| release-to-dockerhub: ${{ steps.check-trigger.outputs.release }} | |
| version: ${{ steps.check-trigger.outputs.version }} | |
| tag: ${{ steps.check-trigger.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| ref: ${{ inputs.use-main && 'main' || github.ref }} | |
| fetch-depth: 5 | |
| fetch-tags: true | |
| - name: Check trigger | |
| id: check-trigger | |
| run: | | |
| TAG=$(git tag --points-at HEAD | grep -E '^v[0-9.]+' | sort -r | head -n 1) | |
| TAGGED_VERSION=$(echo $TAG | cut -c2-) | |
| CURRENT_VERSION=$(cat package.json | jq -r .version) | |
| PREVIOUS_VERSION=$(git show HEAD~1:package.json | jq -r .version) | |
| echo "Tagged Version: $TAGGED_VERSION" | |
| echo "Current Version: $CURRENT_VERSION" | |
| echo "Previous Version: $PREVIOUS_VERSION" | |
| echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| if [ "$CURRENT_VERSION" == "$TAGGED_VERSION" ] && [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then | |
| echo "Tagged & Version Increased. Triggering Docker Hub build..." | |
| echo "release=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Skipping Docker Hub build..." | |
| echo "release=false" >> $GITHUB_OUTPUT | |
| fi | |
| build: | |
| name: Build & Release | |
| runs-on: ubuntu-latest | |
| needs: check-trigger | |
| if: needs.check-trigger.outputs.release-to-dockerhub == 'true' | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| ref: ${{ inputs.use-main && 'main' || github.ref }} | |
| fetch-depth: 5 | |
| fetch-tags: true | |
| - name: Generate Docker Tags | |
| id: traffic-analytics-docker-metadata | |
| uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6 | |
| with: | |
| images: | | |
| ghost/traffic-analytics | |
| tags: | | |
| ${{ github.ref == 'refs/heads/main' && 'type=edge,branch=main' || '' }} | |
| type=semver,pattern={{version}},value=${{ needs.check-trigger.outputs.tag }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ needs.check-trigger.outputs.tag }} | |
| type=semver,pattern={{major}},value=${{ needs.check-trigger.outputs.tag }} | |
| type=sha,priority=1100 | |
| type=sha,format=long | |
| - name: Extract node version | |
| id: extract-node-version | |
| uses: ./.github/actions/extract-node-version | |
| - name: Build Docker Image | |
| id: docker-build | |
| uses: ./.github/actions/docker-build | |
| with: | |
| node-version: ${{ fromJSON(steps.extract-node-version.outputs.node-version) }} | |
| build-multiarchitecture: true | |
| - name: Lint & Test | |
| uses: ./.github/actions/lint-and-test | |
| with: | |
| docker-image: ${{ steps.docker-build.outputs.base-image-name }} | |
| - name: "Login to Docker Hub" | |
| uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Retag & Push Docker Image | |
| run: | | |
| for tag in $(echo "${{ steps.traffic-analytics-docker-metadata.outputs.tags }}"); do | |
| echo "Tagging: $tag" | |
| docker tag ${{ steps.docker-build.outputs.production-image-name }} $tag | |
| done | |
| for tag in $(echo "${{ steps.traffic-analytics-docker-metadata.outputs.tags }}"); do | |
| echo "Pushing: $tag" | |
| docker push $tag | |
| done |