-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: CrazyMax <[email protected]>
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: ci-matrix-gen | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 10 * * *' | ||
push: | ||
branches: | ||
- 'master' | ||
- 'releases/v*' | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
|
||
jobs: | ||
group: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
- | ||
name: Matrix gen | ||
id: gen | ||
uses: ./subaction/matrix-gen | ||
with: | ||
workdir: ./test/group | ||
- | ||
name: Show matrix | ||
run: | | ||
echo matrix=${{ steps.gen.outputs.matrix }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# https://help.github.com/en/articles/metadata-syntax-for-github-actions | ||
name: 'Bake matrix generator' | ||
description: 'Generate a matrix to distribute 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 | ||
default: 'default' | ||
required: false | ||
|
||
outputs: | ||
matrix: | ||
description: Matrix of targets | ||
value: ${{ steps.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 definition`, async () => { | ||
let args = ['buildx', 'bake']; | ||
for (const file of files) { | ||
args.push('--file', file); | ||
} | ||
args.push(target, '--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 matrix`, async () => { | ||
const matrix = def.group[target].targets; | ||
core.info(`matrix: ${JSON.stringify(matrix)}`); | ||
core.setOutput('matrix', JSON.stringify(matrix)); | ||
}); |