Compare commits
10 Commits
v0.1.0-bet
...
v0.1.0-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e8f679709 | ||
|
|
f288f4f7ea | ||
|
|
cb9121174a | ||
|
|
464dfbe1ec | ||
|
|
5695c0049b | ||
|
|
44b1545abd | ||
|
|
4d9d62d542 | ||
|
|
aa3c8ef106 | ||
|
|
259abb56df | ||
|
|
76e5a25cff |
@@ -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
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export class Install {
|
|||||||
this.standalone = opts?.standalone ?? !Docker.isAvailable;
|
this.standalone = opts?.standalone ?? !Docker.isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async download(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, '');
|
||||||
|
|
||||||
@@ -59,13 +59,14 @@ export class Install {
|
|||||||
toolPath = await this.fetchBinary(fversion);
|
toolPath = await this.fetchBinary(fversion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dest = dest || (this.standalone ? this.context.tmpDir() : Docker.configDir);
|
||||||
if (this.standalone) {
|
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> {
|
public async build(gitContext: string, dest?: string): Promise<string> {
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
let [repo, ref] = gitContext.split('#');
|
let [repo, ref] = gitContext.split('#');
|
||||||
if (ref.length == 0) {
|
if (ref.length == 0) {
|
||||||
@@ -98,6 +99,7 @@ export class Install {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dest = dest || Docker.configDir;
|
||||||
if (this.standalone) {
|
if (this.standalone) {
|
||||||
return this.setStandalone(toolPath, dest);
|
return this.setStandalone(toolPath, dest);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
import {Context} from './context';
|
import {Context} from './context';
|
||||||
import {Buildx} from './buildx/buildx';
|
import {Buildx} from './buildx/buildx';
|
||||||
import {Install} from './buildx/install';
|
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';
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ export class Toolkit {
|
|||||||
public github: GitHub;
|
public github: GitHub;
|
||||||
public buildx: Buildx;
|
public buildx: Buildx;
|
||||||
public buildxInstall: Install;
|
public buildxInstall: Install;
|
||||||
|
public builder: Builder;
|
||||||
public buildkit: BuildKit;
|
public buildkit: BuildKit;
|
||||||
|
|
||||||
constructor(opts: ToolkitOpts = {}) {
|
constructor(opts: ToolkitOpts = {}) {
|
||||||
@@ -40,6 +42,7 @@ export class Toolkit {
|
|||||||
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.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