-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
driver-opt as array of inputs (renamed driver-opts)
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
239 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import * as context from '../src/context'; | ||
|
||
describe('getInputList', () => { | ||
it('handles single line correctly', async () => { | ||
await setInput('foo', 'bar'); | ||
const res = await context.getInputList('foo'); | ||
console.log(res); | ||
expect(res).toEqual(['bar']); | ||
}); | ||
|
||
it('handles multiple lines correctly', async () => { | ||
setInput('foo', 'bar\nbaz'); | ||
const res = await context.getInputList('foo'); | ||
console.log(res); | ||
expect(res).toEqual(['bar', 'baz']); | ||
}); | ||
|
||
it('handles comma correctly', async () => { | ||
setInput('foo', 'bar,baz'); | ||
const res = await context.getInputList('foo'); | ||
console.log(res); | ||
expect(res).toEqual(['bar', 'baz']); | ||
}); | ||
|
||
it('handles different new lines correctly', async () => { | ||
setInput('foo', 'bar\r\nbaz'); | ||
const res = await context.getInputList('foo'); | ||
console.log(res); | ||
expect(res).toEqual(['bar', 'baz']); | ||
}); | ||
|
||
it('handles different new lines and comma correctly', async () => { | ||
setInput('foo', 'bar\r\nbaz,bat'); | ||
const res = await context.getInputList('foo'); | ||
console.log(res); | ||
expect(res).toEqual(['bar', 'baz', 'bat']); | ||
}); | ||
|
||
it('handles multiple lines and ignoring comma correctly', async () => { | ||
setInput('driver-opts', 'image=moby/buildkit:master\nnetwork=host'); | ||
const res = await context.getInputList('driver-opts', true); | ||
console.log(res); | ||
expect(res).toEqual(['image=moby/buildkit:master', 'network=host']); | ||
}); | ||
|
||
it('handles different new lines and ignoring comma correctly', async () => { | ||
setInput('driver-opts', 'image=moby/buildkit:master\r\nnetwork=host'); | ||
const res = await context.getInputList('driver-opts', true); | ||
console.log(res); | ||
expect(res).toEqual(['image=moby/buildkit:master', 'network=host']); | ||
}); | ||
}); | ||
|
||
describe('asyncForEach', () => { | ||
it('executes async tasks sequentially', async () => { | ||
const testValues = [1, 2, 3, 4, 5]; | ||
const results: number[] = []; | ||
|
||
await context.asyncForEach(testValues, async value => { | ||
results.push(value); | ||
}); | ||
|
||
expect(results).toEqual(testValues); | ||
}); | ||
}); | ||
|
||
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67 | ||
function getInputName(name: string): string { | ||
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; | ||
} | ||
|
||
function setInput(name: string, value: string): void { | ||
process.env[getInputName(name)] = value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as os from 'os'; | ||
import * as core from '@actions/core'; | ||
|
||
export const osPlat: string = os.platform(); | ||
|
||
export interface Inputs { | ||
version: string; | ||
driver: string; | ||
driverOpts: string[]; | ||
buildkitdFlags: string; | ||
install: boolean; | ||
use: boolean; | ||
} | ||
|
||
export async function getInputs(): Promise<Inputs> { | ||
return { | ||
version: core.getInput('version'), | ||
driver: core.getInput('driver') || 'docker-container', | ||
driverOpts: await getInputList('driver-opts', true), | ||
buildkitdFlags: core.getInput('buildkitd-flags'), | ||
install: /true/i.test(core.getInput('install')), | ||
use: /true/i.test(core.getInput('use')) | ||
}; | ||
} | ||
|
||
export async function getInputList(name: string, ignoreComma?: boolean): Promise<string[]> { | ||
const items = core.getInput(name); | ||
if (items == '') { | ||
return []; | ||
} | ||
return items | ||
.split(/\r?\n/) | ||
.reduce<string[]>((acc, line) => acc.concat(!ignoreComma ? line.split(',') : line).map(pat => pat.trim()), []); | ||
} | ||
|
||
export const asyncForEach = async (array, callback) => { | ||
for (let index = 0; index < array.length; index++) { | ||
await callback(array[index], index, array); | ||
} | ||
}; |
Oops, something went wrong.