Skip to content

Commit

Permalink
set matrix
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Nov 9, 2023
1 parent c2dd866 commit 7758b80
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions subaction/matrix-gen/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,41 @@ description: 'Generate a matrix to distribute builds in your workflow'

inputs:
workdir:
description: 'Working directory'
description: Working directory
default: '.'
required: false
files:
description: 'Comma separated list of Bake files'
description: Comma separated list of Bake files
required: false
target:
description: 'Bake target'
description: Bake target
default: 'default'
required: false

outputs:
matrix:
description: Matrix of targets
value: ${{ jobs.generate.outputs.matrix }}

runs:
using: composite
steps:
-
name: Generate matrix
id: generate
uses: actions/github-script@v6
with:
script: |
let def;
const files = `${{ inputs.files }}` ? `${{ inputs.files }}`.split(',') : [];
const target = `${{ inputs.target }}` ? `${{ inputs.target }}` : 'default';
await core.group(`Validating`, async () => {
await core.group(`Validating definition`, async () => {
let args = ['buildx', 'bake'];
if (`${{ inputs.files }}`) {
for (const file of `${{ inputs.files }}`.split(',')) {
args.push('--file', file);
}
}
if (`${{ inputs.target }}`) {
args.push(`${{ inputs.target }}`);
for (const file of files) {
args.push('--file', file);
}
args.push('--print');
args.push(target, '--print');
const res = await exec.getExecOutput('docker', args, {
ignoreReturnCode: true,
Expand All @@ -46,3 +51,9 @@ runs:
def = JSON.parse(res.stdout.trim());
core.info(JSON.stringify(def, null, 2));
});
await core.group(`Set matrix`, async () => {
const matrix = def.group[target].targets;
core.info(`matrix: ${JSON.stringify(matrix)}`);
core.setOutput('matrix', JSON.stringify(matrix));
});

0 comments on commit 7758b80

Please sign in to comment.