|
| 1 | +name: Build and publish Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [test/workflow] |
| 6 | + workflow_dispatch: |
| 7 | + pull_request: |
| 8 | + types: [closed] |
| 9 | + branches: [main] |
| 10 | + |
| 11 | +concurrency: production |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + name: Tag and create GitHub release |
| 16 | + if: github.event.pull_request.merged == true |
| 17 | + runs-on: ubuntu-24.04-arm |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + outputs: |
| 21 | + new_tag: ${{ steps.version.outputs.new_tag }} |
| 22 | + part: ${{ steps.version.outputs.part }} |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Bump release version and push tag |
| 28 | + id: version |
| 29 | + uses: anothrNick/github-tag-action@1.71.0 |
| 30 | + env: |
| 31 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + GIT_API_TAGGING: true |
| 33 | + WITH_V: false |
| 34 | + INITIAL_VERSION: 1.0.0 |
| 35 | + DEFAULT_BUMP: patch |
| 36 | + DEFAULT_BRANCH: main |
| 37 | + RELEASE_BRANCHES: main |
| 38 | + |
| 39 | + - name: Create a GitHub release |
| 40 | + uses: ncipollo/release-action@v1 |
| 41 | + with: |
| 42 | + tag: ${{ steps.version.outputs.new_tag }} |
| 43 | + name: Release ${{ steps.version.outputs.new_tag }} |
| 44 | + body: ${{ steps.version.outputs.changelog }} |
| 45 | + |
| 46 | + publish: |
| 47 | + name: Build and publish Docker image to GitHub Packages |
| 48 | + needs: release |
| 49 | + if: needs.release.outputs.part != 'patch' |
| 50 | + runs-on: ubuntu-24.04-arm |
| 51 | + permissions: |
| 52 | + packages: write |
| 53 | + contents: read |
| 54 | + steps: |
| 55 | + - name: Checkout repository |
| 56 | + uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Authenticate with GitHub Container Registry |
| 59 | + uses: docker/login-action@v3 |
| 60 | + with: |
| 61 | + registry: ghcr.io |
| 62 | + username: ${{ github.actor }} |
| 63 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + |
| 65 | + - name: Add tags and labels |
| 66 | + id: meta |
| 67 | + uses: docker/metadata-action@v5 |
| 68 | + with: |
| 69 | + images: ghcr.io/${{ github.repository }} |
| 70 | + tags: type=semver,pattern={{version}},value=${{ needs.release.outputs.new_tag }} |
| 71 | + flavor: latest=auto |
| 72 | + |
| 73 | + - name: Set up QEMU |
| 74 | + uses: docker/setup-qemu-action@v3 |
| 75 | + with: |
| 76 | + platforms: arm64 |
| 77 | + |
| 78 | + - name: Set up Docker Buildx |
| 79 | + uses: docker/setup-buildx-action@v3 |
| 80 | + with: |
| 81 | + platforms: linux/arm64 |
| 82 | + |
| 83 | + - name: Build and push Docker image |
| 84 | + uses: docker/build-push-action@v6 |
| 85 | + with: |
| 86 | + context: . |
| 87 | + file: ./Dockerfile |
| 88 | + platforms: linux/arm64 |
| 89 | + push: true |
| 90 | + tags: | |
| 91 | + ghcr.io/${{ github.repository }}:${{ needs.release.outputs.new_tag }} |
| 92 | + ghcr.io/${{ github.repository }}:latest |
| 93 | + labels: ${{ steps.meta.outputs.labels }} |
| 94 | + cache-from: type=gha |
| 95 | + cache-to: type=gha,mode=max |
0 commit comments