@@ -35,7 +35,7 @@ outputs:
35
35
value : ${{ steps.tags.outputs.json }}
36
36
commit-sha :
37
37
description : The Git commit SHA used to build the image.
38
- value : ${{ steps.commit-head .outputs.sha }}
38
+ value : ${{ steps.commit.outputs.sha }}
39
39
runs :
40
40
using : composite
41
41
steps :
@@ -48,14 +48,26 @@ runs:
48
48
# https://github.com/docker/metadata-action/issues/206
49
49
# https://github.com/docker/metadata-action/issues/362
50
50
- name : Determine commit SHA
51
- id : commit-head
51
+ id : commit
52
52
shell : bash
53
53
run : |
54
54
# Determine commit SHA
55
55
sha="$(git rev-parse HEAD)"
56
- short_sha="$(git rev-parse --short "$sha")"
57
56
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"
59
71
# Optional branch name (e.g. "main") for workflows triggered by `pull_request` or `push` events.
60
72
- name : Branch
61
73
id : branch
72
84
images : |
73
85
${{ inputs.image-repository }}
74
86
tags : |
75
- type=raw ,prefix=sha-,value=${{ steps.commit-head.outputs. short-sha }}
87
+ type=sha ,prefix=sha-,format= short
76
88
type=ref,prefix=pr-,event=pr
77
89
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 }}
78
93
# Use separate cache images to avoid bloating final images
79
94
# https://docs.docker.com/build/cache/backends/registry/
80
95
- name : Docker cache-from
@@ -85,18 +100,24 @@ runs:
85
100
images : |
86
101
${{ inputs.image-repository }}
87
102
tags : |
88
- type=raw ,prefix=cache-sha-,value=${{ steps.commit-head.outputs.sha }}
103
+ type=sha ,prefix=cache-sha-,format=long
89
104
type=raw,prefix=cache-branch-,value=${{ steps.branch.outputs.name }},enable=${{ steps.branch.outputs.name != '' }}
90
105
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 }}
91
109
- name : Docker cache-to
92
110
id : cache-to
93
111
uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
94
112
with :
95
113
images : |
96
114
${{ inputs.image-repository }}
97
115
tags : |
98
- type=raw ,prefix=cache-sha-,value=${{ steps.commit-head.outputs.sha }}
116
+ type=sha ,prefix=cache-sha-,format=long
99
117
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 }}
100
121
# Disable environmental variables set by `docker/metadata-action`:
101
122
# https://github.com/docker/metadata-action#outputs
102
123
# https://github.com/docker/metadata-action/issues/490
0 commit comments