mirror of
https://github.com/docker/build-push-action.git
synced 2024-11-25 09:40:56 -05:00
move summary support check right after build
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
dcb0699155
commit
3dc0757c66
3 changed files with 54 additions and 23 deletions
23
.github/workflows/ci.yml
vendored
23
.github/workflows/ci.yml
vendored
|
@ -1345,7 +1345,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
docker image inspect localhost:5000/name/app:latest
|
docker image inspect localhost:5000/name/app:latest
|
||||||
|
|
||||||
disable-summary:
|
summary-disable:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
|
@ -1368,6 +1368,27 @@ jobs:
|
||||||
env:
|
env:
|
||||||
DOCKER_BUILD_NO_SUMMARY: true
|
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:
|
export-retention-days:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
|
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 {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
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 {ConfigFile} from '@docker/actions-toolkit/lib/types/docker/docker';
|
||||||
|
|
||||||
import * as context from './context';
|
import * as context from './context';
|
||||||
|
@ -80,10 +81,10 @@ actionsToolkit.run(
|
||||||
await toolkit.buildx.printVersion();
|
await toolkit.buildx.printVersion();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let builder: BuilderInfo;
|
||||||
await core.group(`Builder info`, async () => {
|
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));
|
core.info(JSON.stringify(builder, null, 2));
|
||||||
stateHelper.setBuilder(builder);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const args: string[] = await context.getArgs(inputs, toolkit);
|
const args: string[] = await context.getArgs(inputs, toolkit);
|
||||||
|
@ -105,7 +106,6 @@ actionsToolkit.run(
|
||||||
const imageID = toolkit.buildxBuild.resolveImageID();
|
const imageID = toolkit.buildxBuild.resolveImageID();
|
||||||
const metadata = toolkit.buildxBuild.resolveMetadata();
|
const metadata = toolkit.buildxBuild.resolveMetadata();
|
||||||
const digest = toolkit.buildxBuild.resolveDigest();
|
const digest = toolkit.buildxBuild.resolveDigest();
|
||||||
|
|
||||||
if (imageID) {
|
if (imageID) {
|
||||||
await core.group(`ImageID`, async () => {
|
await core.group(`ImageID`, async () => {
|
||||||
core.info(imageID);
|
core.info(imageID);
|
||||||
|
@ -125,36 +125,48 @@ actionsToolkit.run(
|
||||||
core.setOutput('metadata', metadatadt);
|
core.setOutput('metadata', metadatadt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ref: string;
|
||||||
await core.group(`Reference`, async () => {
|
await core.group(`Reference`, async () => {
|
||||||
const ref = await buildRef(toolkit, startedTime, inputs.builder);
|
ref = await buildRef(toolkit, startedTime, inputs.builder);
|
||||||
if (ref) {
|
if (ref) {
|
||||||
core.info(ref);
|
core.info(ref);
|
||||||
stateHelper.setBuildRef(ref);
|
stateHelper.setBuildRef(ref);
|
||||||
} else {
|
} 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) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// post
|
// post
|
||||||
async () => {
|
async () => {
|
||||||
if (stateHelper.buildRef.length > 0) {
|
if (stateHelper.isSummarySupported) {
|
||||||
await core.group(`Generating build summary`, async () => {
|
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 {
|
try {
|
||||||
const exportRetentionDays = buildExportRetentionDays();
|
const exportRetentionDays = buildExportRetentionDays();
|
||||||
const buildxHistory = new BuildxHistory();
|
const buildxHistory = new BuildxHistory();
|
||||||
const exportRes = await buildxHistory.export({
|
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)})`);
|
core.info(`Build record exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
|
||||||
const uploadRes = await GitHub.uploadArtifact({
|
const uploadRes = await GitHub.uploadArtifact({
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder';
|
|
||||||
|
|
||||||
import {Inputs, sanitizeInputs} from './context';
|
import {Inputs, sanitizeInputs} from './context';
|
||||||
|
|
||||||
export const tmpDir = process.env['STATE_tmpDir'] || '';
|
export const tmpDir = process.env['STATE_tmpDir'] || '';
|
||||||
export const inputs = process.env['STATE_inputs'] ? JSON.parse(process.env['STATE_inputs']) : undefined;
|
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 buildRef = process.env['STATE_buildRef'] || '';
|
||||||
|
export const isSummarySupported = !!process.env['STATE_isSummarySupported'];
|
||||||
|
|
||||||
export function setTmpDir(tmpDir: string) {
|
export function setTmpDir(tmpDir: string) {
|
||||||
core.saveState('tmpDir', tmpDir);
|
core.saveState('tmpDir', tmpDir);
|
||||||
|
@ -17,10 +15,10 @@ export function setInputs(inputs: Inputs) {
|
||||||
core.saveState('inputs', JSON.stringify(sanitizeInputs(inputs)));
|
core.saveState('inputs', JSON.stringify(sanitizeInputs(inputs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setBuilder(builder: BuilderInfo) {
|
|
||||||
core.saveState('builder', JSON.stringify(builder));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setBuildRef(buildRef: string) {
|
export function setBuildRef(buildRef: string) {
|
||||||
core.saveState('buildRef', buildRef);
|
core.saveState('buildRef', buildRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setSummarySupported() {
|
||||||
|
core.saveState('isSummarySupported', 'true');
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue