-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from crazy-max/matrix-gen
list-targets subaction
- Loading branch information
Showing
7 changed files
with
234 additions
and
2 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,61 @@ | ||
name: ci-subaction | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 10 * * *' | ||
push: | ||
branches: | ||
- 'master' | ||
- 'releases/v*' | ||
tags: | ||
- 'v*' | ||
paths: | ||
- '.github/workflows/ci-subaction.yml' | ||
- 'subaction/**' | ||
- 'test/**' | ||
pull_request: | ||
paths: | ||
- '.github/workflows/ci-subaction.yml' | ||
- 'subaction/**' | ||
- 'test/**' | ||
|
||
jobs: | ||
list-targets-group: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
- | ||
name: Matrix gen | ||
id: gen | ||
uses: ./subaction/list-targets | ||
with: | ||
workdir: ./test/group | ||
- | ||
name: Show matrix | ||
run: | | ||
echo matrix=${{ steps.gen.outputs.matrix }} | ||
list-targets-group-matrix: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
- | ||
name: Matrix gen | ||
id: gen | ||
uses: ./subaction/list-targets | ||
with: | ||
workdir: ./test/group-matrix | ||
target: validate | ||
- | ||
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
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
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
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
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,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@v6 | ||
with: | ||
script: | | ||
let def; | ||
const files = `${{ inputs.files }}` ? `${{ inputs.files }}`.split(',') : []; | ||
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)); | ||
}); |
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,31 @@ | ||
group "validate" { | ||
targets = ["lint", "validate-vendor", "validate-doctoc"] | ||
} | ||
|
||
target "lint" { | ||
name = "lint-${buildtags.name}" | ||
dockerfile = "./hack/dockerfiles/lint.Dockerfile" | ||
target = buildtags.target | ||
output = ["type=cacheonly"] | ||
matrix = { | ||
buildtags = [ | ||
{ name = "default", tags = "", target = "golangci-lint" }, | ||
{ name = "labs", tags = "dfrunsecurity dfparents", target = "golangci-lint" }, | ||
{ name = "nydus", tags = "nydus", target = "golangci-lint" }, | ||
{ name = "yaml", tags = "", target = "yamllint" }, | ||
{ name = "proto", tags = "", target = "protolint" }, | ||
] | ||
} | ||
} | ||
|
||
target "validate-vendor" { | ||
dockerfile = "./hack/dockerfiles/vendor.Dockerfile" | ||
target = "validate" | ||
output = ["type=cacheonly"] | ||
} | ||
|
||
target "validate-doctoc" { | ||
dockerfile = "./hack/dockerfiles/doctoc.Dockerfile" | ||
target = "validate-toc" | ||
output = ["type=cacheonly"] | ||
} |