Skip to content

Commit

Permalink
Improve stateHelper
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
CrazyMax committed Aug 12, 2020
1 parent e53a3da commit c3b8f61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
21 changes: 9 additions & 12 deletions setup-buildx/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions setup-buildx/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -66,11 +66,8 @@ async function cleanup(): Promise<void> {
}
}

// Main
if (!stateHelper.IsPost) {
run();
}
// Post
else {
} else {
cleanup();
}
16 changes: 7 additions & 9 deletions setup-buildx/src/state-helper.ts
Original file line number Diff line number Diff line change
@@ -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'];

export function setBuilderName(builderName: string) {
core.saveState('builderName', 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');
core.saveState('isPost', 'true');
}

0 comments on commit c3b8f61

Please sign in to comment.