Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ jobs:
exit 1
fi

error-source:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v6
-
name: Build
id: bake
continue-on-error: true
uses: ./
with:
source: ./does-not-exist
-
name: Check
run: |
if [ "${{ steps.bake.outcome }}" != "failure" ] || [ "${{ steps.bake.conclusion }}" != "success" ]; then
echo "::error::Should have failed"
exit 1
fi

standalone:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -190,8 +211,7 @@ jobs:
name: Build
uses: ./
with:
workdir: ./test/go
source: .
source: ./test/go
targets: binary
provenance: ${{ matrix.attrs }}
set: |
Expand Down Expand Up @@ -232,8 +252,7 @@ jobs:
name: Build
uses: ./
with:
workdir: ./test/go
source: .
source: ./test/go
targets: ${{ matrix.target }}
sbom: true
set: |
Expand Down Expand Up @@ -279,8 +298,7 @@ jobs:
name: Build
uses: ./
with:
workdir: ./test/go
source: .
source: ./test/go
set: |
*.platform=linux/amd64
*.output=type=image,"name=localhost:5000/name/app:v1.0.0,localhost:5000/name/app:latest",push=true
Expand Down Expand Up @@ -309,8 +327,7 @@ jobs:
name: Build and push
uses: ./
with:
workdir: ./test/group
source: .
source: ./test/group
push: true
set: |
t1.tags=localhost:5000/name/app:t1
Expand Down Expand Up @@ -472,8 +489,7 @@ jobs:
name: Build and push
uses: ./
with:
workdir: ./test/go
source: .
source: ./test/go
set: |
*.output=type=image,name=localhost:5000/name/app:latest,push=true
*.output=type=docker,name=app:local
Expand Down Expand Up @@ -516,8 +532,7 @@ jobs:
name: Build and push
uses: ./
with:
workdir: ./test/go
source: .
source: ./test/go
targets: image
load: true
push: true
Expand Down Expand Up @@ -704,8 +719,7 @@ jobs:
name: Build
uses: ./
with:
workdir: ./test
source: .
source: ./test
files: |
./lint.hcl

Expand All @@ -726,8 +740,7 @@ jobs:
name: Build
uses: ./
with:
workdir: ./test
source: .
source: ./test
files: |
./lint.hcl
env:
Expand Down Expand Up @@ -798,8 +811,7 @@ jobs:
continue-on-error: true
uses: ./
with:
workdir: ./test
source: .
source: ./test
files: |
./lint.hcl
call: check
Expand Down Expand Up @@ -831,8 +843,7 @@ jobs:
continue-on-error: true
uses: ./
with:
workdir: ./test
source: .
source: ./test
files: |
./lint.hcl
call: check
Expand Down Expand Up @@ -885,5 +896,4 @@ jobs:
name: Build and push
uses: ./
with:
workdir: ./test/attest
source: .
source: ./test/attest
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ The following inputs can be used as `step.with` keys
| Name | Type | Description |
|----------------|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `builder` | String | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) |
| `workdir` | String | Working directory of execution |
| `source` | String | Context to build from. Can be either local (`.`) or a [remote bake definition](https://docs.docker.com/build/bake/remote-definition/) |
| `allow` | List/CSV | Allow build to access specified resources (e.g., `network.host`) |
| `call` | String | Set method for evaluating build (e.g., check) |
| `files` | List/CSV | List of [bake definition files](https://docs.docker.com/build/customize/bake/file-definition/) |
Expand All @@ -212,6 +210,7 @@ The following inputs can be used as `step.with` keys
| `push` | Bool | Push is a shorthand for `--set=*.output=type=registry` (default `false`) |
| `sbom` | Bool/String | [SBOM](https://docs.docker.com/build/attestations/sbom/) is a shorthand for `--set=*.attest=type=sbom` |
| `set` | List | List of [targets values to override](https://docs.docker.com/engine/reference/commandline/buildx_bake/#set) (e.g., `targetpattern.key=value`) |
| `source` | String | Context to build from. Can be either local to specify the working directory or a [remote bake definition](https://docs.docker.com/build/bake/remote-definition/) |
| `targets` | List/CSV | List of bake targets (`default` target used if empty) |
| `github-token` | String | API token used to authenticate to a Git repository for [remote definitions](https://docs.docker.com/build/bake/remote-definition/) (default `${{ github.token }}`) |

Expand Down
4 changes: 2 additions & 2 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,11 @@ describe('getArgs', () => {
provenance: inp.provenance,
push: inp.push,
sbom: inp.sbom,
source: inp.source,
source: inp.source.remoteRef,
targets: inp.targets
},
{
cwd: inp.workdir
cwd: inp.source.workdir,
}
);
const res = await context.getArgs(inp, definition, toolkit);
Expand Down
10 changes: 3 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ inputs:
builder:
description: "Builder instance"
required: false
workdir:
description: "Working directory of bake execution"
required: false
default: '.'
source:
description: "Context to build from. Can be either local or a remote bake definition"
required: false
allow:
description: "Allow build to access specified resources (e.g., network.host)"
required: false
Expand Down Expand Up @@ -51,6 +44,9 @@ inputs:
set:
description: "List of targets values to override (eg. targetpattern.key=value)"
required: false
source:
description: "Context to build from. Can be either local to specify the working directory or a remote bake definition"
required: false
targets:
description: "List of bake targets"
required: false
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.

39 changes: 26 additions & 13 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'fs';
import * as core from '@actions/core';
import * as handlebars from 'handlebars';

Expand All @@ -10,10 +11,13 @@ import {Util} from '@docker/actions-toolkit/lib/util';

import {BakeDefinition} from '@docker/actions-toolkit/lib/types/buildx/bake';

export interface BakeContext {
remoteRef?: string;
workdir?: string;
}

export interface Inputs {
builder: string;
workdir: string;
source: string;
allow: string[];
call: string;
files: string[];
Expand All @@ -24,15 +28,14 @@ export interface Inputs {
push: boolean;
sbom: string;
set: string[];
source: BakeContext;
targets: string[];
'github-token': string;
}

export async function getInputs(): Promise<Inputs> {
return {
builder: core.getInput('builder'),
workdir: core.getInput('workdir') || '.',
source: getSourceInput('source'),
allow: Util.getInputList('allow'),
call: core.getInput('call'),
files: Util.getInputList('files'),
Expand All @@ -43,6 +46,7 @@ export async function getInputs(): Promise<Inputs> {
push: core.getBooleanInput('push'),
sbom: core.getInput('sbom'),
set: Util.getInputList('set', {ignoreComma: true, quote: false}),
source: getBakeContext(core.getInput('source')),
targets: Util.getInputList('targets'),
'github-token': core.getInput('github-token')
};
Expand All @@ -59,8 +63,8 @@ export async function getArgs(inputs: Inputs, definition: BakeDefinition, toolki

async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit: Toolkit): Promise<Array<string>> {
const args: Array<string> = ['bake'];
if (inputs.source) {
args.push(inputs.source);
if (inputs.source.remoteRef) {
args.push(inputs.source.remoteRef);
}
if (await toolkit.buildx.versionSatisfies('>=0.17.0')) {
if (await toolkit.buildx.versionSatisfies('>=0.18.0')) {
Expand Down Expand Up @@ -135,17 +139,26 @@ async function getCommonArgs(inputs: Inputs): Promise<Array<string>> {
return args;
}

function getSourceInput(name: string): string {
let source = handlebars.compile(core.getInput(name))({
function getBakeContext(sourceInput: string): BakeContext {
let bakeContext = handlebars.compile(sourceInput)({
defaultContext: Context.gitContext()
});
if (!source) {
source = Context.gitContext();
if (!bakeContext) {
bakeContext = Context.gitContext();
}
if (Util.isValidRef(bakeContext)) {
return {
remoteRef: bakeContext
};
}
if (source === '.') {
source = '';
try {
fs.statSync(sourceInput).isDirectory();
} catch {
throw new Error(`Invalid source: ${sourceInput} does not exist or is not a directory.`);
}
return source;
return {
workdir: bakeContext
};
}

function noDefaultAttestations(): boolean {
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ actionsToolkit.run(
provenance: inputs.provenance,
push: inputs.push,
sbom: inputs.sbom,
source: inputs.source,
source: inputs.source.remoteRef,
targets: inputs.targets,
githubToken: gitAuthToken
},
{
cwd: inputs.workdir
cwd: inputs.source.workdir
}
);
});
Expand All @@ -130,7 +130,7 @@ actionsToolkit.run(

await core.group(`Bake definition`, async () => {
await Exec.getExecOutput(buildCmd.command, [...buildCmd.args, '--print'], {
cwd: inputs.workdir,
cwd: inputs.source.workdir,
env: buildEnv,
ignoreReturnCode: true
}).then(res => {
Expand All @@ -142,7 +142,7 @@ actionsToolkit.run(

let err: Error | undefined;
await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
cwd: inputs.workdir,
cwd: inputs.source.workdir,
env: buildEnv,
ignoreReturnCode: true
}).then(res => {
Expand Down
5 changes: 4 additions & 1 deletion src/state-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ export function setSummarySupported() {

export function setSummaryInputs(inputs: Inputs) {
const res = {};
if (inputs.source.remoteRef || inputs.source.workdir) {
res['source'] = inputs.source.remoteRef || inputs.source.workdir;
}
for (const key of Object.keys(inputs)) {
if (key === 'github-token') {
if (key === 'source' || key === 'github-token') {
continue;
}
const value: string | string[] | boolean = inputs[key];
Expand Down
Loading