mirror of
https://github.com/docker/bake-action.git
synced 2025-07-14 12:41:53 +02:00
81 lines
2.4 KiB
YAML
81 lines
2.4 KiB
YAML
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions
|
|
name: 'List Bake targets'
|
|
description: 'Generate a list of Bake targets to help distributing builds in your workflow'
|
|
|
|
inputs:
|
|
workdir:
|
|
description: Working directory
|
|
default: '.'
|
|
required: false
|
|
files:
|
|
description: Comma separated list of Bake files
|
|
required: false
|
|
target:
|
|
description: Bake target
|
|
required: false
|
|
|
|
outputs:
|
|
targets:
|
|
description: List of targets
|
|
value: ${{ steps.generate.outputs.targets }}
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
-
|
|
name: Install npm dependencies
|
|
uses: actions/github-script@v7
|
|
env:
|
|
INPUT_ACTIONS-TOOLKIT-VERSION: '0.62.1'
|
|
with:
|
|
script: |
|
|
const version = core.getInput('actions-toolkit-version') || 'latest';
|
|
const dep = `@docker/actions-toolkit@${version}`;
|
|
await core.group(`Installing ${dep}`, async () => {
|
|
await exec.exec('npm', ['install', dep]);
|
|
});
|
|
-
|
|
name: Generate
|
|
id: generate
|
|
uses: actions/github-script@v7
|
|
env:
|
|
INPUT_WORKDIR: ${{ inputs.workdir }}
|
|
INPUT_FILES: ${{ inputs.files }}
|
|
INPUT_TARGET: ${{ inputs.target }}
|
|
with:
|
|
script: |
|
|
const { Util } = require('@docker/actions-toolkit/lib/util');
|
|
|
|
const workdir = core.getInput('workdir');
|
|
const files = Util.getInputList('files');
|
|
const target = core.getInput('target');
|
|
|
|
let def = {};
|
|
await core.group(`Validating definition`, async () => {
|
|
let args = ['buildx', 'bake'];
|
|
for (const file of files) {
|
|
args.push('--file', file);
|
|
}
|
|
if (target) {
|
|
args.push(target);
|
|
}
|
|
args.push('--print');
|
|
|
|
const res = await exec.getExecOutput('docker', args, {
|
|
ignoreReturnCode: true,
|
|
silent: true,
|
|
cwd: workdir
|
|
});
|
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
|
throw new Error(res.stderr);
|
|
}
|
|
def = JSON.parse(res.stdout.trim());
|
|
core.info(JSON.stringify(def, null, 2));
|
|
});
|
|
|
|
await core.group(`Set output`, async () => {
|
|
const targets = Object.keys(def.target);
|
|
core.info(`targets: ${JSON.stringify(targets)}`);
|
|
core.setOutput('targets', JSON.stringify(targets));
|
|
});
|