Skip to content

Commit 7b6e76f

Browse files
committed
fix(docker/get-image-metada): set latest tag when necessary
Signed-off-by: Emilien Escalle <[email protected]>
1 parent ab5833e commit 7b6e76f

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

.github/workflows/__test-action-get-image-metadata.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,36 @@ jobs:
6060
6161
const tagsOutput = `${{ steps.get-image-metadata.outputs.tags }}`;
6262
assert(tagsOutput.length, `"tags" output is empty`);
63-
assert(tagsOutput.startsWith("ghcr.io/hoverkraft-tech/ci-github-container/application-test:"), `"tags" output is not valid`);
63+
64+
const tags = tagsOutput.split("\n").filter(Boolean);
65+
assert(tags.length, `"tags" output is empty`);
66+
67+
if (`${{ github.event_name }}` === "pull_request") {
68+
assert.equal(
69+
tags.length,
70+
2,
71+
`"tags" output must contain 2 tags for pull_request event`
72+
);
73+
74+
assert(
75+
tags[0].startsWith("ghcr.io/hoverkraft-tech/ci-github-container/application-test:pr-${{ github.event.pull_request.number }}-"),
76+
`"tags" output is not valid`
77+
);
78+
79+
assert.equal(
80+
tags[1],
81+
"ghcr.io/hoverkraft-tech/ci-github-container/application-test:pr-${{ github.event.pull_request.number }}", `"tags" output is not valid`
82+
);
83+
} else {
84+
assert.equal(
85+
tags.length,
86+
2,
87+
`"tags" output must contain 2 tags for push event`
88+
);
89+
90+
assert.equal(tag[0],"ghcr.io/hoverkraft-tech/ci-github-container/application-test:main", `"tags" output is not valid`);
91+
assert.equal(tags[1],"ghcr.io/hoverkraft-tech/ci-github-container/application-test:latest", `"tags" output is not valid`);
92+
}
6493
6594
tests-with-given-tag:
6695
name: Test for "docker/get-image-metadata" action with given tag

actions/docker/get-image-metadata/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ runs:
6767
result-encoding: string
6868
script: |
6969
// If push on default branch set tag to latest
70-
const isPushOnDefaultBranch = context.eventName === 'push' && context.ref === `refs/heads/${{ github.base_ref }}`;
70+
const isPushOnDefaultBranch = context.eventName === 'push' && `${{ github.ref }}` === `${{ github.event.repository.default_branch }}`;
7171
core.setOutput('flavor', isPushOnDefaultBranch ? 'latest=true' : 'latest=false');
7272
7373
const tagInput = `${{ inputs.tag }}`

0 commit comments

Comments
 (0)