@@ -35,27 +35,35 @@ 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 :
42
42
- name : Set up Docker Buildx
43
43
uses : docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
44
44
with :
45
45
driver : docker-container
46
- # Avoiding using `docker/metadata-action`'s `type=sha` as it is limited to either
47
- # `github.sha` or `github.event.pull_request.head.sha` (when `DOCKER_METADATA_PR_HEAD_SHA=true`).
48
- # https://github.com/docker/metadata-action/issues/206
49
- # https://github.com/docker/metadata-action/issues/362
50
46
- name : Determine commit SHA
51
- id : commit-head
47
+ id : commit
52
48
shell : bash
53
49
run : |
54
50
# Determine commit SHA
55
51
sha="$(git rev-parse HEAD)"
56
- short_sha="$(git rev-parse --short "$sha")"
57
52
echo "sha=$sha" | tee -a "$GITHUB_OUTPUT"
58
- echo "short-sha=$short_sha" | tee -a "$GITHUB_OUTPUT"
53
+
54
+ case "$sha" in
55
+ "${{ github.event.pull_request.head.sha }}")
56
+ is_pr_head_sha=true
57
+ ;;
58
+ "${{ github.sha }}")
59
+ is_pr_head_sha=false
60
+ ;;
61
+ *)
62
+ echo "Context uses unexpected commit SHA" >&2
63
+ exit 1
64
+ ;;
65
+ esac
66
+ echo "is-pr-head-sha=${is_pr_head_sha}" | tee -a "$GITHUB_OUTPUT"
59
67
# Optional branch name (e.g. "main") for workflows triggered by `pull_request` or `push` events.
60
68
- name : Branch
61
69
id : branch
72
80
images : |
73
81
${{ inputs.image-repository }}
74
82
tags : |
75
- type=raw ,prefix=sha-,value=${{ steps.commit-head.outputs. short-sha }}
83
+ type=sha ,prefix=sha-,format= short
76
84
type=ref,prefix=pr-,event=pr
77
85
type=raw,prefix=branch-,value=${{ steps.branch.outputs.name }},enable=${{ steps.branch.outputs.name != '' }}
86
+ env :
87
+ # https://github.com/docker/metadata-action/issues/206
88
+ DOCKER_METADATA_PR_HEAD_SHA : ${{ steps.commit.outputs.is-pr-head-sha }}
78
89
# Use separate cache images to avoid bloating final images
79
90
# https://docs.docker.com/build/cache/backends/registry/
80
91
- name : Docker cache-from
@@ -85,18 +96,24 @@ runs:
85
96
images : |
86
97
${{ inputs.image-repository }}
87
98
tags : |
88
- type=raw ,prefix=cache-sha-,value=${{ steps.commit-head.outputs.sha }}
99
+ type=sha ,prefix=cache-sha-,format=long
89
100
type=raw,prefix=cache-branch-,value=${{ steps.branch.outputs.name }},enable=${{ steps.branch.outputs.name != '' }}
90
101
type=raw,prefix=cache-sha-,value=${{ github.event.pull_request.base.sha }},enable=${{ github.event_name == 'pull_request' }}
102
+ env :
103
+ # https://github.com/docker/metadata-action/issues/206
104
+ DOCKER_METADATA_PR_HEAD_SHA : ${{ steps.commit.outputs.is-pr-head-sha }}
91
105
- name : Docker cache-to
92
106
id : cache-to
93
107
uses : docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
94
108
with :
95
109
images : |
96
110
${{ inputs.image-repository }}
97
111
tags : |
98
- type=raw ,prefix=cache-sha-,value=${{ steps.commit-head.outputs.sha }}
112
+ type=sha ,prefix=cache-sha-,format=long
99
113
type=raw,prefix=cache-branch-,value=${{ steps.branch.outputs.name }},enable=${{ steps.branch.outputs.name != '' }}
114
+ env :
115
+ # https://github.com/docker/metadata-action/issues/206
116
+ DOCKER_METADATA_PR_HEAD_SHA : ${{ steps.commit.outputs.is-pr-head-sha }}
100
117
# Disable environmental variables set by `docker/metadata-action`:
101
118
# https://github.com/docker/metadata-action#outputs
102
119
# https://github.com/docker/metadata-action/issues/490
0 commit comments