Skip to content

Commit 58871a4

Browse files
committed
ci: improve tests to pass with workflow_dispatch event
Signed-off-by: Emilien Escalle <[email protected]>
1 parent 0cbf7fe commit 58871a4

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

.github/workflows/__test-action-docker-build-image.yml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,38 @@ jobs:
109109
`"annotations.org.opencontainers.image.url" output is not valid`
110110
);
111111
112+
const expectedTags = [];
113+
let expectedImageVersion;
112114
if (`${{ github.event_name }}` === "pull_request") {
113115
const shortSha = `${{ github.sha }}`.substring(0, 7);
114116
const prShaTag = `pr-${{ github.event.pull_request.number }}-${shortSha}`;
115117
const prTag = `pr-${{ github.event.pull_request.number }}`;
116118
117-
assert.equal(builtImage.tags.length, 2, `"tags" output is not valid`);
118-
119-
assert.equal(builtImage.tags[0], prShaTag, `"tags" output is not valid`);
120-
assert.equal(builtImage.tags[1], prTag, `"tags" output is not valid`);
121-
122-
assert.equal(
123-
builtImage.annotations["org.opencontainers.image.version"],
124-
prTag,
125-
`"annotations.org.opencontainers.image.version" output is not valid`
126-
);
119+
expectedTags.push(prShaTag, prTag);
120+
expectedImageVersion = prShaTag;
127121
} else {
128122
const refTag = `${{ github.ref_name }}`;
123+
expectedTags.push(refTag);
124+
expectedImageVersion = refTag;
129125
130-
assert.equal(builtImage.tags.length, 2, `"tags" output is not valid`);
131-
assert.equal(builtImage.tags[0], refTag, `"tags" output is not valid`);
132-
assert.equal(builtImage.tags[1], "latest", `"tags" output is not valid`);
126+
if (`${{ github.event_name }}` !== "workflow_dispatch") {
127+
expectedTags.push("latest");
128+
}
129+
}
133130
134-
assert.equal(
135-
builtImage.annotations["org.opencontainers.image.version"],
136-
refTag,
137-
`"annotations.org.opencontainers.image.version" output is not valid`
138-
);
131+
assert.equal(builtImage.tags.length, expectedTags.length, `"tags" output is not valid, expected ${expectedTags.length} tags but got ${builtImage.tags.length}`);
132+
for (const expectedTag of expectedTags) {
133+
if (!builtImage.tags.includes(expectedTag)) {
134+
assert.fail(`Expected tag "${expectedTag}" not found in "tags" output`);
135+
}
139136
}
140137
138+
assert.equal(
139+
builtImage.annotations["org.opencontainers.image.version"],
140+
refTag,
141+
`"annotations.org.opencontainers.image.version" output is not valid`
142+
);
143+
141144
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
142145
with:
143146
registry: ghcr.io

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,33 @@ jobs:
7777
const tags = tagsOutput.split("\n").filter(Boolean);
7878
assert(tags.length, `"tags" output is empty`);
7979
80-
if (`${{ github.event_name }}` === "pull_request") {
81-
assert.equal(
82-
tags.length,
83-
2,
84-
`"tags" output must contain 2 tags for pull_request event`
85-
);
80+
const expectedTags = [];
8681
87-
assert(
88-
tags[0].startsWith("ghcr.io/hoverkraft-tech/ci-github-container/application-test:pr-${{ github.event.pull_request.number }}-"),
89-
`"tags" output is not valid`
90-
);
82+
if (`${{ github.event_name }}` === "pull_request") {
83+
const shortSha = `${{ github.sha }}`.substring(0, 7);
84+
const prShaTag = `pr-${{ github.event.pull_request.number }}-${shortSha}`;
85+
const prTag = `pr-${{ github.event.pull_request.number }}`;
9186
92-
assert.equal(
93-
tags[1],
94-
"ghcr.io/hoverkraft-tech/ci-github-container/application-test:pr-${{ github.event.pull_request.number }}", `"tags" output is not valid`
95-
);
87+
expectedTags.push(prShaTag, prTag);
9688
} else {
97-
assert.equal(
98-
tags.length,
99-
2,
100-
`"tags" output must contain 2 tags for push event`
101-
);
89+
expectedTags.push("main");
90+
if (`${{ github.event_name }}` !== "workflow_dispatch") {
91+
expectedTags.push("latest");
92+
}
93+
}
94+
95+
assert.equal(
96+
tags.length,
97+
expectedTags.length,
98+
`"tags" output must contain ${expectedTags.length} tags for ${{ github.event_name }} event`
99+
);
102100
103-
assert.equal(tags[0],"ghcr.io/hoverkraft-tech/ci-github-container/application-test:main", `"tags" output is not valid`);
104-
assert.equal(tags[1],"ghcr.io/hoverkraft-tech/ci-github-container/application-test:latest", `"tags" output is not valid`);
101+
for(const expectedTag of expectedTags) {
102+
const fullTag = `ghcr.io/hoverkraft-tech/ci-github-container/application-test:${expectedTag}`;
103+
assert(
104+
tags.includes(fullTag),
105+
`Expected tag "${fullTag}" not found in "tags" output`
106+
);
105107
}
106108
107109
tests-with-given-tag:

0 commit comments

Comments
 (0)