diff --git a/.github/workflows/images.yaml b/.github/workflows/images.yaml index 494cb11f..08a8d00c 100644 --- a/.github/workflows/images.yaml +++ b/.github/workflows/images.yaml @@ -6,6 +6,9 @@ on: - master # Trigger the workflow on push to the master branch tags: - 'v*' # Trigger the workflow on tags like v1.0.0, v2.0.0, etc. + pull_request: + branches: + - master # Trigger workflow when a PR targets the master branch permissions: contents: read @@ -49,9 +52,18 @@ jobs: with: context: . push: true - # Tag the image as 'latest' for master branch and as the version tag for versioned pushes + # Tags the image as 'latest' only for master branch, versioned tags for versioned pushes, and PR-specific tags tags: | + # Version tags for releases ${{ steps.meta.outputs.tags }} - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/} # This will use the tag from the push + + # Latest tag for master branch only + ${{ github.ref == 'refs/heads/master' && env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + + # PR-specific tag (only applies during PR events) + ${{ github.event_name == 'pull_request' && env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.pull_request.number }} + + # Commit SHA for PR builds for more precise versioning + ${{ github.event_name == 'pull_request' && env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} + labels: ${{ steps.meta.outputs.labels }}