Check context type

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-08-16 19:13:19 +02:00
parent 10b9d7ec22
commit 9c473659de
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
6 changed files with 835 additions and 4 deletions

View file

@ -1,3 +1,4 @@
import gitUrlParse from 'git-url-parse';
import * as core from '@actions/core';
export interface Inputs {
@ -24,7 +25,7 @@ export interface Inputs {
export async function getInputs(): Promise<Inputs> {
return {
context: core.getInput('context') || '.',
context: await getBuildContext(),
file: core.getInput('file') || './Dockerfile',
buildArgs: await getInputList('build-args'),
labels: await getInputList('labels'),
@ -65,6 +66,21 @@ export async function getArgs(inputs: Inputs): Promise<Array<string>> {
return args;
}
async function getBuildContext(): Promise<string> {
let context: string = core.getInput('context');
if (!context) {
return '.';
}
try {
const gitURL = gitUrlParse(context);
gitURL.token = gitURL.token || process.env['GIT_TOKEN'] || process.env['GITHUB_TOKEN'] || '';
gitURL.ref = gitURL.ref || process.env['GIT_REF'] || process.env['GITHUB_REF'] || '';
return gitURL.toString();
} catch {
return context;
}
}
async function getCommonArgs(inputs: Inputs): Promise<Array<string>> {
let args: Array<string> = [];
if (inputs.noCache) {