Skip to content

Commit 3ebc4bc

Browse files
committed
fix build errors
1 parent b4a20f7 commit 3ebc4bc

File tree

1 file changed

+57
-18
lines changed

1 file changed

+57
-18
lines changed

github-action/src/main.ts

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,29 @@ export async function runMain(): Promise<void> {
142142
if (buildResult.outcome === 'success') {
143143
// Create a digests object to track digests for each platform
144144
const digestsObj: Record<string, string> = {};
145-
145+
146146
if (platform) {
147147
// Extract the image digest from the build output
148-
if (buildResult.imageDigest) {
149-
core.info(`Image digest for ${platform}: ${buildResult.imageDigest}`);
150-
digestsObj[platform] = buildResult.imageDigest;
148+
if (buildResult.imageDigests) {
149+
core.info(
150+
`Image digest for ${platform}: ${buildResult.imageDigests}`,
151+
);
152+
digestsObj[platform] = buildResult.imageDigests[platform];
151153
} else {
152154
// If buildResult doesn't have imageDigest, try to get it from the built image
153155
if (imageName) {
154-
const inspectCmd = await exec('docker', ['buildx', 'imagetools', 'inspect', `${imageName}:${imageTagArray[0]}`, '--format', '{{json .}}'], { silent: true });
156+
const inspectCmd = await exec(
157+
'docker',
158+
[
159+
'buildx',
160+
'imagetools',
161+
'inspect',
162+
`${imageName}:${imageTagArray[0]}`,
163+
'--format',
164+
'{{json .}}',
165+
],
166+
{silent: true},
167+
);
155168
if (inspectCmd.exitCode === 0) {
156169
try {
157170
const imageInfo = JSON.parse(inspectCmd.stdout);
@@ -170,14 +183,23 @@ export async function runMain(): Promise<void> {
170183
}
171184
} else if (imageName) {
172185
// For non-platform specific builds, still try to get the digest
173-
const inspectCmd = await exec('docker', ['inspect', `${imageName}:${imageTagArray[0]}`, '--format', '{{.Id}}'], { silent: true });
186+
const inspectCmd = await exec(
187+
'docker',
188+
[
189+
'inspect',
190+
`${imageName}:${imageTagArray[0]}`,
191+
'--format',
192+
'{{.Id}}',
193+
],
194+
{silent: true},
195+
);
174196
if (inspectCmd.exitCode === 0) {
175197
const digest = inspectCmd.stdout.trim();
176198
core.info(`Image digest: ${digest}`);
177199
digestsObj['default'] = digest;
178200
}
179201
}
180-
202+
181203
// Output the digests as a JSON string
182204
if (Object.keys(digestsObj).length > 0) {
183205
const digestsJson = JSON.stringify(digestsObj);
@@ -315,26 +337,39 @@ export async function runPost(): Promise<void> {
315337
// Create a digests object to track digests for each platform
316338
const digestsObj: Record<string, string> = {};
317339
const platforms = platform.split(/\s*,\s*/);
318-
340+
319341
for (const tag of imageTagArray) {
320342
core.info(`Copying multiplatform image '${imageName}:${tag}'...`);
321343
const imageSource = `oci-archive:/tmp/output.tar:${tag}`;
322344
const imageDest = `docker://${imageName}:${tag}`;
323345

324346
await copyImage(true, imageSource, imageDest);
325-
347+
326348
// After pushing, get and set digest
327-
const inspectCmd = await exec('docker', ['buildx', 'imagetools', 'inspect', `${imageName}:${tag}`, '--format', '{{json .}}'], { silent: true });
349+
const inspectCmd = await exec(
350+
'docker',
351+
[
352+
'buildx',
353+
'imagetools',
354+
'inspect',
355+
`${imageName}:${tag}`,
356+
'--format',
357+
'{{json .}}',
358+
],
359+
{silent: true},
360+
);
328361
if (inspectCmd.exitCode === 0) {
329362
try {
330363
const imageInfo = JSON.parse(inspectCmd.stdout);
331-
364+
332365
// If it's a manifest list, extract digests for each platform
333366
if (imageInfo.manifests) {
334367
for (const manifest of imageInfo.manifests) {
335368
if (manifest.platform && manifest.digest) {
336-
const platformStr = `${manifest.platform.os}/${manifest.platform.architecture}${manifest.platform.variant ? '/' + manifest.platform.variant : ''}`;
337-
core.info(`Image digest for ${imageName}:${tag} (${platformStr}): ${manifest.digest}`);
369+
const platformStr = `${manifest.platform.os}/${manifest.platform.architecture}${manifest.platform.variant ? `/${manifest.platform.variant}` : ''}`;
370+
core.info(
371+
`Image digest for ${imageName}:${tag} (${platformStr}): ${manifest.digest}`,
372+
);
338373
digestsObj[platformStr] = manifest.digest;
339374
}
340375
}
@@ -349,7 +384,7 @@ export async function runPost(): Promise<void> {
349384
}
350385
}
351386
}
352-
387+
353388
// Output the digests as a JSON string
354389
if (Object.keys(digestsObj).length > 0) {
355390
const digestsJson = JSON.stringify(digestsObj);
@@ -359,13 +394,17 @@ export async function runPost(): Promise<void> {
359394
} else {
360395
// Create a digests object for non-platform specific builds
361396
const digestsObj: Record<string, string> = {};
362-
397+
363398
for (const tag of imageTagArray) {
364399
core.info(`Pushing image '${imageName}:${tag}'...`);
365400
await pushImage(imageName, tag);
366-
401+
367402
// After pushing, get and set digest
368-
const inspectCmd = await exec('docker', ['inspect', `${imageName}:${tag}`, '--format', '{{.Id}}'], { silent: true });
403+
const inspectCmd = await exec(
404+
'docker',
405+
['inspect', `${imageName}:${tag}`, '--format', '{{.Id}}'],
406+
{silent: true},
407+
);
369408
if (inspectCmd.exitCode === 0) {
370409
const digest = inspectCmd.stdout.trim();
371410
core.info(`Image digest for ${imageName}:${tag}: ${digest}`);
@@ -374,7 +413,7 @@ export async function runPost(): Promise<void> {
374413
core.warning(`Failed to get image digest: ${inspectCmd.stderr}`);
375414
}
376415
}
377-
416+
378417
// Output the digests as a JSON string
379418
if (Object.keys(digestsObj).length > 0) {
380419
const digestsJson = JSON.stringify(digestsObj);

0 commit comments

Comments
 (0)