2020-12-24 04:13:41 +01:00
|
|
|
import * as fs from 'fs';
|
2022-10-12 07:07:13 +02:00
|
|
|
import {getInputs, Inputs} from './context';
|
2020-10-25 02:25:23 +01:00
|
|
|
import * as github from './github';
|
2020-10-26 01:39:21 +01:00
|
|
|
import {Meta, Version} from './meta';
|
2020-10-25 02:25:23 +01:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import {Context} from '@actions/github/lib/context';
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
try {
|
|
|
|
const inputs: Inputs = await getInputs();
|
|
|
|
if (inputs.images.length == 0) {
|
|
|
|
throw new Error(`images input required`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const context: Context = github.context();
|
2021-05-25 02:07:25 +02:00
|
|
|
const repo: github.ReposGetResponseData = await github.repo(inputs.githubToken);
|
2020-10-25 02:25:23 +01:00
|
|
|
core.startGroup(`Context info`);
|
|
|
|
core.info(`eventName: ${context.eventName}`);
|
|
|
|
core.info(`sha: ${context.sha}`);
|
|
|
|
core.info(`ref: ${context.ref}`);
|
|
|
|
core.info(`workflow: ${context.workflow}`);
|
|
|
|
core.info(`action: ${context.action}`);
|
|
|
|
core.info(`actor: ${context.actor}`);
|
|
|
|
core.info(`runNumber: ${context.runNumber}`);
|
|
|
|
core.info(`runId: ${context.runId}`);
|
|
|
|
core.endGroup();
|
|
|
|
|
2022-04-25 13:42:22 +02:00
|
|
|
if (core.isDebug()) {
|
|
|
|
core.startGroup(`Webhook payload`);
|
|
|
|
core.info(JSON.stringify(context.payload, null, 2));
|
|
|
|
core.endGroup();
|
|
|
|
}
|
|
|
|
|
2020-10-25 02:25:23 +01:00
|
|
|
const meta: Meta = new Meta(inputs, context, repo);
|
|
|
|
|
2020-12-01 05:38:08 +01:00
|
|
|
const version: Version = meta.version;
|
2021-03-29 13:04:53 +02:00
|
|
|
if (meta.version.main == undefined || meta.version.main.length == 0) {
|
|
|
|
core.warning(`No Docker image version has been generated. Check tags input.`);
|
|
|
|
} else {
|
|
|
|
core.startGroup(`Docker image version`);
|
|
|
|
core.info(version.main || '');
|
|
|
|
core.endGroup();
|
|
|
|
}
|
2022-10-12 07:07:13 +02:00
|
|
|
core.setOutput('version', version.main || '');
|
2020-10-25 02:40:42 +01:00
|
|
|
|
2020-12-24 04:13:41 +01:00
|
|
|
// Docker tags
|
2021-03-29 13:04:53 +02:00
|
|
|
const tags: Array<string> = meta.getTags();
|
|
|
|
if (tags.length == 0) {
|
|
|
|
core.warning('No Docker tag has been generated. Check tags input.');
|
|
|
|
} else {
|
|
|
|
core.startGroup(`Docker tags`);
|
2022-03-22 21:09:00 +01:00
|
|
|
for (const tag of tags) {
|
2021-03-29 13:04:53 +02:00
|
|
|
core.info(tag);
|
|
|
|
}
|
|
|
|
core.endGroup();
|
2020-10-25 03:21:46 +01:00
|
|
|
}
|
2022-10-12 07:07:13 +02:00
|
|
|
core.setOutput('tags', tags.join(inputs.sepTags));
|
2020-10-25 02:25:23 +01:00
|
|
|
|
2020-12-24 04:13:41 +01:00
|
|
|
// Docker labels
|
2021-03-29 13:04:53 +02:00
|
|
|
const labels: Array<string> = meta.getLabels();
|
2020-10-25 02:40:42 +01:00
|
|
|
core.startGroup(`Docker labels`);
|
2022-03-22 21:09:00 +01:00
|
|
|
for (const label of labels) {
|
2020-10-25 03:21:46 +01:00
|
|
|
core.info(label);
|
|
|
|
}
|
2020-10-25 02:25:23 +01:00
|
|
|
core.endGroup();
|
2022-10-12 07:07:13 +02:00
|
|
|
core.setOutput('labels', labels.join(inputs.sepLabels));
|
2020-12-24 04:13:41 +01:00
|
|
|
|
2021-05-22 21:23:06 +02:00
|
|
|
// JSON
|
|
|
|
const jsonOutput = meta.getJSON();
|
|
|
|
core.startGroup(`JSON output`);
|
|
|
|
core.info(JSON.stringify(jsonOutput, null, 2));
|
|
|
|
core.endGroup();
|
2022-10-12 07:07:13 +02:00
|
|
|
core.setOutput('json', jsonOutput);
|
2021-05-22 21:23:06 +02:00
|
|
|
|
2022-10-08 02:07:41 +02:00
|
|
|
// Bake file definition
|
2021-03-29 13:04:53 +02:00
|
|
|
const bakeFile: string = meta.getBakeFile();
|
2022-10-08 02:07:41 +02:00
|
|
|
core.startGroup(`Bake file definition`);
|
2020-12-24 04:13:41 +01:00
|
|
|
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
|
|
|
core.endGroup();
|
2022-10-12 07:07:13 +02:00
|
|
|
core.setOutput('bake-file', bakeFile);
|
2020-10-25 02:25:23 +01:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run();
|