Skip to content

Commit 0192482

Browse files
goruhapk-nbmilldr
authored
feat: Parameterized DOCKER_METADATA_PR_HEAD_SHA to allow for PR-HEAD tagging (#41)
* Parameterized DOCKER_METADATA_PR_HEAD_SHA to allow for PR-HEAD tagging By default, Github Action uses merge commits during PR events for the (referenced via the `github.sha` variable). Some users find this challenging, since the merge commit contains code from the target branch, which is troublesome for long-running branches, merge-conflicts, and a hotfix workflow for deploying one-off containers. This allows users to configure docker metadata-action to compute the SHA tags appropriately. Unfortunately the metadata-action does not compute based on a checkout action of the code, so we have to tell it to use the correct event SHA explicitly with this environment variable. See https://github.com/docker/metadata-action#environment-variables * Fix the datatype for the linter Co-authored-by: Dan Miller <[email protected]> --------- Co-authored-by: Nathanael Beisiegel <[email protected]> Co-authored-by: Dan Miller <[email protected]>
1 parent 4bf4c9a commit 0192482

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

action.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ inputs:
6868
secret-files:
6969
description: "List of secret files to expose to the build (e.g., key=filename, MY_SECRET=./secret.txt)"
7070
required: false
71+
docker-metadata-pr-head-sha:
72+
description: "Set to `true` to tag images with the PR HEAD SHA instead of the merge commit SHA within pull requests."
73+
required: false
74+
default: "false"
7175
outputs:
7276
image:
7377
description: "Docker image name"
@@ -94,6 +98,14 @@ runs:
9498
- name: Docker meta
9599
id: meta
96100
uses: docker/metadata-action@v4
101+
env:
102+
# Annoyingly, docker computes the SHA tags independently of any checkout
103+
# action. This option tells this action to use the PR HEAD SHA during a
104+
# pull request. It will then use `github.event.pull_request.head.sha`
105+
# instead of the merge commit (`github.sha`). This is useful for folks
106+
# who want to avoid merge commits in their PRs (for hotfix workflows,
107+
# tag predictability, builds on merge-conflicts, etc).
108+
DOCKER_METADATA_PR_HEAD_SHA: ${{ inputs.docker-metadata-pr-head-sha }}
97109
with:
98110
# list of Docker images to use as base name for tags
99111
images: |
@@ -108,7 +120,7 @@ runs:
108120
type=semver,pattern={{major}}.{{minor}}
109121
type=semver,pattern={{major}}
110122
type=raw,value=latest,enable={{is_default_branch}}
111-
type=sha,format=long
123+
type=sha,format=long
112124
${{ inputs.tags }}
113125
labels: |
114126
org.opencontainers.image.source=https://github.com/${{ inputs.organization }}/${{ inputs.repository }}
@@ -133,7 +145,7 @@ runs:
133145
shell: bash
134146
id: buildx-context
135147
run: |
136-
docker context create buildx-context || true
148+
docker context create buildx-context || true
137149
138150
- name: Set up QEMU
139151
uses: docker/setup-qemu-action@v2

0 commit comments

Comments
 (0)