tear down post step

This commit is contained in:
CrazyMax 2023-03-02 15:03:14 +01:00
parent 611b62c8d7
commit f2c84c46da
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
5 changed files with 33 additions and 5 deletions

View File

@ -14,3 +14,4 @@ inputs:
runs: runs:
using: 'node16' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'
post: 'dist/index.js'

View File

@ -28,7 +28,8 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@docker/actions-toolkit": "link:../../docker_org/actions/docker-actions-toolkit" "@docker/actions-toolkit": "link:../../docker_org/actions/docker-actions-toolkit",
"uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^16.11.26", "@types/node": "^16.11.26",

View File

@ -1,17 +1,21 @@
import * as context from './context'; import os from 'os';
import path from 'path';
import * as uuid from 'uuid';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as actionsToolkit from '@docker/actions-toolkit'; import * as actionsToolkit from '@docker/actions-toolkit';
import {Install} from '../../../docker_org/actions/docker-actions-toolkit/lib/docker/install'; import {Install} from '../../../docker_org/actions/docker-actions-toolkit/lib/docker/install';
import {Context} from '../../../docker_org/actions/docker-actions-toolkit/lib/context';
import {Docker} from '../../../docker_org/actions/docker-actions-toolkit/lib/docker/docker'; import {Docker} from '../../../docker_org/actions/docker-actions-toolkit/lib/docker/docker';
import * as context from './context';
import * as stateHelper from './state-helper';
actionsToolkit.run( actionsToolkit.run(
// main // main
async () => { async () => {
const input: context.Inputs = context.getInputs(); const input: context.Inputs = context.getInputs();
const install = new Install();
const install = new Install();
let toolDir; let toolDir;
if (!(await Docker.isAvailable()) || input.version) { if (!(await Docker.isAvailable()) || input.version) {
await core.group(`Download docker`, async () => { await core.group(`Download docker`, async () => {
@ -19,12 +23,22 @@ actionsToolkit.run(
}); });
} }
if (toolDir) { if (toolDir) {
await install.install(toolDir, Context.tmpDir(), input.version); const runDir = path.join(os.homedir(), `setup-docker-action-${uuid.v4()}`);
stateHelper.setRunDir(runDir);
await install.install(toolDir, runDir, input.version);
} }
await core.group(`Docker info`, async () => { await core.group(`Docker info`, async () => {
await Docker.printVersion(); await Docker.printVersion();
await Docker.printInfo(); await Docker.printInfo();
}); });
},
// post
async () => {
if (stateHelper.runDir.length == 0) {
return;
}
const install = new Install();
await install.tearDown(stateHelper.runDir);
} }
); );

7
src/state-helper.ts Normal file
View File

@ -0,0 +1,7 @@
import * as core from '@actions/core';
export const runDir = process.env['STATE_rundir'] || '';
export function setRunDir(runDir: string) {
core.saveState('rundir', runDir);
}

View File

@ -3204,6 +3204,11 @@ uuid@^8.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
uuid@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==
v8-compile-cache-lib@^3.0.0: v8-compile-cache-lib@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8" resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8"