Skip to content

Commit 75ffdcc

Browse files
committed
call input to set method for evaluating build
Signed-off-by: CrazyMax <[email protected]>
1 parent 5e99dac commit 75ffdcc

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

.github/workflows/ci.yml

+30-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ jobs:
288288
-
289289
name: Check
290290
run: |
291-
echo "${{ toJson(steps.docker_build) }}"
292291
if [ "${{ steps.docker_build.outcome }}" != "failure" ] || [ "${{ steps.docker_build.conclusion }}" != "success" ]; then
293292
echo "::error::Should have failed"
294293
exit 1
@@ -324,7 +323,6 @@ jobs:
324323
-
325324
name: Check
326325
run: |
327-
echo "${{ toJson(steps.docker_build) }}"
328326
if [ "${{ steps.docker_build.outcome }}" != "failure" ] || [ "${{ steps.docker_build.conclusion }}" != "success" ]; then
329327
echo "::error::Should have failed"
330328
exit 1
@@ -1511,3 +1509,33 @@ jobs:
15111509
file: ./test/lint.Dockerfile
15121510
env:
15131511
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
1512+
1513+
call-check:
1514+
runs-on: ubuntu-latest
1515+
steps:
1516+
-
1517+
name: Checkout
1518+
uses: actions/checkout@v4
1519+
-
1520+
name: Set up Docker Buildx
1521+
uses: docker/setup-buildx-action@v3
1522+
with:
1523+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
1524+
driver-opts: |
1525+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
1526+
-
1527+
name: Build
1528+
id: docker_build
1529+
continue-on-error: true
1530+
uses: ./
1531+
with:
1532+
context: ./test
1533+
file: ./test/lint.Dockerfile
1534+
call: check
1535+
-
1536+
name: Check
1537+
run: |
1538+
if [ "${{ steps.docker_build.outcome }}" != "failure" ] || [ "${{ steps.docker_build.conclusion }}" != "success" ]; then
1539+
echo "::error::Should have failed"
1540+
exit 1
1541+
fi

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ The following inputs can be used as `step.with` keys:
220220
| `build-contexts` | List | List of additional [build contexts](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-context) (e.g., `name=path`) |
221221
| `cache-from` | List | List of [external cache sources](https://docs.docker.com/engine/reference/commandline/buildx_build/#cache-from) (e.g., `type=local,src=path/to/dir`) |
222222
| `cache-to` | List | List of [cache export destinations](https://docs.docker.com/engine/reference/commandline/buildx_build/#cache-to) (e.g., `type=local,dest=path/to/dir`) |
223+
| `call` | String | Set [method for evaluating build](https://docs.docker.com/reference/cli/docker/buildx/build/#call) (e.g., `check`) |
223224
| `cgroup-parent` | String | Optional [parent cgroup](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent) for the container used in the build |
224225
| `context` | String | Build's context is the set of files located in the specified [`PATH` or `URL`](https://docs.docker.com/engine/reference/commandline/build/) (default [Git context](#git-context)) |
225226
| `file` | String | Path to the Dockerfile. (default `{context}/Dockerfile`) |

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ inputs:
3434
cache-to:
3535
description: "List of cache export destinations for buildx (e.g., user/app:cache, type=local,dest=path/to/dir)"
3636
required: false
37+
call:
38+
description: "Set method for evaluating build (e.g., check)"
39+
required: false
3740
cgroup-parent:
3841
description: "Optional parent cgroup for the container used in the build"
3942
required: false

src/context.ts

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface Inputs {
1717
builder: string;
1818
'cache-from': string[];
1919
'cache-to': string[];
20+
call: string;
2021
'cgroup-parent': string;
2122
context: string;
2223
file: string;
@@ -53,6 +54,7 @@ export async function getInputs(): Promise<Inputs> {
5354
builder: core.getInput('builder'),
5455
'cache-from': Util.getInputList('cache-from', {ignoreComma: true}),
5556
'cache-to': Util.getInputList('cache-to', {ignoreComma: true}),
57+
call: core.getInput('call'),
5658
'cgroup-parent': core.getInput('cgroup-parent'),
5759
context: core.getInput('context') || Context.gitContext(),
5860
file: core.getInput('file'),
@@ -141,6 +143,12 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
141143
await Util.asyncForEach(inputs['cache-to'], async cacheTo => {
142144
args.push('--cache-to', cacheTo);
143145
});
146+
if (inputs.call) {
147+
if (!(await toolkit.buildx.versionSatisfies('>=0.15.0'))) {
148+
throw new Error(`Buildx >= 0.15.0 is required to use the call flag.`);
149+
}
150+
args.push('--call', inputs.call);
151+
}
144152
if (inputs['cgroup-parent']) {
145153
args.push('--cgroup-parent', inputs['cgroup-parent']);
146154
}

src/main.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ actionsToolkit.run(
104104
[key: string]: string;
105105
}
106106
}).then(res => {
107-
if (res.stderr.length > 0 && res.exitCode != 0) {
108-
err = Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
107+
if (res.exitCode != 0) {
108+
if (inputs.call && inputs.call === 'check' && res.stdout.length > 0) {
109+
// checks warnings are printed to stdout: https://github.com/docker/buildx/pull/2647
110+
// take the first line with the message summaryzing the warnings
111+
err = Error(res.stdout.split('\n')[0]?.trim());
112+
} else if (res.stderr.length > 0) {
113+
err = Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
114+
}
109115
}
110116
});
111117

@@ -161,6 +167,8 @@ actionsToolkit.run(
161167
await core.group(`Check build summary support`, async () => {
162168
if (!buildSummaryEnabled()) {
163169
core.info('Build summary disabled');
170+
} else if (inputs.call && inputs.call !== 'build') {
171+
core.info(`Build summary skipped for ${inputs.call} subrequest`);
164172
} else if (GitHub.isGHES) {
165173
core.info('Build summary is not yet supported on GHES');
166174
} else if (!(await toolkit.buildx.versionSatisfies('>=0.13.0'))) {

0 commit comments

Comments
 (0)