mirror of
https://github.com/docker/build-push-action.git
synced 2024-12-26 07:53:19 +08:00
Merge pull request #1265 from crazy-max/call-check
call input to set method for evaluating build
This commit is contained in:
commit
0259cb088b
32
.github/workflows/ci.yml
vendored
32
.github/workflows/ci.yml
vendored
@ -288,7 +288,6 @@ jobs:
|
||||
-
|
||||
name: Check
|
||||
run: |
|
||||
echo "${{ toJson(steps.docker_build) }}"
|
||||
if [ "${{ steps.docker_build.outcome }}" != "failure" ] || [ "${{ steps.docker_build.conclusion }}" != "success" ]; then
|
||||
echo "::error::Should have failed"
|
||||
exit 1
|
||||
@ -324,7 +323,6 @@ jobs:
|
||||
-
|
||||
name: Check
|
||||
run: |
|
||||
echo "${{ toJson(steps.docker_build) }}"
|
||||
if [ "${{ steps.docker_build.outcome }}" != "failure" ] || [ "${{ steps.docker_build.conclusion }}" != "success" ]; then
|
||||
echo "::error::Should have failed"
|
||||
exit 1
|
||||
@ -1511,3 +1509,33 @@ jobs:
|
||||
file: ./test/lint.Dockerfile
|
||||
env:
|
||||
DOCKER_BUILD_CHECKS_ANNOTATIONS: false
|
||||
|
||||
call-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
|
||||
driver-opts: |
|
||||
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
|
||||
-
|
||||
name: Build
|
||||
id: docker_build
|
||||
continue-on-error: true
|
||||
uses: ./
|
||||
with:
|
||||
context: ./test
|
||||
file: ./test/lint.Dockerfile
|
||||
call: check
|
||||
-
|
||||
name: Check
|
||||
run: |
|
||||
if [ "${{ steps.docker_build.outcome }}" != "failure" ] || [ "${{ steps.docker_build.conclusion }}" != "success" ]; then
|
||||
echo "::error::Should have failed"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -220,6 +220,7 @@ The following inputs can be used as `step.with` keys:
|
||||
| `build-contexts` | List | List of additional [build contexts](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-context) (e.g., `name=path`) |
|
||||
| `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`) |
|
||||
| `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`) |
|
||||
| `call` | String | Set [method for evaluating build](https://docs.docker.com/reference/cli/docker/buildx/build/#call) (e.g., `check`) |
|
||||
| `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 |
|
||||
| `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)) |
|
||||
| `file` | String | Path to the Dockerfile. (default `{context}/Dockerfile`) |
|
||||
|
@ -34,6 +34,9 @@ inputs:
|
||||
cache-to:
|
||||
description: "List of cache export destinations for buildx (e.g., user/app:cache, type=local,dest=path/to/dir)"
|
||||
required: false
|
||||
call:
|
||||
description: "Set method for evaluating build (e.g., check)"
|
||||
required: false
|
||||
cgroup-parent:
|
||||
description: "Optional parent cgroup for the container used in the build"
|
||||
required: false
|
||||
|
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
@ -17,6 +17,7 @@ export interface Inputs {
|
||||
builder: string;
|
||||
'cache-from': string[];
|
||||
'cache-to': string[];
|
||||
call: string;
|
||||
'cgroup-parent': string;
|
||||
context: string;
|
||||
file: string;
|
||||
@ -53,6 +54,7 @@ export async function getInputs(): Promise<Inputs> {
|
||||
builder: core.getInput('builder'),
|
||||
'cache-from': Util.getInputList('cache-from', {ignoreComma: true}),
|
||||
'cache-to': Util.getInputList('cache-to', {ignoreComma: true}),
|
||||
call: core.getInput('call'),
|
||||
'cgroup-parent': core.getInput('cgroup-parent'),
|
||||
context: core.getInput('context') || Context.gitContext(),
|
||||
file: core.getInput('file'),
|
||||
@ -141,6 +143,12 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
|
||||
await Util.asyncForEach(inputs['cache-to'], async cacheTo => {
|
||||
args.push('--cache-to', cacheTo);
|
||||
});
|
||||
if (inputs.call) {
|
||||
if (!(await toolkit.buildx.versionSatisfies('>=0.15.0'))) {
|
||||
throw new Error(`Buildx >= 0.15.0 is required to use the call flag.`);
|
||||
}
|
||||
args.push('--call', inputs.call);
|
||||
}
|
||||
if (inputs['cgroup-parent']) {
|
||||
args.push('--cgroup-parent', inputs['cgroup-parent']);
|
||||
}
|
||||
|
10
src/main.ts
10
src/main.ts
@ -104,9 +104,15 @@ actionsToolkit.run(
|
||||
[key: string]: string;
|
||||
}
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
if (res.exitCode != 0) {
|
||||
if (inputs.call && inputs.call === 'check' && res.stdout.length > 0) {
|
||||
// checks warnings are printed to stdout: https://github.com/docker/buildx/pull/2647
|
||||
// take the first line with the message summaryzing the warnings
|
||||
err = Error(res.stdout.split('\n')[0]?.trim());
|
||||
} else if (res.stderr.length > 0) {
|
||||
err = Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const imageID = toolkit.buildxBuild.resolveImageID();
|
||||
@ -161,6 +167,8 @@ actionsToolkit.run(
|
||||
await core.group(`Check build summary support`, async () => {
|
||||
if (!buildSummaryEnabled()) {
|
||||
core.info('Build summary disabled');
|
||||
} else if (inputs.call && inputs.call !== 'build') {
|
||||
core.info(`Build summary skipped for ${inputs.call} subrequest`);
|
||||
} else if (GitHub.isGHES) {
|
||||
core.info('Build summary is not yet supported on GHES');
|
||||
} else if (!(await toolkit.buildx.versionSatisfies('>=0.13.0'))) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user