mirror of
https://github.com/docker/bake-action.git
synced 2026-10-14 19:30:27 +02:00
Merge pull request #514 from crazy-max/subaction-matrix-typescript
move the matrix subaction to TypeScript
This commit is contained in:
@@ -19,7 +19,9 @@ updates:
|
||||
- "dependencies"
|
||||
- "bot"
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
directories:
|
||||
- "/"
|
||||
- "/subaction/matrix"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
cooldown:
|
||||
|
||||
@@ -44,12 +44,12 @@ jobs:
|
||||
-
|
||||
name: Commit and push dist
|
||||
run: |
|
||||
if [ -n "$(git status --porcelain -- dist)" ]; then
|
||||
if [ -n "$(git status --porcelain -- dist subaction/matrix/dist)" ]; then
|
||||
(
|
||||
set -x
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git add dist
|
||||
git add dist subaction/matrix/dist
|
||||
git commit -m "[dependabot skip] chore: update generated content"
|
||||
git push
|
||||
)
|
||||
|
||||
+6
-4
@@ -40,10 +40,12 @@ RUN --mount=target=/context \
|
||||
--mount=type=cache,target=/src/node_modules <<EOT
|
||||
set -e
|
||||
rsync -a /context/. .
|
||||
rm -rf dist
|
||||
yarn run build
|
||||
rm -rf dist subaction/matrix/dist
|
||||
yarn workspaces foreach --all run build
|
||||
mkdir /out
|
||||
cp -r dist /out
|
||||
mkdir -p /out/subaction/matrix
|
||||
cp -r subaction/matrix/dist /out/subaction/matrix
|
||||
EOT
|
||||
|
||||
FROM scratch AS build-update
|
||||
@@ -55,9 +57,9 @@ RUN --mount=target=/context \
|
||||
set -e
|
||||
rsync -a /context/. .
|
||||
git add -A
|
||||
rm -rf dist
|
||||
rm -rf dist subaction/matrix/dist
|
||||
cp -rf /out/* .
|
||||
if [ -n "$(git status --porcelain -- dist)" ]; then
|
||||
if [ -n "$(git status --porcelain -- dist subaction/matrix/dist)" ]; then
|
||||
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
|
||||
git status --porcelain -- dist
|
||||
exit 1
|
||||
|
||||
+3
-2
@@ -2629,11 +2629,12 @@ END OF TERMS AND CONDITIONS
|
||||
|
||||
-----------
|
||||
|
||||
The following npm package may be included in this product:
|
||||
The following npm packages may be included in this product:
|
||||
|
||||
- @sigstore/verify@4.1.2
|
||||
- docker-buildx-bake-matrix@unknown
|
||||
|
||||
This package contains the following license:
|
||||
These packages each contain the following license:
|
||||
|
||||
Apache-2.0
|
||||
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import eslintPluginPrettier from 'eslint-plugin-prettier';
|
||||
|
||||
export default defineConfig([
|
||||
{
|
||||
ignores: ['.yarn/**/*', 'coverage/**/*', 'dist/**/*']
|
||||
ignores: ['.yarn/**/*', 'coverage/**/*', 'dist/**/*', 'subaction/matrix/dist/**/*']
|
||||
},
|
||||
js.configs.recommended,
|
||||
...tseslint.configs['flat/recommended'],
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
"test": "vitest run",
|
||||
"license": "generate-license-file --input package.json --output dist/licenses.txt --overwrite --ci --no-spinner --eol lf"
|
||||
},
|
||||
"workspaces": [
|
||||
"subaction/matrix"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/docker/bake-action.git"
|
||||
|
||||
@@ -20,82 +20,7 @@ inputs:
|
||||
outputs:
|
||||
matrix:
|
||||
description: Matrix configuration
|
||||
value: ${{ steps.generate.outputs.includes }}
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
-
|
||||
name: Generate
|
||||
id: generate
|
||||
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
||||
env:
|
||||
INPUT_WORKDIR: ${{ inputs.workdir }}
|
||||
INPUT_FILES: ${{ inputs.files }}
|
||||
INPUT_TARGET: ${{ inputs.target }}
|
||||
INPUT_FIELDS: ${{ inputs.fields }}
|
||||
with:
|
||||
script: |
|
||||
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');
|
||||
const fields = getInputList('fields');
|
||||
|
||||
let def = {};
|
||||
await core.group(`Parsing 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(`Generating matrix`, async () => {
|
||||
const result = [];
|
||||
for (const targetName of Object.keys(def.target)) {
|
||||
const target = def.target[targetName];
|
||||
const entry = { target: targetName };
|
||||
if (fields.length === 0) {
|
||||
result.push({ ...entry });
|
||||
continue;
|
||||
}
|
||||
let fieldFound = false;
|
||||
Object.keys(target).forEach(field => {
|
||||
if (fields.includes(field)) {
|
||||
fieldFound = true;
|
||||
const value = target[field];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((v) => {
|
||||
entry[field] = v;
|
||||
result.push({ ...entry });
|
||||
});
|
||||
} else {
|
||||
entry[field] = value;
|
||||
result.push({ ...entry });
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!fieldFound) {
|
||||
result.push({ ...entry });
|
||||
}
|
||||
}
|
||||
core.info(JSON.stringify(result, null, 2));
|
||||
core.setOutput('includes', JSON.stringify(result));
|
||||
});
|
||||
using: 'node24'
|
||||
main: 'dist/index.cjs'
|
||||
|
||||
Vendored
+159
File diff suppressed because one or more lines are too long
Vendored
+7
File diff suppressed because one or more lines are too long
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
This file was generated with the generate-license-file npm package!
|
||||
https://www.npmjs.com/package/generate-license-file
|
||||
|
||||
This file was generated with the generate-license-file npm package!
|
||||
https://www.npmjs.com/package/generate-license-file
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "docker-buildx-bake-matrix",
|
||||
"description": "GitHub Action to generate a multi-dimension GitHub matrix from bake definition files",
|
||||
"type": "module",
|
||||
"main": "src/main.ts",
|
||||
"scripts": {
|
||||
"build": "esbuild src/main.ts --bundle --platform=node --target=node24 --format=cjs --outfile=dist/index.cjs --sourcemap --minify --keep-names && yarn run license",
|
||||
"license": "generate-license-file --input package.json --output dist/licenses.txt --overwrite --ci --no-spinner --eol lf"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/docker/bake-action.git",
|
||||
"directory": "subaction/matrix"
|
||||
},
|
||||
"author": "Docker Inc.",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@actions/core": "^3.0.1",
|
||||
"@actions/exec": "^3.0.0",
|
||||
"@docker/actions-toolkit": "^0.100.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"esbuild": "^0.28.0",
|
||||
"generate-license-file": "^4.1.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as actionsToolkit from '@docker/actions-toolkit';
|
||||
|
||||
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx.js';
|
||||
import {Util} from '@docker/actions-toolkit/lib/util.js';
|
||||
|
||||
import {BakeDefinition, Target} from '@docker/actions-toolkit/lib/types/buildx/bake.js';
|
||||
|
||||
actionsToolkit.run(
|
||||
// main
|
||||
async () => {
|
||||
const workdir = core.getInput('workdir');
|
||||
const files = Util.getInputList('files');
|
||||
const target = core.getInput('target');
|
||||
const fields = Util.getInputList('fields');
|
||||
|
||||
const def = await core.group(`Parsing definition`, async () => {
|
||||
const 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.exitCode !== 0) {
|
||||
throw new Error(`buildx bake failed with: ${Buildx.getErrorMessage(res.stderr)}`);
|
||||
}
|
||||
const def: BakeDefinition = JSON.parse(res.stdout.trim());
|
||||
core.info(JSON.stringify(def, null, 2));
|
||||
return def;
|
||||
});
|
||||
|
||||
await core.group(`Generating matrix`, async () => {
|
||||
const result: Array<MatrixConfigEntry> = [];
|
||||
for (const [targetName, target] of Object.entries(def.target)) {
|
||||
const entry: MatrixConfigEntry = {target: targetName};
|
||||
if (fields.length === 0) {
|
||||
result.push(entry);
|
||||
continue;
|
||||
}
|
||||
let fieldFound = false;
|
||||
Object.keys(target).forEach(field => {
|
||||
if (fields.includes(field)) {
|
||||
fieldFound = true;
|
||||
const value = target[field];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(v => {
|
||||
entry[field] = v;
|
||||
result.push({...entry});
|
||||
});
|
||||
} else {
|
||||
entry[field] = value;
|
||||
result.push({...entry});
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!fieldFound) {
|
||||
result.push(entry);
|
||||
}
|
||||
}
|
||||
core.info(JSON.stringify(result, null, 2));
|
||||
core.setOutput('matrix', JSON.stringify(result));
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
type ArrayToSingleEntry<Type> = {
|
||||
[Property in keyof Type]: Type[Property] extends Array<infer Entry> ? Entry : Type[Property];
|
||||
};
|
||||
|
||||
type MatrixConfigEntry = Partial<ArrayToSingleEntry<Target>> & {
|
||||
target: string;
|
||||
};
|
||||
+2
-1
@@ -12,6 +12,7 @@
|
||||
"useUnknownInCatchVariables": false,
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
"src/**/*.ts",
|
||||
"subaction/matrix/src/**/*.ts"
|
||||
]
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ export default defineConfig({
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reporter: ['clover'],
|
||||
include: ['src/**/*.ts'],
|
||||
exclude: ['src/**/main.ts']
|
||||
include: ['src/**/*.ts', 'subaction/matrix/src/**/*.ts'],
|
||||
exclude: ['src/**/main.ts', 'subaction/matrix/src/**/main.ts']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2830,6 +2830,18 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"docker-buildx-bake-matrix@workspace:subaction/matrix":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "docker-buildx-bake-matrix@workspace:subaction/matrix"
|
||||
dependencies:
|
||||
"@actions/core": "npm:^3.0.1"
|
||||
"@actions/exec": "npm:^3.0.0"
|
||||
"@docker/actions-toolkit": "npm:^0.100.0"
|
||||
esbuild: "npm:^0.28.0"
|
||||
generate-license-file: "npm:^4.1.1"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"docker-buildx-bake@workspace:.":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "docker-buildx-bake@workspace:."
|
||||
|
||||
Reference in New Issue
Block a user