Skip to content

Commit

Permalink
Merge pull request #225 from crazy-max/check-summary-support
Browse files Browse the repository at this point in the history
move summary support check right after build
  • Loading branch information
crazy-max authored Jul 2, 2024
2 parents 5060c11 + 40a4ea9 commit 2b6f83c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 23 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ jobs:
run: |
docker image inspect localhost:5000/name/app:latest
disable-summary:
summary-disable:
runs-on: ubuntu-latest
steps:
-
Expand All @@ -546,6 +546,27 @@ jobs:
env:
DOCKER_BUILD_NO_SUMMARY: true

summary-not-supported:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
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: ./
with:
files: |
./test/config.hcl
targets: app

export-retention-days:
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

41 changes: 27 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
import {Util} from '@docker/actions-toolkit/lib/util';

import {BakeDefinition} from '@docker/actions-toolkit/lib/types/buildx/bake';
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';
Expand Down Expand Up @@ -83,10 +84,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);
});

let definition: BakeDefinition | undefined;
Expand Down Expand Up @@ -148,33 +149,45 @@ actionsToolkit.run(
core.setOutput('metadata', metadatadt);
});
}

let refs: Array<string> = [];
await core.group(`Build references`, async () => {
const refs = await buildRefs(toolkit, startedTime, inputs.builder);
if (refs) {
refs = await buildRefs(toolkit, startedTime, inputs.builder);
if (refs.length > 0) {
for (const ref of refs) {
core.info(ref);
}
stateHelper.setBuildRefs(refs);
} else {
core.warning('No build refs found');
core.info('No build references 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 (refs.length == 0) {
core.warning('Build summary requires at least one build reference');
} else {
core.info('Build summary supported!');
stateHelper.setSummarySupported();
}
});

if (err) {
throw err;
}
},
// post
async () => {
if (stateHelper.buildRefs.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();
Expand Down
11 changes: 5 additions & 6 deletions src/state-helper.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as core from '@actions/core';

import {BakeDefinition} from '@docker/actions-toolkit/lib/types/buildx/bake';
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 bakeDefinition = process.env['STATE_bakeDefinition'] ? <BakeDefinition>JSON.parse(process.env['STATE_bakeDefinition']) : undefined;
export const buildRefs = process.env['STATE_buildRefs'] ? process.env['STATE_buildRefs'].split(',') : [];
export const isSummarySupported = !!process.env['STATE_isSummarySupported'];

export function setTmpDir(tmpDir: string) {
core.saveState('tmpDir', tmpDir);
Expand All @@ -19,14 +18,14 @@ 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 setBakeDefinition(bakeDefinition: BakeDefinition) {
core.saveState('bakeDefinition', JSON.stringify(bakeDefinition));
}

export function setBuildRefs(buildRefs: Array<string>) {
core.saveState('buildRefs', buildRefs.join(','));
}

export function setSummarySupported() {
core.saveState('isSummarySupported', 'true');
}

0 comments on commit 2b6f83c

Please sign in to comment.