Skip to content

Commit 04bf6ae

Browse files
committed
fix: validate buildx and imageName early for mergeTag, guard empty imageName
- Move isDockerBuildXInstalled() before the mergeTag early return so missing buildx fails immediately with a clear error instead of at runtime in the post step. - Validate imageName is set when mergeTag is used. - Guard buildImageNames calls so empty imageName produces [] instead of invalid image refs like ':latest'.
1 parent c397a55 commit 04bf6ae

4 files changed

Lines changed: 50 additions & 17 deletions

File tree

azdo-task/DevcontainersCi/src/main.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,24 @@ export async function runMain(): Promise<void> {
3636
return;
3737
}
3838

39+
const buildXInstalled = await isDockerBuildXInstalled();
40+
3941
if (mergeTag) {
42+
const imageName = task.getInput('imageName');
43+
if (!imageName) {
44+
task.setResult(
45+
task.TaskResult.Failed,
46+
'imageName is required when using mergeTag',
47+
);
48+
return;
49+
}
50+
if (!buildXInstalled) {
51+
task.setResult(
52+
task.TaskResult.Failed,
53+
'docker buildx is required for mergeTag - add a step to set up docker buildx',
54+
);
55+
return;
56+
}
4057
const pushOption = task.getInput('push');
4158
if (pushOption !== 'always') {
4259
task.setResult(
@@ -51,8 +68,6 @@ export async function runMain(): Promise<void> {
5168
task.setTaskVariable('mergeTag', mergeTag);
5269
return;
5370
}
54-
55-
const buildXInstalled = await isDockerBuildXInstalled();
5671
if (!buildXInstalled) {
5772
console.log(
5873
'### WARNING: docker buildx not available: add a step to set up with docker/setup-buildx-action - see https://github.com/devcontainers/ci/blob/main/docs/azure-devops-task.md',
@@ -113,11 +128,9 @@ export async function runMain(): Promise<void> {
113128

114129
const resolvedImageTag = imageTag ?? 'latest';
115130
const imageTagArray = resolvedImageTag.split(/\s*,\s*/);
116-
const fullImageNameArray = buildImageNames(
117-
imageName ?? '',
118-
imageTagArray,
119-
platformTag,
120-
);
131+
const fullImageNameArray = imageName
132+
? buildImageNames(imageName, imageTagArray, platformTag)
133+
: [];
121134
if (imageName) {
122135
if (fullImageNameArray.length === 1) {
123136
if (!noCache && !cacheFrom.includes(fullImageNameArray[0])) {

github-action/dist/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,17 @@ function runMain() {
21712171
core.setFailed('mergeTag and platformTag cannot be used together - mergeTag is for the manifest merge job, platformTag is for per-platform build jobs');
21722172
return;
21732173
}
2174+
const buildXInstalled = yield (0, docker_1.isDockerBuildXInstalled)();
21742175
if (mergeTag) {
2176+
const imageName = emptyStringAsUndefined(core.getInput('imageName'));
2177+
if (!imageName) {
2178+
core.setFailed('imageName is required when using mergeTag');
2179+
return;
2180+
}
2181+
if (!buildXInstalled) {
2182+
core.setFailed('docker buildx is required for mergeTag - add a step to set up with docker/setup-buildx-action');
2183+
return;
2184+
}
21752185
const pushOption = emptyStringAsUndefined(core.getInput('push'));
21762186
if (pushOption !== 'always') {
21772187
core.setFailed("push must be set to 'always' when using mergeTag - the manifest merge job must push the resulting multi-arch image");
@@ -2181,7 +2191,6 @@ function runMain() {
21812191
core.saveState('mergeTag', mergeTag);
21822192
return;
21832193
}
2184-
const buildXInstalled = yield (0, docker_1.isDockerBuildXInstalled)();
21852194
if (!buildXInstalled) {
21862195
core.warning('docker buildx not available: add a step to set up with docker/setup-buildx-action - see https://github.com/devcontainers/ci/blob/main/docs/github-action.md');
21872196
return;
@@ -2230,7 +2239,9 @@ function runMain() {
22302239
const configFile = relativeConfigFile && path_1.default.resolve(checkoutPath, relativeConfigFile);
22312240
const resolvedImageTag = imageTag !== null && imageTag !== void 0 ? imageTag : 'latest';
22322241
const imageTagArray = resolvedImageTag.split(/\s*,\s*/);
2233-
const fullImageNameArray = (0, platform_1.buildImageNames)(imageName !== null && imageName !== void 0 ? imageName : '', imageTagArray, platformTag);
2242+
const fullImageNameArray = imageName
2243+
? (0, platform_1.buildImageNames)(imageName, imageTagArray, platformTag)
2244+
: [];
22342245
if (imageName) {
22352246
if (fullImageNameArray.length === 1) {
22362247
if (!noCache && !cacheFrom.includes(fullImageNameArray[0])) {

github-action/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github-action/src/main.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,20 @@ export async function runMain(): Promise<void> {
4545
return;
4646
}
4747

48+
const buildXInstalled = await isDockerBuildXInstalled();
49+
4850
if (mergeTag) {
51+
const imageName = emptyStringAsUndefined(core.getInput('imageName'));
52+
if (!imageName) {
53+
core.setFailed('imageName is required when using mergeTag');
54+
return;
55+
}
56+
if (!buildXInstalled) {
57+
core.setFailed(
58+
'docker buildx is required for mergeTag - add a step to set up with docker/setup-buildx-action',
59+
);
60+
return;
61+
}
4962
const pushOption = emptyStringAsUndefined(core.getInput('push'));
5063
if (pushOption !== 'always') {
5164
core.setFailed(
@@ -59,8 +72,6 @@ export async function runMain(): Promise<void> {
5972
core.saveState('mergeTag', mergeTag);
6073
return;
6174
}
62-
63-
const buildXInstalled = await isDockerBuildXInstalled();
6475
if (!buildXInstalled) {
6576
core.warning(
6677
'docker buildx not available: add a step to set up with docker/setup-buildx-action - see https://github.com/devcontainers/ci/blob/main/docs/github-action.md',
@@ -123,11 +134,9 @@ export async function runMain(): Promise<void> {
123134

124135
const resolvedImageTag = imageTag ?? 'latest';
125136
const imageTagArray = resolvedImageTag.split(/\s*,\s*/);
126-
const fullImageNameArray = buildImageNames(
127-
imageName ?? '',
128-
imageTagArray,
129-
platformTag,
130-
);
137+
const fullImageNameArray = imageName
138+
? buildImageNames(imageName, imageTagArray, platformTag)
139+
: [];
131140
if (imageName) {
132141
if (fullImageNameArray.length === 1) {
133142
if (!noCache && !cacheFrom.includes(fullImageNameArray[0])) {

0 commit comments

Comments
 (0)