@@ -35,7 +35,7 @@ outputs:
3535 value : ${{ steps.tags.outputs.json }}
3636 commit-sha :
3737 description : The Git commit SHA used to build the image.
38- value : ${{ steps.commit-head .outputs.sha }}
38+ value : ${{ steps.commit.outputs.sha }}
3939runs :
4040 using : composite
4141 steps :
@@ -48,14 +48,26 @@ runs:
4848 # https://github.com/docker/metadata-action/issues/206
4949 # https://github.com/docker/metadata-action/issues/362
5050 - name : Determine commit SHA
51- id : commit-head
51+ id : commit
5252 shell : bash
5353 run : |
5454 # Determine commit SHA
5555 sha="$(git rev-parse HEAD)"
56- short_sha="$(git rev-parse --short "$sha")"
5756 echo "sha=$sha" | tee -a "$GITHUB_OUTPUT"
58- echo "short-sha=$short_sha" | tee -a "$GITHUB_OUTPUT"
57+
58+ case "$sha" in
59+ "${{ github.event.pull_request.head.sha }}")
60+ is_pr_head_sha=true
61+ ;;
62+ "${{ github.sha }}")
63+ is_pr_head_sha=false
64+ ;;
65+ *)
66+ echo "Context uses unexpected commit SHA" >&2
67+ exit 1
68+ ;;
69+ esac
70+ echo "is-pr-head-sha=${is_pr_head_sha}" | tee -a "$GITHUB_OUTPUT"
5971 # Optional branch name (e.g. "main") for workflows triggered by `pull_request` or `push` events.
6072 - name : Branch
6173 id : branch
7284 images : |
7385 ${{ inputs.image-repository }}
7486 tags : |
75- type=raw ,prefix=sha-,value=${{ steps.commit-head.outputs. short-sha }}
87+ type=sha ,prefix=sha-,format= short
7688 type=ref,prefix=pr-,event=pr
7789 type=raw,prefix=branch-,value=${{ steps.branch.outputs.name }},enable=${{ steps.branch.outputs.name != '' }}
90+ env :
91+ # https://github.com/docker/metadata-action/issues/206
92+ DOCKER_METADATA_PR_HEAD_SHA : ${{ steps.commit.outputs.is-pr-head-sha }}
7893 # Use separate cache images to avoid bloating final images
7994 # https://docs.docker.com/build/cache/backends/registry/
8095 - name : Docker cache-from
@@ -85,18 +100,24 @@ runs:
85100 images : |
86101 ${{ inputs.image-repository }}
87102 tags : |
88- type=raw ,prefix=cache-sha-,value=${{ steps.commit-head.outputs.sha }}
103+ type=sha ,prefix=cache-sha-,format=long
89104 type=raw,prefix=cache-branch-,value=${{ steps.branch.outputs.name }},enable=${{ steps.branch.outputs.name != '' }}
90105 type=raw,prefix=cache-sha-,value=${{ github.event.pull_request.base.sha }},enable=${{ github.event_name == 'pull_request' }}
106+ env :
107+ # https://github.com/docker/metadata-action/issues/206
108+ DOCKER_METADATA_PR_HEAD_SHA : ${{ steps.commit.outputs.is-pr-head-sha }}
91109 - name : Docker cache-to
92110 id : cache-to
93111 uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
94112 with :
95113 images : |
96114 ${{ inputs.image-repository }}
97115 tags : |
98- type=raw ,prefix=cache-sha-,value=${{ steps.commit-head.outputs.sha }}
116+ type=sha ,prefix=cache-sha-,format=long
99117 type=raw,prefix=cache-branch-,value=${{ steps.branch.outputs.name }},enable=${{ steps.branch.outputs.name != '' }}
118+ env :
119+ # https://github.com/docker/metadata-action/issues/206
120+ DOCKER_METADATA_PR_HEAD_SHA : ${{ steps.commit.outputs.is-pr-head-sha }}
100121 # Disable environmental variables set by `docker/metadata-action`:
101122 # https://github.com/docker/metadata-action#outputs
102123 # https://github.com/docker/metadata-action/issues/490
0 commit comments