diff --git a/.github/workflows/docker-build-release.yml b/.github/workflows/docker-build-release.yml index 39b5b700..ba3e37dd 100644 --- a/.github/workflows/docker-build-release.yml +++ b/.github/workflows/docker-build-release.yml @@ -4,11 +4,14 @@ name: Publish Docker image on: push: - branches: ['main', 'main_docker'] + branches: ["main", "main_docker"] + # Publish semver tags as releases. + tags: ["v*.*.*"] env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository_owner }}/gamgee + # github.repository as / + IMAGE_NAME: ${{ github.repository }} jobs: build-and-push-image: @@ -19,18 +22,31 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Log in to the registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + - name: Log in to registry ${{ env.REGISTRY }} + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + # Extract metadata (tags, labels) for Docker + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + - name: Build and push Docker image - uses: docker/build-push-action@v4 + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 with: context: . push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}