mirror of
https://github.com/docker/build-push-action.git
synced 2024-11-15 11:43:51 +08:00
Merge pull request #1160 from crazy-max/check-summary-support
move summary support check right after build
This commit is contained in:
commit
709dde20a7
23
.github/workflows/ci.yml
vendored
23
.github/workflows/ci.yml
vendored
@ -1345,7 +1345,7 @@ jobs:
|
||||
run: |
|
||||
docker image inspect localhost:5000/name/app:latest
|
||||
|
||||
disable-summary:
|
||||
summary-disable:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
@ -1368,6 +1368,27 @@ jobs:
|
||||
env:
|
||||
DOCKER_BUILD_NO_SUMMARY: true
|
||||
|
||||
summary-not-supported:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: action
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: v0.12.1
|
||||
driver-opts: |
|
||||
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
|
||||
-
|
||||
name: Build
|
||||
uses: ./action
|
||||
with:
|
||||
file: ./test/Dockerfile
|
||||
|
||||
export-retention-days:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
|
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
42
src/main.ts
42
src/main.ts
@ -13,6 +13,7 @@ import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||
|
||||
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder';
|
||||
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker/docker';
|
||||
|
||||
import * as context from './context';
|
||||
@ -80,10 +81,10 @@ actionsToolkit.run(
|
||||
await toolkit.buildx.printVersion();
|
||||
});
|
||||
|
||||
let builder: BuilderInfo;
|
||||
await core.group(`Builder info`, async () => {
|
||||
const builder = await toolkit.builder.inspect(inputs.builder);
|
||||
builder = await toolkit.builder.inspect(inputs.builder);
|
||||
core.info(JSON.stringify(builder, null, 2));
|
||||
stateHelper.setBuilder(builder);
|
||||
});
|
||||
|
||||
const args: string[] = await context.getArgs(inputs, toolkit);
|
||||
@ -105,7 +106,6 @@ actionsToolkit.run(
|
||||
const imageID = toolkit.buildxBuild.resolveImageID();
|
||||
const metadata = toolkit.buildxBuild.resolveMetadata();
|
||||
const digest = toolkit.buildxBuild.resolveDigest();
|
||||
|
||||
if (imageID) {
|
||||
await core.group(`ImageID`, async () => {
|
||||
core.info(imageID);
|
||||
@ -125,36 +125,48 @@ actionsToolkit.run(
|
||||
core.setOutput('metadata', metadatadt);
|
||||
});
|
||||
}
|
||||
|
||||
let ref: string;
|
||||
await core.group(`Reference`, async () => {
|
||||
const ref = await buildRef(toolkit, startedTime, inputs.builder);
|
||||
ref = await buildRef(toolkit, startedTime, inputs.builder);
|
||||
if (ref) {
|
||||
core.info(ref);
|
||||
stateHelper.setBuildRef(ref);
|
||||
} else {
|
||||
core.warning('No build ref found');
|
||||
core.info('No build reference found');
|
||||
}
|
||||
});
|
||||
|
||||
await core.group(`Check build summary support`, async () => {
|
||||
if (process.env.DOCKER_BUILD_NO_SUMMARY && Util.parseBool(process.env.DOCKER_BUILD_NO_SUMMARY)) {
|
||||
core.info('Build summary disabled');
|
||||
} else if (GitHub.isGHES) {
|
||||
core.warning('Build summary is not yet supported on GHES');
|
||||
} else if (!(await toolkit.buildx.versionSatisfies('>=0.13.0'))) {
|
||||
core.warning('Build summary requires Buildx >= 0.13.0');
|
||||
} else if (builder && builder.driver === 'cloud') {
|
||||
core.warning('Build summary is not yet supported with Docker Build Cloud');
|
||||
} else if (!ref) {
|
||||
core.warning('Build summary requires a build reference');
|
||||
} else {
|
||||
core.info('Build summary supported!');
|
||||
stateHelper.setSummarySupported();
|
||||
}
|
||||
});
|
||||
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
// post
|
||||
async () => {
|
||||
if (stateHelper.buildRef.length > 0) {
|
||||
if (stateHelper.isSummarySupported) {
|
||||
await core.group(`Generating build summary`, async () => {
|
||||
if (process.env.DOCKER_BUILD_NO_SUMMARY && Util.parseBool(process.env.DOCKER_BUILD_NO_SUMMARY)) {
|
||||
core.info('Summary disabled');
|
||||
return;
|
||||
}
|
||||
if (stateHelper.builder && stateHelper.builder.driver === 'cloud') {
|
||||
core.info('Summary is not yet supported with Docker Build Cloud');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const exportRetentionDays = buildExportRetentionDays();
|
||||
const buildxHistory = new BuildxHistory();
|
||||
const exportRes = await buildxHistory.export({
|
||||
refs: [stateHelper.buildRef]
|
||||
refs: stateHelper.buildRef ? [stateHelper.buildRef] : []
|
||||
});
|
||||
core.info(`Build record exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
|
||||
const uploadRes = await GitHub.uploadArtifact({
|
||||
|
@ -1,13 +1,11 @@
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder';
|
||||
|
||||
import {Inputs, sanitizeInputs} from './context';
|
||||
|
||||
export const tmpDir = process.env['STATE_tmpDir'] || '';
|
||||
export const inputs = process.env['STATE_inputs'] ? JSON.parse(process.env['STATE_inputs']) : undefined;
|
||||
export const builder = process.env['STATE_builder'] ? <BuilderInfo>JSON.parse(process.env['STATE_builder']) : undefined;
|
||||
export const buildRef = process.env['STATE_buildRef'] || '';
|
||||
export const isSummarySupported = !!process.env['STATE_isSummarySupported'];
|
||||
|
||||
export function setTmpDir(tmpDir: string) {
|
||||
core.saveState('tmpDir', tmpDir);
|
||||
@ -17,10 +15,10 @@ export function setInputs(inputs: Inputs) {
|
||||
core.saveState('inputs', JSON.stringify(sanitizeInputs(inputs)));
|
||||
}
|
||||
|
||||
export function setBuilder(builder: BuilderInfo) {
|
||||
core.saveState('builder', JSON.stringify(builder));
|
||||
}
|
||||
|
||||
export function setBuildRef(buildRef: string) {
|
||||
core.saveState('buildRef', buildRef);
|
||||
}
|
||||
|
||||
export function setSummarySupported() {
|
||||
core.saveState('isSummarySupported', 'true');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user