1
0
Files

1031 lines
29 KiB
TypeScript
Raw Permalink Normal View History

2026-02-28 16:32:47 +01:00
import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest';
import * as fs from 'fs';
2026-02-28 16:32:47 +01:00
import * as os from 'os';
import * as path from 'path';
2026-02-28 16:47:36 +01:00
import {Builder} from '@docker/actions-toolkit/lib/buildx/builder.js';
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx.js';
import {Build} from '@docker/actions-toolkit/lib/buildx/build.js';
import {Context} from '@docker/actions-toolkit/lib/context.js';
import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js';
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js';
2026-02-28 16:47:36 +01:00
import {BuilderInfo} from '@docker/actions-toolkit/lib/types/buildx/builder.js';
2026-02-28 16:32:47 +01:00
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'context-'));
const tmpName = path.join(tmpDir, '.tmpname-vi');
const fixturesDir = path.join(__dirname, 'fixtures');
2026-02-28 16:32:47 +01:00
vi.spyOn(Context, 'tmpDir').mockImplementation((): string => {
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir;
});
2026-02-28 16:32:47 +01:00
vi.spyOn(Context, 'tmpName').mockImplementation((): string => {
2023-02-20 11:11:15 +01:00
return tmpName;
});
2026-02-28 16:32:47 +01:00
vi.spyOn(Docker, 'isAvailable').mockImplementation(async (): Promise<boolean> => {
2023-02-20 11:11:15 +01:00
return true;
});
const metadataJson = path.join(tmpDir, 'metadata.json');
2026-02-28 16:32:47 +01:00
vi.spyOn(Build.prototype, 'getMetadataFilePath').mockImplementation((): string => {
return metadataJson;
});
const imageIDFilePath = path.join(tmpDir, 'iidfile.txt');
2026-02-28 16:32:47 +01:00
vi.spyOn(Build.prototype, 'getImageIDFilePath').mockImplementation((): string => {
return imageIDFilePath;
});
type BuilderInfoFixture = Omit<BuilderInfo, 'lastActivity'> & {lastActivity: string};
const builderInfoFixture = <BuilderInfoFixture>JSON.parse(fs.readFileSync(path.join(fixturesDir, 'builder-info.json'), {encoding: 'utf-8'}).trim());
2026-02-28 16:32:47 +01:00
vi.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<BuilderInfo> => {
2023-02-20 11:11:15 +01:00
return {
...builderInfoFixture,
lastActivity: new Date(builderInfoFixture.lastActivity)
2023-02-20 11:11:15 +01:00
};
});
2023-01-13 12:57:15 +01:00
describe('getInputs', () => {
const originalEnv = process.env;
beforeEach(() => {
process.env = Object.keys(process.env).reduce((object, key) => {
if (!key.startsWith('INPUT_')) {
object[key] = process.env[key];
}
return object;
}, {});
});
afterEach(() => {
process.env = originalEnv;
});
function setRequiredBooleanInputs(): void {
setInput('load', 'false');
setInput('no-cache', 'false');
setInput('push', 'false');
setInput('pull', 'false');
}
test('uses Build git context when context input is empty', async () => {
const gitContext = 'https://github.com/docker/build-push-action.git?ref=refs/heads/master';
const gitContextSpy = vi.spyOn(Build.prototype, 'gitContext').mockResolvedValue(gitContext);
setRequiredBooleanInputs();
const context = await loadContextModule();
const inputs = await context.getInputs();
expect(inputs.context).toBe(gitContext);
expect(gitContextSpy).toHaveBeenCalledTimes(1);
gitContextSpy.mockRestore();
});
test('renders defaultContext templates from Build git context', async () => {
const gitContext = 'https://github.com/docker/build-push-action.git#refs/heads/master';
const gitContextSpy = vi.spyOn(Build.prototype, 'gitContext').mockResolvedValue(gitContext);
setRequiredBooleanInputs();
setInput('context', '{{defaultContext}}:subdir');
const context = await loadContextModule();
const inputs = await context.getInputs();
expect(inputs.context).toBe(`${gitContext}:subdir`);
expect(gitContextSpy).toHaveBeenCalledTimes(1);
gitContextSpy.mockRestore();
});
test('requests untrimmed secrets input explicitly', async () => {
const gitContext = 'https://github.com/docker/build-push-action.git#refs/heads/master';
const gitContextSpy = vi.spyOn(Build.prototype, 'gitContext').mockResolvedValue(gitContext);
const getInputList = vi.fn().mockReturnValue([]);
vi.resetModules();
vi.doMock('@docker/actions-toolkit/lib/util.js', () => ({
Util: {
getInputList
}
}));
setRequiredBooleanInputs();
setInput('secrets', `"PRIVATE_SSH_KEY=test\n\n"`);
const context = await import('../src/context.js');
await context.getInputs();
expect(getInputList).toHaveBeenCalledWith('secrets', {ignoreComma: true, trimWhitespace: false});
vi.doUnmock('@docker/actions-toolkit/lib/util.js');
gitContextSpy.mockRestore();
});
});
describe('getArgs', () => {
2025-03-28 11:16:09 +01:00
const originalEnv = process.env;
beforeEach(() => {
process.env = Object.keys(process.env).reduce((object, key) => {
if (!key.startsWith('INPUT_')) {
object[key] = process.env[key];
}
return object;
}, {});
});
2025-03-28 11:16:09 +01:00
afterEach(() => {
process.env = originalEnv;
});
// prettier-ignore
test.each([
2020-10-21 09:51:06 +02:00
[
2021-11-16 05:19:44 +01:00
0,
2020-10-21 09:51:06 +02:00
'0.4.1',
new Map<string, string>([
['context', '.'],
2021-06-22 17:25:52 +02:00
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2020-10-21 09:51:06 +02:00
]),
[
'build',
'--iidfile', imageIDFilePath,
2020-10-21 09:51:06 +02:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2020-10-21 09:51:06 +02:00
],
[
2021-11-16 05:19:44 +01:00
1,
'0.4.2',
new Map<string, string>([
2023-01-13 12:57:15 +01:00
['build-args', `MY_ARG=val1,val2,val3
ARG=val
"MULTILINE=aaaa
bbbb
ccc"`],
2021-06-22 17:25:52 +02:00
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
]),
[
'build',
'--build-arg', 'MY_ARG=val1,val2,val3',
'--build-arg', 'ARG=val',
2023-01-13 12:57:15 +01:00
'--build-arg', `MULTILINE=aaaa\nbbbb\nccc`,
'--iidfile', imageIDFilePath,
2023-02-20 11:11:15 +01:00
'https://github.com/docker/build-push-action.git#refs/heads/master'
2025-03-28 11:16:09 +01:00
],
undefined
],
2020-12-05 03:40:39 +01:00
[
2021-11-16 05:19:44 +01:00
2,
2020-12-05 03:40:39 +01:00
'0.4.2',
new Map<string, string>([
['tags', 'name/app:7.4, name/app:latest'],
2021-06-22 17:25:52 +02:00
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2020-12-05 03:40:39 +01:00
]),
[
'build',
'--iidfile', imageIDFilePath,
2020-12-05 03:40:39 +01:00
'--tag', 'name/app:7.4',
'--tag', 'name/app:latest',
2023-02-20 11:11:15 +01:00
'https://github.com/docker/build-push-action.git#refs/heads/master'
2025-03-28 11:16:09 +01:00
],
undefined
2020-12-05 03:40:39 +01:00
],
[
2021-11-16 05:19:44 +01:00
3,
'0.4.2',
new Map<string, string>([
['context', '.'],
['labels', 'org.opencontainers.image.title=buildkit\norg.opencontainers.image.description=concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit'],
2021-06-22 17:25:52 +02:00
['outputs', 'type=local,dest=./release-out'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
]),
[
'build',
'--label', 'org.opencontainers.image.title=buildkit',
'--label', 'org.opencontainers.image.description=concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit',
'--output', 'type=local,dest=./release-out',
'.'
2025-03-28 11:16:09 +01:00
],
undefined
],
2020-10-21 09:51:06 +02:00
[
2021-11-16 05:19:44 +01:00
4,
2020-10-21 09:51:06 +02:00
'0.4.1',
new Map<string, string>([
['context', '.'],
2021-06-22 17:25:52 +02:00
['platforms', 'linux/amd64,linux/arm64'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2020-10-21 09:51:06 +02:00
]),
[
'build',
'--platform', 'linux/amd64,linux/arm64',
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2020-10-21 09:51:06 +02:00
],
[
2021-11-16 05:19:44 +01:00
5,
'0.4.1',
new Map<string, string>([
2021-06-22 17:25:52 +02:00
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'.'
2025-03-28 11:16:09 +01:00
],
undefined
],
[
2021-11-16 05:19:44 +01:00
6,
'0.4.2',
new Map<string, string>([
['context', '.'],
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
2021-06-22 17:25:52 +02:00
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
2023-02-20 11:11:15 +01:00
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
'.'
2025-03-28 11:16:09 +01:00
],
undefined
],
[
2021-11-16 05:19:44 +01:00
7,
'0.4.2',
new Map<string, string>([
2020-10-20 15:18:02 +02:00
['github-token', 'abcdefghijklmno0123456789'],
2021-06-22 17:25:52 +02:00
['outputs', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
]),
[
'build',
2020-10-20 15:18:02 +02:00
'--output', '.',
2026-02-10 15:31:34 +01:00
'--secret', `id=GIT_AUTH_TOKEN.github.com,src=${tmpName}`,
2023-02-20 11:11:15 +01:00
'https://github.com/docker/build-push-action.git#refs/heads/master'
2025-03-28 11:16:09 +01:00
],
undefined
2020-10-21 02:46:41 +02:00
],
[
2021-11-16 05:19:44 +01:00
8,
2020-10-21 02:46:41 +02:00
'0.4.2',
new Map<string, string>([
2021-04-26 11:02:09 +02:00
['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'],
2020-10-21 02:46:41 +02:00
['tag', 'localhost:5000/name/app:latest'],
['platforms', 'linux/amd64,linux/arm64'],
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
2020-10-21 02:46:41 +02:00
['file', './test/Dockerfile'],
['builder', 'builder-git-context-2'],
2021-06-22 17:25:52 +02:00
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2020-10-21 02:46:41 +02:00
]),
[
'build',
2021-11-16 05:19:44 +01:00
'--file', './test/Dockerfile',
'--iidfile', imageIDFilePath,
2021-11-16 05:19:44 +01:00
'--platform', 'linux/amd64,linux/arm64',
2023-02-20 11:11:15 +01:00
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
2020-10-21 02:46:41 +02:00
'--builder', 'builder-git-context-2',
'--push',
2021-04-26 11:02:09 +02:00
'https://github.com/docker/build-push-action.git#refs/heads/master'
2025-03-28 11:16:09 +01:00
],
undefined
2020-11-17 21:38:45 +01:00
],
[
2021-11-16 05:19:44 +01:00
9,
2020-11-17 21:38:45 +01:00
'0.4.2',
new Map<string, string>([
2021-04-26 11:02:09 +02:00
['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'],
2020-11-17 21:38:45 +01:00
['tag', 'localhost:5000/name/app:latest'],
['platforms', 'linux/amd64,linux/arm64'],
['secrets', `GIT_AUTH_TOKEN=abcdefghi,jklmno=0123456789
"MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc"
FOO=bar
"EMPTYLINE=aaaa
bbbb
ccc"`],
['file', './test/Dockerfile'],
['builder', 'builder-git-context-2'],
2021-06-22 17:25:52 +02:00
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2020-11-17 21:38:45 +01:00
]),
[
'build',
2021-11-16 05:19:44 +01:00
'--file', './test/Dockerfile',
'--iidfile', imageIDFilePath,
2021-11-16 05:19:44 +01:00
'--platform', 'linux/amd64,linux/arm64',
2023-02-20 11:11:15 +01:00
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
'--secret', `id=MYSECRET,src=${tmpName}`,
'--secret', `id=FOO,src=${tmpName}`,
'--secret', `id=EMPTYLINE,src=${tmpName}`,
2020-11-17 21:38:45 +01:00
'--builder', 'builder-git-context-2',
'--push',
2021-04-26 11:02:09 +02:00
'https://github.com/docker/build-push-action.git#refs/heads/master'
2025-03-28 11:16:09 +01:00
],
undefined
2020-11-17 21:38:45 +01:00
],
[
2021-11-16 05:19:44 +01:00
10,
2020-11-17 21:38:45 +01:00
'0.4.2',
new Map<string, string>([
2021-04-26 11:02:09 +02:00
['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'],
2020-11-17 21:38:45 +01:00
['tag', 'localhost:5000/name/app:latest'],
['platforms', 'linux/amd64,linux/arm64'],
['secrets', `GIT_AUTH_TOKEN=abcdefghi,jklmno=0123456789
MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc
FOO=bar
EMPTYLINE=aaaa
bbbb
ccc`],
['file', './test/Dockerfile'],
['builder', 'builder-git-context-2'],
2021-06-22 17:25:52 +02:00
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2020-11-17 21:38:45 +01:00
]),
[
'build',
2021-11-16 05:19:44 +01:00
'--file', './test/Dockerfile',
'--iidfile', imageIDFilePath,
2021-11-16 05:19:44 +01:00
'--platform', 'linux/amd64,linux/arm64',
2023-02-20 11:11:15 +01:00
'--secret', `id=GIT_AUTH_TOKEN,src=${tmpName}`,
'--secret', `id=MYSECRET,src=${tmpName}`,
'--secret', `id=FOO,src=${tmpName}`,
'--secret', `id=EMPTYLINE,src=${tmpName}`,
2020-11-17 21:38:45 +01:00
'--builder', 'builder-git-context-2',
'--push',
2021-04-26 11:02:09 +02:00
'https://github.com/docker/build-push-action.git#refs/heads/master'
2025-03-28 11:16:09 +01:00
],
undefined
2021-02-15 10:08:19 +01:00
],
[
2021-11-16 05:19:44 +01:00
11,
2021-02-15 10:08:19 +01:00
'0.5.1',
new Map<string, string>([
2021-04-26 11:02:09 +02:00
['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'],
2021-02-15 10:08:19 +01:00
['tag', 'localhost:5000/name/app:latest'],
['secret-files', `MY_SECRET=${path.join(fixturesDir, 'secret.txt')}`],
2021-02-15 10:08:19 +01:00
['file', './test/Dockerfile'],
['builder', 'builder-git-context-2'],
2021-04-06 14:49:15 +02:00
['network', 'host'],
2021-06-22 17:25:52 +02:00
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2021-02-15 10:08:19 +01:00
]),
[
'build',
2021-11-16 05:19:44 +01:00
'--file', './test/Dockerfile',
'--iidfile', imageIDFilePath,
'--secret', `id=MY_SECRET,src=${path.join(fixturesDir, 'secret.txt')}`,
2021-02-15 10:08:19 +01:00
'--builder', 'builder-git-context-2',
2021-04-06 14:49:15 +02:00
'--network', 'host',
2021-02-15 10:08:19 +01:00
'--push',
2021-04-26 11:02:09 +02:00
'https://github.com/docker/build-push-action.git#refs/heads/master'
2025-03-28 11:16:09 +01:00
],
undefined
2021-05-23 02:41:02 +02:00
],
[
2021-11-16 05:19:44 +01:00
12,
2021-05-23 02:41:02 +02:00
'0.4.2',
new Map<string, string>([
['context', '.'],
['labels', 'org.opencontainers.image.title=filter_results_top_n\norg.opencontainers.image.description=Reference implementation of operation "filter results (top-n)"'],
2021-06-22 17:25:52 +02:00
['outputs', 'type=local,dest=./release-out'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2021-05-23 02:41:02 +02:00
]),
[
'build',
'--label', 'org.opencontainers.image.title=filter_results_top_n',
'--label', 'org.opencontainers.image.description=Reference implementation of operation "filter results (top-n)"',
'--output', 'type=local,dest=./release-out',
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2021-08-16 23:44:13 +02:00
],
[
2021-11-16 05:19:44 +01:00
13,
2021-08-16 23:44:13 +02:00
'0.6.0',
new Map<string, string>([
['context', '.'],
['tag', 'localhost:5000/name/app:latest'],
['file', './test/Dockerfile'],
2022-01-31 11:47:45 +01:00
['add-hosts', 'docker:10.180.0.1,foo:10.0.0.1'],
2021-08-16 23:44:13 +02:00
['network', 'host'],
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
2021-11-16 07:19:27 +01:00
['pull', 'false'],
2021-08-16 23:44:13 +02:00
]),
[
'build',
2022-01-31 11:47:45 +01:00
'--add-host', 'docker:10.180.0.1',
'--add-host', 'foo:10.0.0.1',
2021-11-16 05:19:44 +01:00
'--file', './test/Dockerfile',
'--iidfile', imageIDFilePath,
'--metadata-file', metadataJson,
2021-08-16 23:44:13 +02:00
'--network', 'host',
'--push',
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2021-08-16 23:44:13 +02:00
],
2021-11-16 07:19:27 +01:00
[
14,
'0.7.0',
new Map<string, string>([
['context', '.'],
['file', './test/Dockerfile'],
2022-01-31 11:47:45 +01:00
['add-hosts', 'docker:10.180.0.1\nfoo:10.0.0.1'],
2021-11-16 07:19:27 +01:00
['cgroup-parent', 'foo'],
['shm-size', '2g'],
['ulimit', `nofile=1024:1024
nproc=3`],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
2022-01-30 18:33:31 +01:00
'--add-host', 'docker:10.180.0.1',
2022-01-31 11:47:45 +01:00
'--add-host', 'foo:10.0.0.1',
2021-11-16 07:19:27 +01:00
'--cgroup-parent', 'foo',
'--file', './test/Dockerfile',
'--iidfile', imageIDFilePath,
2021-11-16 07:19:27 +01:00
'--shm-size', '2g',
'--ulimit', 'nofile=1024:1024',
'--ulimit', 'nproc=3',
'--metadata-file', metadataJson,
2021-11-16 07:19:27 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2021-11-16 07:19:27 +01:00
],
2021-12-28 00:49:32 +01:00
[
15,
'0.7.0',
new Map<string, string>([
['context', '{{defaultContext}}:docker'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--metadata-file', metadataJson,
2023-02-20 11:11:15 +01:00
'https://github.com/docker/build-push-action.git#refs/heads/master:docker'
2025-03-28 11:16:09 +01:00
],
undefined
2021-12-28 00:49:32 +01:00
],
[
16,
'0.8.2',
new Map<string, string>([
['github-token', 'abcdefghijklmno0123456789'],
['context', '{{defaultContext}}:subdir'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
2026-02-10 15:31:34 +01:00
'--secret', `id=GIT_AUTH_TOKEN.github.com,src=${tmpName}`,
'--metadata-file', metadataJson,
2023-02-20 11:11:15 +01:00
'https://github.com/docker/build-push-action.git#refs/heads/master:subdir'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-13 12:57:15 +01:00
],
[
17,
'0.8.2',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['provenance', 'true'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--metadata-file', metadataJson,
2023-01-13 12:57:15 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-13 12:57:15 +01:00
],
[
18,
'0.10.0',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--metadata-file', metadataJson,
2023-01-13 12:57:15 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-13 12:57:15 +01:00
],
[
19,
'0.10.0',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['provenance', 'true'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--metadata-file', metadataJson,
2023-01-13 12:57:15 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-13 12:57:15 +01:00
],
[
20,
'0.10.0',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['provenance', 'mode=max'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--metadata-file', metadataJson,
2023-01-13 12:57:15 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-13 12:57:15 +01:00
],
[
21,
'0.10.0',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['provenance', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', 'type=provenance,disabled=true',
'--metadata-file', metadataJson,
2023-01-13 12:57:15 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-13 12:57:15 +01:00
],
[
22,
'0.10.0',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['provenance', 'builder-id=foo'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', 'type=provenance,builder-id=foo',
'--metadata-file', metadataJson,
2023-01-13 12:57:15 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-13 12:57:15 +01:00
],
2023-01-27 14:06:06 +01:00
[
23,
'0.10.0',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['outputs', 'type=docker'],
]),
[
'build',
'--iidfile', imageIDFilePath,
2023-01-27 14:06:06 +01:00
"--output", 'type=docker',
'--metadata-file', metadataJson,
2023-01-27 14:06:06 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-27 14:06:06 +01:00
],
[
24,
'0.10.0',
new Map<string, string>([
['context', '.'],
['load', 'true'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
2023-06-13 10:52:03 +02:00
'--load',
'--metadata-file', metadataJson,
2023-06-13 10:52:03 +02:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-06-13 10:52:03 +02:00
],
[
25,
'0.10.0',
new Map<string, string>([
['context', '.'],
['build-args', `FOO=bar#baz`],
['load', 'true'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--build-arg', 'FOO=bar#baz',
'--iidfile', imageIDFilePath,
2023-09-26 16:34:10 +02:00
'--load',
'--metadata-file', metadataJson,
2023-09-26 16:34:10 +02:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-09-26 16:34:10 +02:00
],
[
26,
2023-09-26 16:34:10 +02:00
'0.10.0',
new Map<string, string>([
['context', '.'],
['no-cache', 'false'],
['load', 'true'],
['push', 'false'],
['pull', 'false'],
['secret-envs', `MY_SECRET=MY_SECRET_ENV
ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
]),
[
'build',
'--secret', 'id=MY_SECRET,env=MY_SECRET_ENV',
'--secret', 'id=ANOTHER_SECRET,env=ANOTHER_SECRET_ENV',
'--iidfile', imageIDFilePath,
2023-09-26 16:34:10 +02:00
'--load',
'--metadata-file', metadataJson,
2023-09-26 16:34:10 +02:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-09-26 16:34:10 +02:00
],
[
27,
2023-09-26 16:34:10 +02:00
'0.10.0',
new Map<string, string>([
['context', '.'],
['no-cache', 'false'],
['load', 'true'],
['push', 'false'],
['pull', 'false'],
['secret-envs', 'MY_SECRET=MY_SECRET_ENV,ANOTHER_SECRET=ANOTHER_SECRET_ENV']
]),
[
'build',
'--secret', 'id=MY_SECRET,env=MY_SECRET_ENV',
'--secret', 'id=ANOTHER_SECRET,env=ANOTHER_SECRET_ENV',
'--iidfile', imageIDFilePath,
2023-02-20 11:11:15 +01:00
'--load',
'--metadata-file', metadataJson,
2023-01-27 14:06:06 +01:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-01-27 14:06:06 +01:00
],
2023-10-24 07:23:44 +02:00
[
28,
2023-10-24 07:23:44 +02:00
'0.11.0',
new Map<string, string>([
['context', '.'],
['annotations', 'example1=www\nindex:example2=xxx\nmanifest:example3=yyy\nmanifest-descriptor[linux/amd64]:example4=zzz'],
['outputs', 'type=local,dest=./release-out'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'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/attempts/1`,
'--metadata-file', metadataJson,
2023-10-24 07:23:44 +02:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
2023-10-24 07:23:44 +02:00
],
[
29,
2023-10-24 07:23:44 +02:00
'0.12.0',
new Map<string, string>([
['context', '.'],
['annotations', 'example1=www\nindex:example2=xxx\nmanifest:example3=yyy\nmanifest-descriptor[linux/amd64]:example4=zzz'],
['outputs', 'type=local,dest=./release-out'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--annotation', 'example1=www',
'--annotation', 'index:example2=xxx',
'--annotation', 'manifest:example3=yyy',
'--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/attempts/1`,
'--metadata-file', metadataJson,
'.'
2025-03-28 11:16:09 +01:00
],
undefined
],
[
30,
'0.12.0',
new Map<string, string>([
['context', '.'],
['outputs', `type=image,"name=localhost:5000/name/app:latest,localhost:5000/name/app:foo",push-by-digest=true,name-canonical=true,push=true`],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--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/attempts/1`,
'--metadata-file', metadataJson,
2023-10-24 07:23:44 +02:00
'.'
2025-03-28 11:16:09 +01:00
],
undefined
],
[
31,
'0.13.1',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['provenance', 'mode=max'],
['sbom', 'true'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--attest', `type=sbom,disabled=false`,
'--metadata-file', metadataJson,
'.'
2025-03-28 11:16:09 +01:00
],
undefined
],
[
32,
'0.13.1',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['attests', 'type=provenance,mode=min'],
['provenance', 'mode=max'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=max,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--metadata-file', metadataJson,
'.'
2025-03-28 11:16:09 +01:00
],
undefined
],
[
33,
'0.13.1',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
['attests', 'type=provenance,mode=min'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=min,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--metadata-file', metadataJson,
'.'
2025-03-28 11:16:09 +01:00
],
undefined
],
[
34,
'0.13.1',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
]),
[
'build',
'--iidfile', imageIDFilePath,
'--metadata-file', metadataJson,
'.'
],
new Map<string, string>([
['BUILDX_NO_DEFAULT_ATTESTATIONS', '1']
])
],
2026-02-12 01:24:04 +01:00
[
35,
'0.13.1',
new Map<string, string>([
['github-token', 'abcdefghijklmno0123456789'],
['context', '{{defaultContext}}'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=http://10.0.0.5:22827/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--secret', `id=GIT_AUTH_TOKEN.10.0.0.5:22827,src=${tmpName}`,
'--metadata-file', metadataJson,
'http://10.0.0.5:22827/docker/build-push-action.git#refs/heads/master'
],
new Map<string, string>([
['GITHUB_SERVER_URL', 'http://10.0.0.5:22827'],
])
],
[
36,
'0.13.1',
new Map<string, string>([
['github-token', 'abcdefghijklmno0123456789'],
['context', '{{defaultContext}}'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=https://github.cds.internal.unity3d.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--secret', `id=GIT_AUTH_TOKEN.github.cds.internal.unity3d.com,src=${tmpName}`,
'--metadata-file', metadataJson,
'https://github.cds.internal.unity3d.com/docker/build-push-action.git#refs/heads/master'
],
new Map<string, string>([
['GITHUB_SERVER_URL', 'https://github.cds.internal.unity3d.com'],
])
],
[
37,
'0.29.0',
new Map<string, string>([
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--metadata-file', metadataJson,
'https://github.com/docker/build-push-action.git?ref=refs/heads/master'
],
new Map<string, string>([
['BUILDX_SEND_GIT_QUERY_AS_INPUT', 'true']
])
],
[
38,
'0.28.0',
new Map<string, string>([
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'build',
'--iidfile', imageIDFilePath,
'--attest', `type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--metadata-file', metadataJson,
'https://github.com/docker/build-push-action.git#refs/heads/master'
],
new Map<string, string>([
['BUILDX_SEND_GIT_QUERY_AS_INPUT', 'true']
])
],
])(
2026-02-28 16:32:47 +01:00
'[%d] given %o with %o as inputs, returns %o',
2025-03-28 11:16:09 +01:00
async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>, envs: Map<string, string> | undefined) => {
if (envs) {
envs.forEach((value: string, name: string) => {
process.env[name] = value;
});
}
2022-03-15 21:59:52 +01:00
inputs.forEach((value: string, name: string) => {
setInput(name, value);
});
2023-02-20 11:11:15 +01:00
const toolkit = new Toolkit();
2026-02-28 16:32:47 +01:00
vi.spyOn(Buildx.prototype, 'version').mockImplementation(async (): Promise<string> => {
2023-02-20 11:11:15 +01:00
return buildxVersion;
});
const context = await loadContextModule();
2023-04-17 01:32:21 +02:00
const inp = await context.getInputs();
2023-02-20 11:11:15 +01:00
const res = await context.getArgs(inp, toolkit);
expect(res).toEqual(expected);
}
);
});
2020-08-17 02:32:27 +02:00
2021-06-22 17:25:52 +02:00
// See: https://github.com/actions/toolkit/blob/a1b068ec31a042ff1e10a522d8fdf0b8869d53ca/packages/core/src/core.ts#L89
2020-08-17 02:32:27 +02:00
function getInputName(name: string): string {
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
}
function setInput(name: string, value: string): void {
process.env[getInputName(name)] = value;
}
async function loadContextModule(): Promise<typeof import('../src/context.js')> {
vi.resetModules();
return await import('../src/context.js');
}