mirror of
https://github.com/docker/build-push-action.git
synced 2026-06-30 19:12:00 +00:00
Compare commits
9 Commits
d188ab8bb0
...
35f3630278
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35f3630278 | ||
|
|
b274a74e63 | ||
|
|
1a557b3d82 | ||
|
|
0af89ac169 | ||
|
|
8e3a402792 | ||
|
|
df19a799eb | ||
|
|
0e2ab16cd2 | ||
|
|
54d0f58d64 | ||
|
|
563a2f55e4 |
@ -1,12 +1,15 @@
|
||||
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import {Builder} from '@docker/actions-toolkit/lib/buildx/builder';
|
||||
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
||||
import {Build} from '@docker/actions-toolkit/lib/buildx/build';
|
||||
import {Context} from '@docker/actions-toolkit/lib/context';
|
||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||
|
||||
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/builder';
|
||||
import {GitHubRepo} from '@docker/actions-toolkit/lib/types/github';
|
||||
|
||||
@ -35,6 +38,16 @@ jest.spyOn(Docker, 'isAvailable').mockImplementation(async (): Promise<boolean>
|
||||
return true;
|
||||
});
|
||||
|
||||
const metadataJson = path.join(tmpDir, 'metadata.json');
|
||||
jest.spyOn(Build.prototype, 'getMetadataFilePath').mockImplementation((): string => {
|
||||
return metadataJson;
|
||||
});
|
||||
|
||||
const imageIDFilePath = path.join(tmpDir, 'iidfile.txt');
|
||||
jest.spyOn(Build.prototype, 'getImageIDFilePath').mockImplementation((): string => {
|
||||
return imageIDFilePath;
|
||||
});
|
||||
|
||||
jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<BuilderInfo> => {
|
||||
return {
|
||||
name: 'builder2',
|
||||
@ -78,7 +91,7 @@ describe('getArgs', () => {
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -101,7 +114,7 @@ ccc"`],
|
||||
'--build-arg', 'MY_ARG=val1,val2,val3',
|
||||
'--build-arg', 'ARG=val',
|
||||
'--build-arg', `MULTILINE=aaaa\nbbbb\nccc`,
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'https://github.com/docker/build-push-action.git#refs/heads/master'
|
||||
]
|
||||
],
|
||||
@ -117,7 +130,7 @@ ccc"`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--tag', 'name/app:7.4',
|
||||
'--tag', 'name/app:latest',
|
||||
'https://github.com/docker/build-push-action.git#refs/heads/master'
|
||||
@ -172,7 +185,7 @@ ccc"`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -189,7 +202,7 @@ ccc"`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
|
||||
'.'
|
||||
]
|
||||
@ -230,7 +243,7 @@ ccc"`],
|
||||
[
|
||||
'build',
|
||||
'--file', './test/Dockerfile',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--platform', 'linux/amd64,linux/arm64',
|
||||
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
|
||||
'--builder', 'builder-git-context-2',
|
||||
@ -264,7 +277,7 @@ ccc"`],
|
||||
[
|
||||
'build',
|
||||
'--file', './test/Dockerfile',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--platform', 'linux/amd64,linux/arm64',
|
||||
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
|
||||
'--secret', `id=MYSECRET,src=${tmpName}`,
|
||||
@ -301,7 +314,7 @@ ccc`],
|
||||
[
|
||||
'build',
|
||||
'--file', './test/Dockerfile',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--platform', 'linux/amd64,linux/arm64',
|
||||
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
|
||||
'--secret', `id=MYSECRET,src=${tmpName}`,
|
||||
@ -330,7 +343,7 @@ ccc`],
|
||||
[
|
||||
'build',
|
||||
'--file', './test/Dockerfile',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--secret', `id=MY_SECRET,src=${tmpName}`,
|
||||
'--builder', 'builder-git-context-2',
|
||||
'--network', 'host',
|
||||
@ -377,8 +390,8 @@ ccc`],
|
||||
'--add-host', 'docker:10.180.0.1',
|
||||
'--add-host', 'foo:10.0.0.1',
|
||||
'--file', './test/Dockerfile',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--metadata-file', metadataJson,
|
||||
'--network', 'host',
|
||||
'--push',
|
||||
'.'
|
||||
@ -406,11 +419,11 @@ nproc=3`],
|
||||
'--add-host', 'foo:10.0.0.1',
|
||||
'--cgroup-parent', 'foo',
|
||||
'--file', './test/Dockerfile',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--shm-size', '2g',
|
||||
'--ulimit', 'nofile=1024:1024',
|
||||
'--ulimit', 'nproc=3',
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -426,8 +439,8 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--metadata-file', metadataJson,
|
||||
'https://github.com/docker/build-push-action.git#refs/heads/master:docker'
|
||||
]
|
||||
],
|
||||
@ -444,9 +457,9 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'https://github.com/docker/build-push-action.git#refs/heads/master:subdir'
|
||||
]
|
||||
],
|
||||
@ -463,8 +476,8 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -480,9 +493,9 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -499,9 +512,9 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--attest', `type=provenance,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -518,9 +531,9 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--attest', `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -537,9 +550,9 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--attest', 'type=provenance,disabled=true',
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -556,9 +569,9 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--attest', 'type=provenance,builder-id=foo',
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -575,9 +588,9 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
"--output", 'type=docker',
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -593,9 +606,9 @@ nproc=3`],
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--load',
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -613,9 +626,9 @@ nproc=3`],
|
||||
[
|
||||
'build',
|
||||
'--build-arg', 'FOO=bar#baz',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--load',
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -635,9 +648,9 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
|
||||
'build',
|
||||
'--secret', 'id=MY_SECRET,env=MY_SECRET_ENV',
|
||||
'--secret', 'id=ANOTHER_SECRET,env=ANOTHER_SECRET_ENV',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--load',
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -656,9 +669,9 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
|
||||
'build',
|
||||
'--secret', 'id=MY_SECRET,env=MY_SECRET_ENV',
|
||||
'--secret', 'id=ANOTHER_SECRET,env=ANOTHER_SECRET_ENV',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--load',
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -678,7 +691,7 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
|
||||
'build',
|
||||
'--output', 'type=local,dest=./release-out',
|
||||
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -702,7 +715,7 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
|
||||
'--annotation', 'manifest-descriptor[linux/amd64]:example4=zzz',
|
||||
'--output', 'type=local,dest=./release-out',
|
||||
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -719,10 +732,10 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
"--output", `type=image,"name=localhost:5000/name/app:latest,localhost:5000/name/app:foo",push-by-digest=true,name-canonical=true,push=true`,
|
||||
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -740,10 +753,10 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--attest', `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--attest', `type=sbom,disabled=false`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -761,9 +774,9 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--attest', `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
@ -780,9 +793,9 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
|
||||
]),
|
||||
[
|
||||
'build',
|
||||
'--iidfile', path.join(tmpDir, 'iidfile'),
|
||||
'--iidfile', imageIDFilePath,
|
||||
'--attest', `type=provenance,mode=min,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
|
||||
'--metadata-file', path.join(tmpDir, 'metadata-file'),
|
||||
'--metadata-file', metadataJson,
|
||||
'.'
|
||||
]
|
||||
],
|
||||
|
||||
24
dist/index.js
generated
vendored
24
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
44
dist/licenses.txt
generated
vendored
44
dist/licenses.txt
generated
vendored
@ -2602,6 +2602,31 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
isarray
|
||||
MIT
|
||||
|
||||
js-yaml
|
||||
MIT
|
||||
(The MIT License)
|
||||
|
||||
Copyright (C) 2011-2015 by Vitaly Puzrin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
jwt-decode
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
@ -3855,25 +3880,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
yallist
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
zip-stream
|
||||
MIT
|
||||
Copyright (c) 2014 Chris Talkington, contributors.
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
"packageManager": "yarn@3.6.3",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@docker/actions-toolkit": "0.22.0",
|
||||
"@docker/actions-toolkit": "https://github.com/crazy-max/docker-actions-toolkit#summary-test",
|
||||
"handlebars": "^4.7.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -136,7 +136,7 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
|
||||
args.push('--file', inputs.file);
|
||||
}
|
||||
if (!Build.hasLocalExporter(inputs.outputs) && !Build.hasTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || (await toolkit.buildx.versionSatisfies('>=0.4.2')))) {
|
||||
args.push('--iidfile', Build.getImageIDFilePath());
|
||||
args.push('--iidfile', toolkit.buildxBuild.getImageIDFilePath());
|
||||
}
|
||||
await Util.asyncForEach(inputs.labels, async label => {
|
||||
args.push('--label', label);
|
||||
@ -199,7 +199,7 @@ async function getCommonArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<st
|
||||
args.push('--load');
|
||||
}
|
||||
if (await toolkit.buildx.versionSatisfies('>=0.6.0')) {
|
||||
args.push('--metadata-file', Build.getMetadataFilePath());
|
||||
args.push('--metadata-file', toolkit.buildxBuild.getMetadataFilePath());
|
||||
}
|
||||
if (inputs.network) {
|
||||
args.push('--network', inputs.network);
|
||||
|
||||
69
src/main.ts
69
src/main.ts
@ -4,12 +4,14 @@ import * as stateHelper from './state-helper';
|
||||
import * as core from '@actions/core';
|
||||
import * as actionsToolkit from '@docker/actions-toolkit';
|
||||
|
||||
import {Build} from '@docker/actions-toolkit/lib/buildx/build';
|
||||
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx';
|
||||
import {History as BuildxHistory} from '@docker/actions-toolkit/lib/buildx/history';
|
||||
import {Context} from '@docker/actions-toolkit/lib/context';
|
||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
|
||||
import {Exec} from '@docker/actions-toolkit/lib/exec';
|
||||
import {GitHub} from '@docker/actions-toolkit/lib/github';
|
||||
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
|
||||
import {Util} from '@docker/actions-toolkit/lib/util';
|
||||
|
||||
import {ConfigFile} from '@docker/actions-toolkit/lib/types/docker';
|
||||
|
||||
@ -18,8 +20,10 @@ import * as context from './context';
|
||||
actionsToolkit.run(
|
||||
// main
|
||||
async () => {
|
||||
const startedTime = new Date();
|
||||
const inputs: context.Inputs = await context.getInputs();
|
||||
core.debug(`inputs: ${JSON.stringify(inputs)}`);
|
||||
stateHelper.setInputs(inputs);
|
||||
|
||||
const toolkit = new Toolkit();
|
||||
|
||||
@ -83,17 +87,18 @@ actionsToolkit.run(
|
||||
core.debug(`buildCmd.command: ${buildCmd.command}`);
|
||||
core.debug(`buildCmd.args: ${JSON.stringify(buildCmd.args)}`);
|
||||
|
||||
let err: Error | undefined;
|
||||
await Exec.getExecOutput(buildCmd.command, buildCmd.args, {
|
||||
ignoreReturnCode: true
|
||||
}).then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
|
||||
err = Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'}`);
|
||||
}
|
||||
});
|
||||
|
||||
const imageID = Build.resolveImageID();
|
||||
const metadata = Build.resolveMetadata();
|
||||
const digest = Build.resolveDigest();
|
||||
const imageID = toolkit.buildxBuild.resolveImageID();
|
||||
const metadata = toolkit.buildxBuild.resolveMetadata();
|
||||
const digest = toolkit.buildxBuild.resolveDigest();
|
||||
|
||||
if (imageID) {
|
||||
await core.group(`ImageID`, async () => {
|
||||
@ -114,9 +119,44 @@ actionsToolkit.run(
|
||||
core.setOutput('metadata', metadatadt);
|
||||
});
|
||||
}
|
||||
await core.group(`Reference`, async () => {
|
||||
const ref = await buildRef(toolkit, startedTime, inputs.builder);
|
||||
if (ref) {
|
||||
core.info(ref);
|
||||
stateHelper.setBuildRef(ref);
|
||||
} else {
|
||||
core.warning('No build ref found');
|
||||
}
|
||||
});
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
// post
|
||||
async () => {
|
||||
if (stateHelper.buildRef.length > 0) {
|
||||
await core.group(`Generating build summary`, async () => {
|
||||
try {
|
||||
const buildxHistory = new BuildxHistory();
|
||||
const exportRes = await buildxHistory.export({
|
||||
refs: [stateHelper.buildRef]
|
||||
});
|
||||
core.info(`Build record exported to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`);
|
||||
const uploadRes = await GitHub.uploadArtifact({
|
||||
filename: exportRes.dockerbuildFilename,
|
||||
mimeType: 'application/gzip',
|
||||
retentionDays: 90
|
||||
});
|
||||
await GitHub.writeBuildSummary({
|
||||
exportRes: exportRes,
|
||||
uploadRes: uploadRes,
|
||||
inputs: stateHelper.inputs
|
||||
});
|
||||
} catch (e) {
|
||||
core.warning(e.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (stateHelper.tmpDir.length > 0) {
|
||||
await core.group(`Removing temp folder ${stateHelper.tmpDir}`, async () => {
|
||||
fs.rmSync(stateHelper.tmpDir, {recursive: true});
|
||||
@ -124,3 +164,22 @@ actionsToolkit.run(
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
async function buildRef(toolkit: Toolkit, since: Date, builder?: string): Promise<string> {
|
||||
// get ref from metadata file
|
||||
const ref = toolkit.buildxBuild.resolveRef();
|
||||
if (ref) {
|
||||
return ref;
|
||||
}
|
||||
// otherwise, look for the very first build ref since the build has started
|
||||
if (!builder) {
|
||||
const currentBuilder = await toolkit.builder.inspect();
|
||||
builder = currentBuilder.name;
|
||||
}
|
||||
const refs = Buildx.refs({
|
||||
dir: Buildx.refsDir,
|
||||
builderName: builder,
|
||||
since: since
|
||||
});
|
||||
return Object.keys(refs).length > 0 ? Object.keys(refs)[0] : '';
|
||||
}
|
||||
|
||||
@ -1,7 +1,34 @@
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import {Inputs} from './context';
|
||||
|
||||
export const tmpDir = process.env['STATE_tmpDir'] || '';
|
||||
export const inputs = process.env['STATE_inputs'] ? JSON.parse(process.env['STATE_inputs']) : undefined;
|
||||
export const buildRef = process.env['STATE_buildRef'] || '';
|
||||
|
||||
export function setTmpDir(tmpDir: string) {
|
||||
core.saveState('tmpDir', tmpDir);
|
||||
}
|
||||
|
||||
export function setInputs(inputs: Inputs) {
|
||||
const newInputs = {};
|
||||
for (const key of Object.keys(inputs)) {
|
||||
if (key === 'github-token') {
|
||||
continue;
|
||||
}
|
||||
const value: string | string[] | boolean = inputs[key];
|
||||
if (typeof value === 'boolean' && value === false) {
|
||||
continue;
|
||||
} else if (Array.isArray(value) && value.length === 0) {
|
||||
continue;
|
||||
} else if (!value) {
|
||||
continue;
|
||||
}
|
||||
newInputs[key] = value;
|
||||
}
|
||||
core.saveState('inputs', JSON.stringify(newInputs));
|
||||
}
|
||||
|
||||
export function setBuildRef(buildRef: string) {
|
||||
core.saveState('buildRef', buildRef);
|
||||
}
|
||||
|
||||
35
yarn.lock
35
yarn.lock
@ -1055,9 +1055,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@docker/actions-toolkit@npm:0.22.0":
|
||||
version: 0.22.0
|
||||
resolution: "@docker/actions-toolkit@npm:0.22.0"
|
||||
"@docker/actions-toolkit@https://github.com/crazy-max/docker-actions-toolkit#summary-test":
|
||||
version: 0.0.0+unknown
|
||||
resolution: "@docker/actions-toolkit@https://github.com/crazy-max/docker-actions-toolkit.git#commit=3bf4429db863cb5fc40af57778d3dc44b794d5a0"
|
||||
dependencies:
|
||||
"@actions/artifact": ^2.1.7
|
||||
"@actions/cache": ^3.2.4
|
||||
@ -1071,12 +1071,13 @@ __metadata:
|
||||
"@octokit/core": ^5.1.0
|
||||
"@octokit/plugin-rest-endpoint-methods": ^10.4.0
|
||||
async-retry: ^1.3.3
|
||||
csv-parse: ^5.5.5
|
||||
csv-parse: ^5.5.6
|
||||
handlebars: ^4.7.8
|
||||
js-yaml: ^4.1.0
|
||||
jwt-decode: ^4.0.0
|
||||
semver: ^7.6.0
|
||||
semver: ^7.6.2
|
||||
tmp: ^0.2.3
|
||||
checksum: 860bfe0f4b161181ffae47a9f82612b5d812b0197f582f5308fc80e8e3c55a47595134619cc7805df71a79a891fd10b6b1c4fb95c498423df1ea82a5fd84b44e
|
||||
checksum: d285217419e425f116ea85f6abf10e9cb2604f28f7760e8cf374f1b756c8529e7d098bcd224929a89b4c4b4b00c10a7f0591cfb9dc649bdb9dc9604a687e31e2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -3113,13 +3114,20 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"csv-parse@npm:*, csv-parse@npm:^5.5.5":
|
||||
"csv-parse@npm:*":
|
||||
version: 5.5.5
|
||||
resolution: "csv-parse@npm:5.5.5"
|
||||
checksum: 9e76b3dc3dbbf0a9b1c3529843e3891f0da23d094bdb0540a3d8f4083d00110dd545399f9cf510498def6c1fc7012cc6bc00046d281f16d705add64099467973
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"csv-parse@npm:^5.5.6":
|
||||
version: 5.5.6
|
||||
resolution: "csv-parse@npm:5.5.6"
|
||||
checksum: ee06f97f674487dc1d001b360de8ea510a41b9d971abf43bcf9c3be22c83a3634df0d3ebfbe52fd49d145077066be7ff9f25de3fc6b71aefb973099b04147a25
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"debug@npm:4, debug@npm:^4.3.4":
|
||||
version: 4.3.4
|
||||
resolution: "debug@npm:4.3.4"
|
||||
@ -3260,7 +3268,7 @@ __metadata:
|
||||
resolution: "docker-build-push@workspace:."
|
||||
dependencies:
|
||||
"@actions/core": ^1.10.1
|
||||
"@docker/actions-toolkit": 0.22.0
|
||||
"@docker/actions-toolkit": "https://github.com/crazy-max/docker-actions-toolkit#summary-test"
|
||||
"@types/csv-parse": ^1.2.2
|
||||
"@types/node": ^20.5.9
|
||||
"@typescript-eslint/eslint-plugin": ^6.6.0
|
||||
@ -6064,7 +6072,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"semver@npm:^7.3.5, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.0":
|
||||
"semver@npm:^7.3.5, semver@npm:^7.5.3, semver@npm:^7.5.4":
|
||||
version: 7.6.0
|
||||
resolution: "semver@npm:7.6.0"
|
||||
dependencies:
|
||||
@ -6075,6 +6083,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"semver@npm:^7.6.2":
|
||||
version: 7.6.2
|
||||
resolution: "semver@npm:7.6.2"
|
||||
bin:
|
||||
semver: bin/semver.js
|
||||
checksum: 40f6a95101e8d854357a644da1b8dd9d93ce786d5c6a77227bc69dbb17bea83d0d1d1d7c4cd5920a6df909f48e8bd8a5909869535007f90278289f2451d0292d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"shebang-command@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "shebang-command@npm:2.0.0"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user