dagger-for-github/src/context.ts
Gerhard Lazu 75549c92b9
Pin dagger CLI to v0.2 (#81)
Since we published https://github.com/dagger/dagger/releases/tag/v0.3.6
(Nov. 30, 2022), this action started downloading that version (i.e.
`latest`), which resulted in breakage, as described in the issue that
this fixes.

As soon as all tests pass and this gets the OK + merge, we should:
1. Cut a new release for this action (I am thinking v3.2.0)
2. Update the v3 tag to point to this new version

That should fix this for all existing GitHub Actions users without any
intervention on their part.

Fixes https://github.com/dagger/dagger-for-github/issues/80

Signed-off-by: Gerhard Lazu <gerhard@dagger.io>
2022-12-06 19:39:50 +00:00

50 lines
1.3 KiB
TypeScript

import fs from 'fs';
import * as os from 'os';
import path from 'path';
import * as core from '@actions/core';
let _tmpDir: string;
export function tmpDir(): string {
if (!_tmpDir) {
_tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'dagger-')).split(path.sep).join(path.posix.sep);
}
return _tmpDir;
}
export interface Inputs {
version: string;
workdir: string;
args: string;
installOnly: boolean;
cleanup: boolean;
cmds: string[];
}
export async function getInputs(): Promise<Inputs> {
return {
version: core.getInput('version') || '0.2',
workdir: core.getInput('workdir') || '.',
args: core.getInput('args'),
installOnly: core.getBooleanInput('install-only'),
cleanup: core.getBooleanInput('cleanup'),
cmds: await getInputList('cmds')
};
}
export async function getInputList(name: string, ignoreComma?: boolean): Promise<string[]> {
const items = core.getInput(name);
if (items == '') {
return [];
}
return items
.split(/\r?\n/)
.filter(x => x)
.reduce<string[]>((acc, line) => acc.concat(!ignoreComma ? line.split(',').filter(x => x) : line).map(pat => pat.trim()), []);
}
export const asyncForEach = async (array, callback) => {
for (const index in array) {
await callback(array[index], index, array);
}
};