|
1 | 1 | name: release |
2 | 2 | on: |
3 | | - # Test that it works on pull_request or merge group; goreleaser goes into snapshot mode if not a tag. |
| 3 | + # Test that it works on pull_request or merge group; |
| 4 | + # goreleaser goes into snapshot mode if not a tag; |
| 5 | + # docker image will be built but not pushed for pull requests or merge group events. |
4 | 6 | pull_request: |
5 | 7 | merge_group: |
6 | 8 | push: |
7 | 9 | tags: |
8 | 10 | - v* |
9 | 11 |
|
| 12 | +env: |
| 13 | + # Use docker.io for Docker Hub if empty |
| 14 | + REGISTRY: ghcr.io |
| 15 | + # github.repository as <account>/<repo> |
| 16 | + IMAGE_NAME: ${{ github.repository }} |
| 17 | + |
10 | 18 | jobs: |
11 | 19 | goreleaser: |
12 | 20 | runs-on: ubuntu-latest |
|
32 | 40 | args: release --rm-dist ${{ env.flags }} |
33 | 41 | env: |
34 | 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + docker-release: |
| 44 | + runs-on: ubuntu-latest |
| 45 | + permissions: |
| 46 | + # docker writes packages to container registry |
| 47 | + packages: write |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + fetch-depth: 0 |
| 52 | + - run: git fetch --force --tags |
| 53 | + - name: Log in to the Container registry |
| 54 | + uses: docker/login-action@v3.0.0 |
| 55 | + with: |
| 56 | + registry: ${{ env.REGISTRY }} |
| 57 | + username: ${{ github.actor }} |
| 58 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + - name: Extract metadata (tags, labels) for Docker |
| 60 | + id: meta |
| 61 | + uses: docker/metadata-action@v5.4.0 |
| 62 | + with: |
| 63 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 64 | + - name: Build and push Docker image (image is not pushed on pull request) |
| 65 | + uses: docker/build-push-action@v5.1.0 |
| 66 | + with: |
| 67 | + context: . |
| 68 | + push: ${{ github.event_name != 'pull_request' && github.event_name != 'merge_group' }} |
| 69 | + tags: ${{ steps.meta.outputs.tags }} |
| 70 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments