Merge pull request #370 from crazy-max/remove-list-targets
remove list-targets subaction
This commit is contained in:
BIN
.github/subaction-list-targets.png
vendored
BIN
.github/subaction-list-targets.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 8.1 KiB |
50
.github/workflows/ci-subaction.yml
vendored
50
.github/workflows/ci-subaction.yml
vendored
@@ -25,56 +25,6 @@ on:
|
|||||||
- 'test/**'
|
- 'test/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
list-targets:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
-
|
|
||||||
testdir: group
|
|
||||||
expected: >
|
|
||||||
["t1","t2"]
|
|
||||||
-
|
|
||||||
testdir: group-matrix
|
|
||||||
target: validate
|
|
||||||
expected: >
|
|
||||||
["lint-default","lint-labs","lint-nydus","lint-proto","lint-yaml","validate-doctoc","validate-vendor"]
|
|
||||||
-
|
|
||||||
testdir: multi-files
|
|
||||||
files: |
|
|
||||||
docker-bake.json
|
|
||||||
docker-bake.hcl
|
|
||||||
expected: >
|
|
||||||
["v1-tag","v2-tag"]
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
-
|
|
||||||
name: Matrix gen
|
|
||||||
id: gen
|
|
||||||
uses: ./subaction/list-targets
|
|
||||||
with:
|
|
||||||
workdir: ./test/${{ matrix.testdir }}
|
|
||||||
files: ${{ matrix.files }}
|
|
||||||
target: ${{ matrix.target }}
|
|
||||||
-
|
|
||||||
name: Check output
|
|
||||||
uses: actions/github-script@v8
|
|
||||||
env:
|
|
||||||
INPUT_TARGETS: ${{ steps.gen.outputs.targets }}
|
|
||||||
INPUT_EXPECTED: ${{ matrix.expected }}
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const targets = JSON.stringify(JSON.parse(core.getInput('targets')));
|
|
||||||
const expected = JSON.stringify(JSON.parse(core.getInput('expected')));
|
|
||||||
if (targets !== expected) {
|
|
||||||
throw new Error(`Targets do not match expected values: ${targets} != ${expected}`);
|
|
||||||
} else {
|
|
||||||
core.info(`✅`);
|
|
||||||
}
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
|
|||||||
6
.github/workflows/validate.yml
vendored
6
.github/workflows/validate.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
prepare:
|
prepare:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
targets: ${{ steps.generate.outputs.targets }}
|
matrix: ${{ steps.generate.outputs.matrix }}
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
@@ -23,7 +23,7 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: List targets
|
name: List targets
|
||||||
id: generate
|
id: generate
|
||||||
uses: ./subaction/list-targets
|
uses: ./subaction/matrix
|
||||||
with:
|
with:
|
||||||
target: validate
|
target: validate
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
target: ${{ fromJson(needs.prepare.outputs.targets) }}
|
include: ${{ fromJson(needs.prepare.outputs.matrix) }}
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Validate
|
name: Validate
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
> [!WARNING]
|
|
||||||
> `docker/bake-action/subaction/list-targets` is deprecated and will be removed
|
|
||||||
> in a future release. Please use [`docker/bake-action/subaction/matrix`](../matrix)
|
|
||||||
> instead.
|
|
||||||
|
|
||||||
## About
|
|
||||||
|
|
||||||
This subaction generates a list of Bake targets that can be used in a [GitHub matrix](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix),
|
|
||||||
so you can distribute your builds across multiple runners.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
___
|
|
||||||
|
|
||||||
* [Usage](#usage)
|
|
||||||
* [Customizing](#customizing)
|
|
||||||
* [inputs](#inputs)
|
|
||||||
* [outputs](#outputs)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```hcl
|
|
||||||
# docker-bake.hcl
|
|
||||||
group "validate" {
|
|
||||||
targets = ["lint", "doctoc"]
|
|
||||||
}
|
|
||||||
|
|
||||||
target "lint" {
|
|
||||||
target = "lint"
|
|
||||||
}
|
|
||||||
|
|
||||||
target "doctoc" {
|
|
||||||
target = "doctoc"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
jobs:
|
|
||||||
prepare:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
targets: ${{ steps.generate.outputs.targets }}
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
-
|
|
||||||
name: List targets
|
|
||||||
id: generate
|
|
||||||
uses: docker/bake-action/subaction/list-targets@v6
|
|
||||||
with:
|
|
||||||
target: validate
|
|
||||||
|
|
||||||
validate:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- prepare
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
target: ${{ fromJson(needs.prepare.outputs.targets) }}
|
|
||||||
steps:
|
|
||||||
-
|
|
||||||
name: Validate
|
|
||||||
uses: docker/bake-action@v6
|
|
||||||
with:
|
|
||||||
targets: ${{ matrix.target }}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Customizing
|
|
||||||
|
|
||||||
### inputs
|
|
||||||
|
|
||||||
| Name | Type | Description |
|
|
||||||
|--------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
|
||||||
| `workdir` | String | Working directory to use (defaults to `.`) |
|
|
||||||
| `files` | List/CSV | List of [bake definition files](https://docs.docker.com/build/customize/bake/file-definition/) |
|
|
||||||
| `target` | String | The target to use within the bake file |
|
|
||||||
|
|
||||||
### outputs
|
|
||||||
|
|
||||||
The following outputs are available
|
|
||||||
|
|
||||||
| Name | Type | Description |
|
|
||||||
|------------|----------|---------------------------|
|
|
||||||
| `targets` | List/CSV | List of extracted targets |
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
# 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
|
|
||||||
env:
|
|
||||||
INPUT_WORKDIR: ${{ inputs.workdir }}
|
|
||||||
INPUT_FILES: ${{ inputs.files }}
|
|
||||||
INPUT_TARGET: ${{ inputs.target }}
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
core.warning(`docker/bake-action/subaction/list-targets is deprecated and will be removed in a future release. Please use docker/bake-action/subaction/matrix instead.`);
|
|
||||||
|
|
||||||
function getInputList(name) {
|
|
||||||
return core.getInput(name) ? core.getInput(name).split(/[\r?\n,]+/).filter(x => x !== '') : [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const workdir = core.getInput('workdir');
|
|
||||||
const files = 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));
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user