Improve stateHelper

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-08-12 23:10:28 +02:00
parent e53a3da260
commit c3b8f61f90
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
3 changed files with 19 additions and 27 deletions

View file

@ -28,8 +28,8 @@ async function run(): Promise<void> {
await exec.exec('docker', ['buildx', 'version'], false);
const builderName: string = `builder-${(await buildx.countBuilders()) + 1}-${process.env.GITHUB_JOB}`;
core.saveState('builderName', builderName);
core.setOutput('name', builderName);
stateHelper.setBuilderName(builderName);
core.info('🔨 Creating a new builder instance...');
let createArgs: Array<string> = ['buildx', 'create', '--name', builderName, '--driver', driver];
@ -66,11 +66,8 @@ async function cleanup(): Promise<void> {
}
}
// Main
if (!stateHelper.IsPost) {
run();
}
// Post
else {
} else {
cleanup();
}

View file

@ -1,14 +1,12 @@
// From https://github.com/actions/checkout/blob/master/src/state-helper.ts
import * as core from '@actions/core';
import * as coreCommand from '@actions/core/lib/command';
/**
* Indicates whether the POST action is running
*/
export const IsPost = !!process.env['STATE_isPost'];
export const builderName = !!process.env['STATE_builderName'];
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
// This is necessary since we don't have a separate entry point.
if (!IsPost) {
coreCommand.issueCommand('save-state', {name: 'isPost'}, 'true');
export function setBuilderName(builderName: string) {
core.saveState('builderName', builderName);
}
if (!IsPost) {
core.saveState('isPost', 'true');
}