Skip to content

Commit efd8837

Browse files
committed
Back to restricted SHA
1 parent 98b26c0 commit efd8837

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

.github/workflows/integration-tests.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ jobs:
4444
from-scratch: true
4545
- title: Head Commit
4646
commit-sha: ${{ github.event.pull_request.head.sha }}
47-
- title: Fixed Commit
48-
commit-sha: 5921a42f27af154dec1372cb1e1d1fe11c701437
4947
steps:
5048
- name: Job started at
5149
id: job-started

action.yaml

+28-11
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,35 @@ 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 }}
3939
runs:
4040
using: composite
4141
steps:
4242
- name: Set up Docker Buildx
4343
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
4444
with:
4545
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
5046
- name: Determine commit SHA
51-
id: commit-head
47+
id: commit
5248
shell: bash
5349
run: |
5450
# Determine commit SHA
5551
sha="$(git rev-parse HEAD)"
56-
short_sha="$(git rev-parse --short "$sha")"
5752
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"
5967
# Optional branch name (e.g. "main") for workflows triggered by `pull_request` or `push` events.
6068
- name: Branch
6169
id: branch
@@ -72,9 +80,12 @@ runs:
7280
images: |
7381
${{ inputs.image-repository }}
7482
tags: |
75-
type=raw,prefix=sha-,value=${{ steps.commit-head.outputs.short-sha }}
83+
type=sha,prefix=sha-,format=short
7684
type=ref,prefix=pr-,event=pr
7785
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 }}
7889
# Use separate cache images to avoid bloating final images
7990
# https://docs.docker.com/build/cache/backends/registry/
8091
- name: Docker cache-from
@@ -85,18 +96,24 @@ runs:
8596
images: |
8697
${{ inputs.image-repository }}
8798
tags: |
88-
type=raw,prefix=cache-sha-,value=${{ steps.commit-head.outputs.sha }}
99+
type=sha,prefix=cache-sha-,format=long
89100
type=raw,prefix=cache-branch-,value=${{ steps.branch.outputs.name }},enable=${{ steps.branch.outputs.name != '' }}
90101
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 }}
91105
- name: Docker cache-to
92106
id: cache-to
93107
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
94108
with:
95109
images: |
96110
${{ inputs.image-repository }}
97111
tags: |
98-
type=raw,prefix=cache-sha-,value=${{ steps.commit-head.outputs.sha }}
112+
type=sha,prefix=cache-sha-,format=long
99113
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 }}
100117
# Disable environmental variables set by `docker/metadata-action`:
101118
# https://github.com/docker/metadata-action#outputs
102119
# https://github.com/docker/metadata-action/issues/490

0 commit comments

Comments
 (0)