Skip to content

Commit 204b355

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

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
`"tags" output must contain 2 tags for push event`
8888
);
8989
90-
assert.equal(tag[0],"ghcr.io/hoverkraft-tech/ci-github-container/application-test:main", `"tags" output is not valid`);
90+
assert.equal(tags[0],"ghcr.io/hoverkraft-tech/ci-github-container/application-test:main", `"tags" output is not valid`);
9191
assert.equal(tags[1],"ghcr.io/hoverkraft-tech/ci-github-container/application-test:latest", `"tags" output is not valid`);
9292
}
9393

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,17 @@ runs:
6666
with:
6767
result-encoding: string
6868
script: |
69-
// If push on default branch set tag to latest
70-
const isPushOnDefaultBranch = context.eventName === 'push' && `${{ github.ref }}` === `${{ github.event.repository.default_branch }}`;
71-
core.setOutput('flavor', isPushOnDefaultBranch ? 'latest=true' : 'latest=false');
72-
7369
const tagInput = `${{ inputs.tag }}`
7470
if (tagInput.length) {
7571
core.setOutput('tags',`type=semver,pattern={{raw}},value=${tagInput}`);
72+
core.setOutput('flavor', 'latest=false');
7673
return;
7774
}
7875
76+
// If push on default branch set tag to latest
77+
const isPushOnDefaultBranch = context.eventName === 'push' && `${{ github.ref }}` === `refs/heads/${{ github.event.repository.default_branch }}`;
78+
core.setOutput('flavor', isPushOnDefaultBranch ? 'latest=true' : 'latest=false');
79+
7980
const isPullRequestOrIssueComment =
8081
context.eventName === 'pull_request'
8182
|| context.eventName === 'pull_request_review'
@@ -122,9 +123,21 @@ runs:
122123
core.setOutput('annotations', annotations);
123124
124125
const tags = `${{ steps.docker-metadata.outputs.tags }}`;
126+
125127
const sortedTags = tags
126128
.split("\n")
127-
.sort((a, b) => b.length - a.length)
129+
.sort((a, b) => {
130+
// Move "latest" at the end
131+
if (a.includes("latest")) {
132+
return 1
133+
};
134+
if (b.includes("latest")) {
135+
return -1
136+
};
137+
138+
// Sort by length
139+
return b.length - a.length;
140+
})
128141
.join("\n");
129142
130143
core.setOutput('tags', sortedTags);

0 commit comments

Comments
 (0)