Compare commits
19 Commits
v0.1.0-bet
...
v0.1.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e8f679709 | ||
|
|
f288f4f7ea | ||
|
|
cb9121174a | ||
|
|
464dfbe1ec | ||
|
|
5695c0049b | ||
|
|
44b1545abd | ||
|
|
4d9d62d542 | ||
|
|
aa3c8ef106 | ||
|
|
259abb56df | ||
|
|
76e5a25cff | ||
|
|
bb8a659d9e | ||
|
|
6ab0483b34 | ||
|
|
d7dbf54456 | ||
|
|
496d7e2c9d | ||
|
|
094239d9eb | ||
|
|
c8a13a2352 | ||
|
|
875c6c9e95 | ||
|
|
12e3bd7469 | ||
|
|
2abe456e6b |
@@ -14,31 +14,36 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, it, jest, test, beforeEach} from '@jest/globals';
|
import {describe, expect, it, jest, test, beforeEach, afterEach} from '@jest/globals';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as rimraf from 'rimraf';
|
||||||
import osm = require('os');
|
import osm = require('os');
|
||||||
|
|
||||||
import {Install} from '../../src/buildx/install';
|
import {Install} from '../../src/buildx/install';
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest').split(path.sep).join(path.posix.sep);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('install', () => {
|
afterEach(function () {
|
||||||
// prettier-ignore
|
rimraf.sync(tmpDir);
|
||||||
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-install-jest').split(path.sep).join(path.posix.sep);
|
});
|
||||||
|
|
||||||
|
describe('download', () => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
test.each([
|
test.each([
|
||||||
['v0.4.1', false],
|
['v0.9.1', false],
|
||||||
['latest', false],
|
['latest', false],
|
||||||
['v0.4.1', true],
|
['v0.9.1', true],
|
||||||
['latest', true]
|
['latest', true]
|
||||||
])(
|
])(
|
||||||
'acquires %p of buildx (standalone: %p)', async (version, standalone) => {
|
'acquires %p of buildx (standalone: %p)', async (version, standalone) => {
|
||||||
const install = new Install({standalone: standalone});
|
const install = new Install({standalone: standalone});
|
||||||
const buildxBin = await install.install(version, tmpDir);
|
const buildxBin = await install.download(version, tmpDir);
|
||||||
expect(fs.existsSync(buildxBin)).toBe(true);
|
expect(fs.existsSync(buildxBin)).toBe(true);
|
||||||
},
|
},
|
||||||
100000
|
100000
|
||||||
@@ -60,7 +65,7 @@ describe('install', () => {
|
|||||||
jest.spyOn(osm, 'platform').mockImplementation(() => os);
|
jest.spyOn(osm, 'platform').mockImplementation(() => os);
|
||||||
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
|
jest.spyOn(osm, 'arch').mockImplementation(() => arch);
|
||||||
const install = new Install();
|
const install = new Install();
|
||||||
const buildxBin = await install.install('latest', tmpDir);
|
const buildxBin = await install.download('latest', tmpDir);
|
||||||
expect(fs.existsSync(buildxBin)).toBe(true);
|
expect(fs.existsSync(buildxBin)).toBe(true);
|
||||||
},
|
},
|
||||||
100000
|
100000
|
||||||
@@ -73,6 +78,22 @@ describe('install', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('build', () => {
|
||||||
|
// eslint-disable-next-line jest/no-disabled-tests
|
||||||
|
it.skip('builds refs/pull/648/head', async () => {
|
||||||
|
const install = new Install();
|
||||||
|
const buildxBin = await install.build('https://github.com/docker/buildx.git#refs/pull/648/head', tmpDir);
|
||||||
|
expect(fs.existsSync(buildxBin)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
// eslint-disable-next-line jest/no-disabled-tests
|
||||||
|
it.skip('builds 67bd6f4dc82a9cd96f34133dab3f6f7af803bb14', async () => {
|
||||||
|
const install = new Install();
|
||||||
|
const buildxBin = await install.build('https://github.com/docker/buildx.git#67bd6f4dc82a9cd96f34133dab3f6f7af803bb14', tmpDir);
|
||||||
|
expect(fs.existsSync(buildxBin)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
});
|
||||||
|
|
||||||
describe('getRelease', () => {
|
describe('getRelease', () => {
|
||||||
it('returns latest buildx GitHub release', async () => {
|
it('returns latest buildx GitHub release', async () => {
|
||||||
const release = await Install.getRelease('latest');
|
const release = await Install.getRelease('latest');
|
||||||
|
|||||||
@@ -69,16 +69,28 @@ describe('getInputList', () => {
|
|||||||
|
|
||||||
it('multiline and ignoring comma correctly', async () => {
|
it('multiline and ignoring comma correctly', async () => {
|
||||||
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
|
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
|
||||||
const res = Util.getInputList('cache-from', true);
|
const res = Util.getInputList('cache-from', {ignoreComma: true});
|
||||||
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('different new lines and ignoring comma correctly', async () => {
|
it('different new lines and ignoring comma correctly', async () => {
|
||||||
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
|
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
|
||||||
const res = Util.getInputList('cache-from', true);
|
const res = Util.getInputList('cache-from', {ignoreComma: true});
|
||||||
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('do not escape surrounding quotes', async () => {
|
||||||
|
setInput('driver-opts', `"env.no_proxy=localhost,127.0.0.1,.mydomain"`);
|
||||||
|
const res = Util.getInputList('driver-opts', {ignoreComma: true, quote: false});
|
||||||
|
expect(res).toEqual(['"env.no_proxy=localhost,127.0.0.1,.mydomain"']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('escape surrounding quotes', async () => {
|
||||||
|
setInput('platforms', 'linux/amd64\n"linux/arm64,linux/arm/v7"');
|
||||||
|
const res = Util.getInputList('platforms');
|
||||||
|
expect(res).toEqual(['linux/amd64', 'linux/arm64', 'linux/arm/v7']);
|
||||||
|
});
|
||||||
|
|
||||||
it('multiline values', async () => {
|
it('multiline values', async () => {
|
||||||
setInput(
|
setInput(
|
||||||
'secrets',
|
'secrets',
|
||||||
@@ -88,7 +100,7 @@ bbbbbbb
|
|||||||
ccccccccc"
|
ccccccccc"
|
||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = Util.getInputList('secrets', true);
|
const res = Util.getInputList('secrets', {ignoreComma: true});
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
@@ -111,7 +123,7 @@ FOO=bar
|
|||||||
bbbb
|
bbbb
|
||||||
ccc"`
|
ccc"`
|
||||||
);
|
);
|
||||||
const res = Util.getInputList('secrets', true);
|
const res = Util.getInputList('secrets', {ignoreComma: true});
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
@@ -134,7 +146,7 @@ bbbbbbb
|
|||||||
ccccccccc
|
ccccccccc
|
||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = Util.getInputList('secrets', true);
|
const res = Util.getInputList('secrets', {ignoreComma: true});
|
||||||
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -145,7 +157,7 @@ FOO=bar`
|
|||||||
`"GPG_KEY=${pgp}"
|
`"GPG_KEY=${pgp}"
|
||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = Util.getInputList('secrets', true);
|
const res = Util.getInputList('secrets', {ignoreComma: true});
|
||||||
expect(res).toEqual([`GPG_KEY=${pgp}`, 'FOO=bar']);
|
expect(res).toEqual([`GPG_KEY=${pgp}`, 'FOO=bar']);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -158,7 +170,7 @@ bbbb""bbb
|
|||||||
ccccccccc"
|
ccccccccc"
|
||||||
FOO=bar`
|
FOO=bar`
|
||||||
);
|
);
|
||||||
const res = Util.getInputList('secrets', true);
|
const res = Util.getInputList('secrets', {ignoreComma: true});
|
||||||
expect(res).toEqual([
|
expect(res).toEqual([
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
||||||
`MYSECRET=aaaaaaaa
|
`MYSECRET=aaaaaaaa
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@docker/actions-toolkit",
|
"name": "@docker/actions-toolkit",
|
||||||
|
"version": "0.0.0+unknown",
|
||||||
"description": "Toolkit for Docker (GitHub) Actions",
|
"description": "Toolkit for Docker (GitHub) Actions",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import * as semver from 'semver';
|
|||||||
import {Docker} from '../docker';
|
import {Docker} from '../docker';
|
||||||
import {Context} from '../context';
|
import {Context} from '../context';
|
||||||
import {Inputs} from './inputs';
|
import {Inputs} from './inputs';
|
||||||
import {Install} from './install';
|
|
||||||
|
|
||||||
import {Cert} from '../types/buildx';
|
import {Cert} from '../types/buildx';
|
||||||
|
|
||||||
@@ -36,13 +35,11 @@ export class Buildx {
|
|||||||
private _version: string | undefined;
|
private _version: string | undefined;
|
||||||
|
|
||||||
public readonly inputs: Inputs;
|
public readonly inputs: Inputs;
|
||||||
public readonly install: Install;
|
|
||||||
public readonly standalone: boolean;
|
public readonly standalone: boolean;
|
||||||
|
|
||||||
constructor(opts: BuildxOpts) {
|
constructor(opts: BuildxOpts) {
|
||||||
this.context = opts.context;
|
this.context = opts.context;
|
||||||
this.inputs = new Inputs(this.context);
|
this.inputs = new Inputs(this.context);
|
||||||
this.install = new Install({standalone: opts.standalone});
|
|
||||||
this.standalone = opts?.standalone ?? !Docker.isAvailable;
|
this.standalone = opts?.standalone ?? !Docker.isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,27 +18,37 @@ import fs from 'fs';
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
import * as httpm from '@actions/http-client';
|
import * as httpm from '@actions/http-client';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
|
|
||||||
|
import {Buildx} from './buildx';
|
||||||
|
import {Context} from '../context';
|
||||||
|
import {Docker} from '../docker';
|
||||||
|
import {Git} from '../git';
|
||||||
|
|
||||||
import {GitHubRelease} from '../types/github';
|
import {GitHubRelease} from '../types/github';
|
||||||
|
|
||||||
export interface InstallOpts {
|
export interface InstallOpts {
|
||||||
|
context?: Context;
|
||||||
standalone?: boolean;
|
standalone?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Install {
|
export class Install {
|
||||||
private readonly opts: InstallOpts;
|
private readonly context: Context;
|
||||||
|
private readonly standalone: boolean;
|
||||||
|
|
||||||
constructor(opts?: InstallOpts) {
|
constructor(opts?: InstallOpts) {
|
||||||
this.opts = opts || {};
|
this.context = opts?.context || new Context();
|
||||||
|
this.standalone = opts?.standalone ?? !Docker.isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async install(version: string, dest: string): Promise<string> {
|
public async download(version: string, dest?: string): Promise<string> {
|
||||||
const release: GitHubRelease = await Install.getRelease(version);
|
const release: GitHubRelease = await Install.getRelease(version);
|
||||||
const fversion = release.tag_name.replace(/^v+|v+$/g, '');
|
const fversion = release.tag_name.replace(/^v+|v+$/g, '');
|
||||||
|
|
||||||
let toolPath: string;
|
let toolPath: string;
|
||||||
toolPath = tc.find('buildx', fversion, this.platform());
|
toolPath = tc.find('buildx', fversion, this.platform());
|
||||||
if (!toolPath) {
|
if (!toolPath) {
|
||||||
@@ -46,14 +56,87 @@ export class Install {
|
|||||||
if (!semver.valid(c)) {
|
if (!semver.valid(c)) {
|
||||||
throw new Error(`Invalid Buildx version "${fversion}".`);
|
throw new Error(`Invalid Buildx version "${fversion}".`);
|
||||||
}
|
}
|
||||||
toolPath = await this.download(fversion);
|
toolPath = await this.fetchBinary(fversion);
|
||||||
}
|
}
|
||||||
if (this.opts.standalone) {
|
|
||||||
|
dest = dest || (this.standalone ? this.context.tmpDir() : Docker.configDir);
|
||||||
|
if (this.standalone) {
|
||||||
return this.setStandalone(toolPath, dest);
|
return this.setStandalone(toolPath, dest);
|
||||||
}
|
}
|
||||||
return this.setPlugin(toolPath, dest);
|
return this.setPlugin(toolPath, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async build(gitContext: string, dest?: string): Promise<string> {
|
||||||
|
// eslint-disable-next-line prefer-const
|
||||||
|
let [repo, ref] = gitContext.split('#');
|
||||||
|
if (ref.length == 0) {
|
||||||
|
ref = 'master';
|
||||||
|
}
|
||||||
|
|
||||||
|
let vspec: string;
|
||||||
|
// TODO: include full ref as fingerprint. Use commit sha as best-effort in the meantime.
|
||||||
|
if (ref.match(/^[0-9a-fA-F]{40}$/)) {
|
||||||
|
vspec = ref;
|
||||||
|
} else {
|
||||||
|
vspec = await Git.getRemoteSha(repo, ref);
|
||||||
|
}
|
||||||
|
core.debug(`Tool version spec ${vspec}`);
|
||||||
|
|
||||||
|
let toolPath: string;
|
||||||
|
toolPath = tc.find('buildx', vspec);
|
||||||
|
if (!toolPath) {
|
||||||
|
const outputDir = path.join(this.context.tmpDir(), 'build-cache').split(path.sep).join(path.posix.sep);
|
||||||
|
const buildCmd = await this.buildCommand(gitContext, outputDir);
|
||||||
|
toolPath = await exec
|
||||||
|
.getExecOutput(buildCmd.command, buildCmd.args, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
core.warning(res.stderr.trim());
|
||||||
|
}
|
||||||
|
return tc.cacheFile(`${outputDir}/buildx`, os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx', 'buildx', vspec);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
dest = dest || Docker.configDir;
|
||||||
|
if (this.standalone) {
|
||||||
|
return this.setStandalone(toolPath, dest);
|
||||||
|
}
|
||||||
|
return this.setPlugin(toolPath, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async buildCommand(gitContext: string, outputDir: string): Promise<{args: Array<string>; command: string}> {
|
||||||
|
const buildxStandaloneFound = await new Buildx({context: this.context, standalone: true}).isAvailable();
|
||||||
|
const buildxPluginFound = await new Buildx({context: this.context, standalone: false}).isAvailable();
|
||||||
|
|
||||||
|
let buildStandalone = false;
|
||||||
|
if (this.standalone && buildxStandaloneFound) {
|
||||||
|
core.debug(`Buildx standalone found, build with it`);
|
||||||
|
buildStandalone = true;
|
||||||
|
} else if (!this.standalone && buildxPluginFound) {
|
||||||
|
core.debug(`Buildx plugin found, build with it`);
|
||||||
|
buildStandalone = false;
|
||||||
|
} else if (buildxStandaloneFound) {
|
||||||
|
core.debug(`Buildx plugin not found, but standalone found so trying to build with it`);
|
||||||
|
buildStandalone = true;
|
||||||
|
} else if (buildxPluginFound) {
|
||||||
|
core.debug(`Buildx standalone not found, but plugin found so trying to build with it`);
|
||||||
|
buildStandalone = false;
|
||||||
|
} else {
|
||||||
|
throw new Error(`Neither buildx standalone or plugin have been found to build from ref ${gitContext}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
//prettier-ignore
|
||||||
|
return new Buildx({context: this.context, standalone: buildStandalone}).getCommand([
|
||||||
|
'build',
|
||||||
|
'--target', 'binaries',
|
||||||
|
'--build-arg', 'BUILDKIT_CONTEXT_KEEP_GIT_DIR=1',
|
||||||
|
'--output', `type=local,dest=${outputDir}`,
|
||||||
|
gitContext
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
private async setStandalone(toolPath: string, dest: string): Promise<string> {
|
private async setStandalone(toolPath: string, dest: string): Promise<string> {
|
||||||
const toolBinPath = path.join(toolPath, os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx');
|
const toolBinPath = path.join(toolPath, os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx');
|
||||||
const binDir = path.join(dest, 'bin');
|
const binDir = path.join(dest, 'bin');
|
||||||
@@ -81,7 +164,7 @@ export class Install {
|
|||||||
return pluginPath;
|
return pluginPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async download(version: string): Promise<string> {
|
private async fetchBinary(version: string): Promise<string> {
|
||||||
const targetFile: string = os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx';
|
const targetFile: string = os.platform() == 'win32' ? 'docker-buildx.exe' : 'docker-buildx';
|
||||||
const downloadURL = util.format('https://github.com/docker/buildx/releases/download/v%s/%s', version, this.filename(version));
|
const downloadURL = util.format('https://github.com/docker/buildx/releases/download/v%s/%s', version, this.filename(version));
|
||||||
const downloadPath = await tc.downloadTool(downloadURL);
|
const downloadPath = await tc.downloadTool(downloadURL);
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
import {Context} from './context';
|
import {Context} from './context';
|
||||||
import {Buildx} from './buildx/buildx';
|
import {Buildx} from './buildx/buildx';
|
||||||
|
import {Install} from './buildx/install';
|
||||||
|
import {Builder} from './buildx/builder';
|
||||||
import {BuildKit} from './buildkit/buildkit';
|
import {BuildKit} from './buildkit/buildkit';
|
||||||
import {GitHub} from './github';
|
import {GitHub} from './github';
|
||||||
|
|
||||||
@@ -31,12 +33,16 @@ export class Toolkit {
|
|||||||
public context: Context;
|
public context: Context;
|
||||||
public github: GitHub;
|
public github: GitHub;
|
||||||
public buildx: Buildx;
|
public buildx: Buildx;
|
||||||
|
public buildxInstall: Install;
|
||||||
|
public builder: Builder;
|
||||||
public buildkit: BuildKit;
|
public buildkit: BuildKit;
|
||||||
|
|
||||||
constructor(opts: ToolkitOpts = {}) {
|
constructor(opts: ToolkitOpts = {}) {
|
||||||
this.context = new Context();
|
this.context = new Context();
|
||||||
this.github = new GitHub({token: opts.githubToken});
|
this.github = new GitHub({token: opts.githubToken});
|
||||||
this.buildx = new Buildx({context: this.context});
|
this.buildx = new Buildx({context: this.context});
|
||||||
|
this.buildxInstall = new Install({context: this.context, standalone: this.buildx.standalone});
|
||||||
|
this.builder = new Builder({context: this.context, buildx: this.buildx});
|
||||||
this.buildkit = new BuildKit({context: this.context, buildx: this.buildx});
|
this.buildkit = new BuildKit({context: this.context, buildx: this.buildx});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,3 +30,11 @@ export interface NodeInfo {
|
|||||||
buildkitVersion?: string;
|
buildkitVersion?: string;
|
||||||
platforms?: string;
|
platforms?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Node {
|
||||||
|
name?: string;
|
||||||
|
endpoint?: string;
|
||||||
|
'driver-opts'?: Array<string>;
|
||||||
|
'buildkitd-flags'?: string;
|
||||||
|
platforms?: string;
|
||||||
|
}
|
||||||
|
|||||||
23
src/util.ts
23
src/util.ts
@@ -17,8 +17,13 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {parse} from 'csv-parse/sync';
|
import {parse} from 'csv-parse/sync';
|
||||||
|
|
||||||
|
export interface InputListOpts {
|
||||||
|
ignoreComma?: boolean;
|
||||||
|
quote?: string | boolean | Buffer | null;
|
||||||
|
}
|
||||||
|
|
||||||
export class Util {
|
export class Util {
|
||||||
public static getInputList(name: string, ignoreComma?: boolean): string[] {
|
public static getInputList(name: string, opts?: InputListOpts): string[] {
|
||||||
const res: Array<string> = [];
|
const res: Array<string> = [];
|
||||||
|
|
||||||
const items = core.getInput(name);
|
const items = core.getInput(name);
|
||||||
@@ -31,18 +36,22 @@ export class Util {
|
|||||||
relaxQuotes: true,
|
relaxQuotes: true,
|
||||||
comment: '#',
|
comment: '#',
|
||||||
relaxColumnCount: true,
|
relaxColumnCount: true,
|
||||||
skipEmptyLines: true
|
skipEmptyLines: true,
|
||||||
|
quote: opts?.quote
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const record of records as Array<string[]>) {
|
for (const record of records as Array<string[]>) {
|
||||||
if (record.length == 1) {
|
if (record.length == 1) {
|
||||||
res.push(record[0]);
|
if (opts?.ignoreComma) {
|
||||||
continue;
|
res.push(record[0]);
|
||||||
} else if (!ignoreComma) {
|
} else {
|
||||||
|
res.push(...record[0].split(','));
|
||||||
|
}
|
||||||
|
} else if (!opts?.ignoreComma) {
|
||||||
res.push(...record);
|
res.push(...record);
|
||||||
continue;
|
} else {
|
||||||
|
res.push(record.join(','));
|
||||||
}
|
}
|
||||||
res.push(record.join(','));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.filter(item => item).map(pat => pat.trim());
|
return res.filter(item => item).map(pat => pat.trim());
|
||||||
|
|||||||
Reference in New Issue
Block a user