mirror of
https://github.com/docker/build-push-action.git
synced 2025-03-31 09:16:35 +00:00
additional check for build summary support
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
94f8f8c2ee
commit
1e9b39bbeb
4 changed files with 51 additions and 24 deletions
21
.github/workflows/ci.yml
vendored
21
.github/workflows/ci.yml
vendored
|
@ -1345,7 +1345,7 @@ jobs:
|
|||
run: |
|
||||
docker image inspect localhost:5000/name/app:latest
|
||||
|
||||
disable-summary:
|
||||
summary-disabled:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
|
@ -1367,3 +1367,22 @@ jobs:
|
|||
file: ./test/Dockerfile
|
||||
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.11.2
|
||||
-
|
||||
name: Build
|
||||
uses: ./action
|
||||
with:
|
||||
file: ./test/Dockerfile
|
||||
|
|
|
@ -123,7 +123,7 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
|
|||
args.push('--annotation', annotation);
|
||||
});
|
||||
} else if (inputs.annotations.length > 0) {
|
||||
core.warning("Annotations are only supported by buildx >= 0.12.0; the input 'annotations' is ignored.");
|
||||
core.warning("Annotations are only supported by Buildx >= 0.12.0; the input 'annotations' is ignored.");
|
||||
}
|
||||
await Util.asyncForEach(inputs['build-args'], async buildArg => {
|
||||
args.push('--build-arg', buildArg);
|
||||
|
@ -133,7 +133,7 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
|
|||
args.push('--build-context', buildContext);
|
||||
});
|
||||
} else if (inputs['build-contexts'].length > 0) {
|
||||
core.warning("Build contexts are only supported by buildx >= 0.8.0; the input 'build-contexts' is ignored.");
|
||||
core.warning("Build contexts are only supported by Buildx >= 0.8.0; the input 'build-contexts' is ignored.");
|
||||
}
|
||||
await Util.asyncForEach(inputs['cache-from'], async cacheFrom => {
|
||||
args.push('--cache-from', cacheFrom);
|
||||
|
@ -172,7 +172,7 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
|
|||
if (await toolkit.buildx.versionSatisfies('>=0.10.0')) {
|
||||
args.push(...(await getAttestArgs(inputs, toolkit)));
|
||||
} else {
|
||||
core.warning("Attestations are only supported by buildx >= 0.10.0; the inputs 'attests', 'provenance' and 'sbom' are ignored.");
|
||||
core.warning("Attestations are only supported by Buildx >= 0.10.0; the inputs 'attests', 'provenance' and 'sbom' are ignored.");
|
||||
}
|
||||
await Util.asyncForEach(inputs.secrets, async secret => {
|
||||
try {
|
||||
|
|
36
src/main.ts
36
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);
|
||||
|
@ -125,13 +126,30 @@ 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.warning('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 (!ref) {
|
||||
core.warning('Build summary requires a build reference');
|
||||
} else if (builder && builder.driver === 'cloud') {
|
||||
core.warning('Build summary is not yet supported with Docker Build Cloud');
|
||||
} else if (!(await toolkit.buildx.versionSatisfies('>=0.13.0'))) {
|
||||
core.warning('Build summary requires Buildx >= 0.13.0');
|
||||
} else {
|
||||
core.info('Build summary supported!');
|
||||
stateHelper.setSummarySupported();
|
||||
}
|
||||
});
|
||||
if (err) {
|
||||
|
@ -140,16 +158,8 @@ actionsToolkit.run(
|
|||
},
|
||||
// post
|
||||
async () => {
|
||||
if (stateHelper.buildRef.length > 0) {
|
||||
if (stateHelper.isSummarySupported && stateHelper.buildRef.length > 0) {
|
||||
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 buildxHistory = new BuildxHistory();
|
||||
const exportRes = await buildxHistory.export({
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue