|
| 1 | +name: Container |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + workflow_run: |
| 10 | + workflows: [Releaser] |
| 11 | + types: |
| 12 | + - completed |
| 13 | + pull_request: |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +env: |
| 20 | + REGISTRY: ghcr.io |
| 21 | + IMAGE_NAME: ${{ github.repository }} |
| 22 | + |
| 23 | +jobs: |
| 24 | + # PR Build Check - validate Dockerfile compiles, single platform, no push |
| 25 | + build-check: |
| 26 | + if: github.event_name == 'pull_request' |
| 27 | + name: Build Check |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Set up Docker Buildx |
| 34 | + uses: docker/setup-buildx-action@v3 |
| 35 | + |
| 36 | + - name: Build (amd64 only, no push) |
| 37 | + uses: docker/build-push-action@v6 |
| 38 | + with: |
| 39 | + context: . |
| 40 | + push: false |
| 41 | + platforms: linux/amd64 |
| 42 | + cache-from: type=gha |
| 43 | + |
| 44 | + # Prepare ref for Releaser workflow integration |
| 45 | + prepare-checkout: |
| 46 | + if: github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' |
| 47 | + name: Prepare ref |
| 48 | + runs-on: ubuntu-latest |
| 49 | + outputs: |
| 50 | + ref: ${{ steps.releaser.outputs.version }} |
| 51 | + steps: |
| 52 | + - name: Get ref from Releaser |
| 53 | + id: releaser |
| 54 | + uses: ipdxco/unified-github-workflows/.github/actions/inspect-releaser@v1.0 |
| 55 | + with: |
| 56 | + artifacts-url: ${{ github.event.workflow_run.artifacts_url }} |
| 57 | + |
| 58 | + # Publish on push to main branch |
| 59 | + publish-main: |
| 60 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 61 | + name: Publish (main) |
| 62 | + runs-on: ubuntu-latest |
| 63 | + permissions: |
| 64 | + contents: read |
| 65 | + packages: write |
| 66 | + steps: |
| 67 | + - name: Checkout |
| 68 | + uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - name: Set up QEMU |
| 71 | + uses: docker/setup-qemu-action@v3 |
| 72 | + |
| 73 | + - name: Set up Docker Buildx |
| 74 | + uses: docker/setup-buildx-action@v3 |
| 75 | + |
| 76 | + - name: Log in to Container registry |
| 77 | + uses: docker/login-action@v3 |
| 78 | + with: |
| 79 | + registry: ${{ env.REGISTRY }} |
| 80 | + username: ${{ github.actor }} |
| 81 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + |
| 83 | + - name: Extract metadata |
| 84 | + id: meta |
| 85 | + uses: docker/metadata-action@v5 |
| 86 | + with: |
| 87 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 88 | + tags: | |
| 89 | + type=raw,value=main |
| 90 | + type=sha,prefix=sha-,format=short |
| 91 | +
|
| 92 | + - name: Build and push |
| 93 | + uses: docker/build-push-action@v6 |
| 94 | + with: |
| 95 | + context: . |
| 96 | + push: true |
| 97 | + platforms: linux/amd64,linux/arm64 |
| 98 | + tags: ${{ steps.meta.outputs.tags }} |
| 99 | + labels: ${{ steps.meta.outputs.labels }} |
| 100 | + cache-from: type=gha |
| 101 | + cache-to: type=gha,mode=max |
| 102 | + |
| 103 | + # Publish on release tag (v*) - direct push or via Releaser |
| 104 | + publish-release: |
| 105 | + name: Publish (release) |
| 106 | + needs: [prepare-checkout] |
| 107 | + # Run if: direct tag push OR workflow_run completed successfully |
| 108 | + # always() allows running even when prepare-checkout was skipped (direct tag push) |
| 109 | + if: | |
| 110 | + always() && !cancelled() && !failure() && |
| 111 | + ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || |
| 112 | + (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')) |
| 113 | + runs-on: ubuntu-latest |
| 114 | + permissions: |
| 115 | + contents: read |
| 116 | + packages: write |
| 117 | + steps: |
| 118 | + - name: Determine ref |
| 119 | + id: ref |
| 120 | + run: | |
| 121 | + if [ "${{ github.event_name }}" = "workflow_run" ]; then |
| 122 | + echo "ref=${{ needs.prepare-checkout.outputs.ref }}" >> $GITHUB_OUTPUT |
| 123 | + else |
| 124 | + echo "ref=${{ github.ref }}" >> $GITHUB_OUTPUT |
| 125 | + fi |
| 126 | +
|
| 127 | + - name: Checkout |
| 128 | + uses: actions/checkout@v4 |
| 129 | + with: |
| 130 | + ref: ${{ steps.ref.outputs.ref }} |
| 131 | + |
| 132 | + - name: Set up QEMU |
| 133 | + uses: docker/setup-qemu-action@v3 |
| 134 | + |
| 135 | + - name: Set up Docker Buildx |
| 136 | + uses: docker/setup-buildx-action@v3 |
| 137 | + |
| 138 | + - name: Log in to Container registry |
| 139 | + uses: docker/login-action@v3 |
| 140 | + with: |
| 141 | + registry: ${{ env.REGISTRY }} |
| 142 | + username: ${{ github.actor }} |
| 143 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 144 | + |
| 145 | + - name: Extract metadata |
| 146 | + id: meta |
| 147 | + uses: docker/metadata-action@v5 |
| 148 | + with: |
| 149 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 150 | + tags: | |
| 151 | + type=semver,pattern={{version}} |
| 152 | +
|
| 153 | + - name: Build and push |
| 154 | + uses: docker/build-push-action@v6 |
| 155 | + with: |
| 156 | + context: . |
| 157 | + push: true |
| 158 | + platforms: linux/amd64,linux/arm64 |
| 159 | + tags: ${{ steps.meta.outputs.tags }} |
| 160 | + labels: ${{ steps.meta.outputs.labels }} |
| 161 | + cache-from: type=gha |
| 162 | + cache-to: type=gha,mode=max |
0 commit comments