-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathaction.yml
61 lines (55 loc) · 1.81 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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: Generate
id: generate
uses: actions/github-script@v7
with:
script: |
let def;
const files = `${{ inputs.files }}` ? `${{ inputs.files }}`.split(/[\r?\n,]+/).filter(Boolean) : [];
const target = `${{ inputs.target }}`;
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: `${{ inputs.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));
});