|
| 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 | +jobs: |
| 16 | + prepare-checkout: |
| 17 | + if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' |
| 18 | + name: Prepare ref |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + ref: ${{ github.event_name != 'workflow_run' && github.ref || steps.releaser.outputs.version }} |
| 22 | + steps: |
| 23 | + - name: Get Ref from releaser |
| 24 | + id: releaser |
| 25 | + if: github.event_name == 'workflow_run' |
| 26 | + uses: ipdxco/unified-github-workflows/.github/actions/inspect-releaser@v1.0 |
| 27 | + with: |
| 28 | + artifacts-url: ${{ github.event.workflow_run.artifacts_url }} |
| 29 | + publish: |
| 30 | + name: Publish |
| 31 | + needs: [ prepare-checkout ] |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: read |
| 35 | + packages: write |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v3 |
| 39 | + with: |
| 40 | + ref: ${{ needs.prepare-checkout.outputs.ref }} |
| 41 | + - name: Set up Docker Buildx |
| 42 | + uses: docker/setup-buildx-action@v2 |
| 43 | + - name: Log in to the Container registry |
| 44 | + uses: docker/login-action@v2 |
| 45 | + with: |
| 46 | + registry: ghcr.io |
| 47 | + username: ${{ github.actor }} |
| 48 | + password: ${{ github.token }} |
| 49 | + - name: Extract metadata |
| 50 | + id: meta |
| 51 | + uses: docker/metadata-action@v4 |
| 52 | + with: |
| 53 | + images: ghcr.io/${{ github.repository }} |
| 54 | + tags: | |
| 55 | + type=semver,pattern={{raw}} |
| 56 | + type=ref,event=branch |
| 57 | + type=raw,value=${{ needs.prepare-checkout.outputs.ref }} |
| 58 | + - name: Build and push Docker image |
| 59 | + uses: docker/build-push-action@v4 |
| 60 | + with: |
| 61 | + context: . |
| 62 | + cache-from: type=gha |
| 63 | + cache-to: type=gha,mode=max |
| 64 | + push: ${{ github.event_name != 'pull_request' }} |
| 65 | + tags: ${{ steps.meta.outputs.tags }} |
| 66 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments