mirror of
https://github.com/dagger/dagger-for-github.git
synced 2025-12-31 20:59:43 +11:00
Merge pull request #4 from crazy-max/cleanup
Add input to allow to cleanup Dagger home folder at the end of a job
This commit is contained in:
commit
83c45d9edf
6 changed files with 95 additions and 4 deletions
|
|
@ -74,6 +74,7 @@ Following inputs can be used as `step.with` keys
|
|||
| `args` | String | | Arguments to pass to Dagger |
|
||||
| `workdir` | String | `.` | Working directory (below repository root) |
|
||||
| `install-only` | Bool | `false` | Just install Dagger |
|
||||
| `cleanup` | Bool | `true` | Cleanup Dagger home folder at the end of a job |
|
||||
|
||||
## Development
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,12 @@ inputs:
|
|||
description: 'Just install Dagger'
|
||||
default: 'false'
|
||||
required: false
|
||||
cleanup:
|
||||
description: 'Cleanup Dagger home folder at the end of a job'
|
||||
default: 'true'
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
post: 'dist/index.js'
|
||||
|
|
|
|||
61
dist/index.js
generated
vendored
61
dist/index.js
generated
vendored
|
|
@ -45,7 +45,8 @@ function getInputs() {
|
|||
ageKey: core.getInput('age-key'),
|
||||
workdir: core.getInput('workdir') || '.',
|
||||
args: core.getInput('args'),
|
||||
installOnly: core.getBooleanInput('install-only')
|
||||
installOnly: core.getBooleanInput('install-only'),
|
||||
cleanup: core.getBooleanInput('cleanup')
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
@ -186,6 +187,7 @@ const path_1 = __importDefault(__webpack_require__(622));
|
|||
const os_1 = __importDefault(__webpack_require__(87));
|
||||
const context = __importStar(__webpack_require__(842));
|
||||
const dagger = __importStar(__webpack_require__(113));
|
||||
const stateHelper = __importStar(__webpack_require__(647));
|
||||
const core = __importStar(__webpack_require__(186));
|
||||
const exec = __importStar(__webpack_require__(514));
|
||||
function run() {
|
||||
|
|
@ -214,6 +216,7 @@ function run() {
|
|||
core.info(`Using ${inputs.workdir} as working directory`);
|
||||
process.chdir(inputs.workdir);
|
||||
}
|
||||
stateHelper.setCleanup(inputs.cleanup);
|
||||
yield exec.exec(`${daggerBin} ${inputs.args} --log-format pretty`);
|
||||
}
|
||||
catch (error) {
|
||||
|
|
@ -221,11 +224,65 @@ function run() {
|
|||
}
|
||||
});
|
||||
}
|
||||
run();
|
||||
function cleanup() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!stateHelper.cleanup) {
|
||||
return;
|
||||
}
|
||||
core.info(`Removing ${path_1.default.join(os_1.default.homedir(), '.dagger')}`);
|
||||
fs_1.default.rmdirSync(path_1.default.join(os_1.default.homedir(), '.dagger'), { recursive: true });
|
||||
});
|
||||
}
|
||||
if (!stateHelper.IsPost) {
|
||||
run();
|
||||
}
|
||||
else {
|
||||
cleanup();
|
||||
}
|
||||
//# sourceMappingURL=main.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 647:
|
||||
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.setCleanup = exports.cleanup = exports.IsPost = void 0;
|
||||
const core = __importStar(__webpack_require__(186));
|
||||
exports.IsPost = !!process.env['STATE_isPost'];
|
||||
exports.cleanup = /true/i.test(process.env['STATE_cleanup'] || '');
|
||||
function setCleanup(cleanup) {
|
||||
core.saveState('cleanup', cleanup);
|
||||
}
|
||||
exports.setCleanup = setCleanup;
|
||||
if (!exports.IsPost) {
|
||||
core.saveState('isPost', 'true');
|
||||
}
|
||||
//# sourceMappingURL=state-helper.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 351:
|
||||
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ export interface Inputs {
|
|||
workdir: string;
|
||||
args: string;
|
||||
installOnly: boolean;
|
||||
cleanup: boolean;
|
||||
}
|
||||
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
|
|
@ -14,6 +15,7 @@ export async function getInputs(): Promise<Inputs> {
|
|||
ageKey: core.getInput('age-key'),
|
||||
workdir: core.getInput('workdir') || '.',
|
||||
args: core.getInput('args'),
|
||||
installOnly: core.getBooleanInput('install-only')
|
||||
installOnly: core.getBooleanInput('install-only'),
|
||||
cleanup: core.getBooleanInput('cleanup')
|
||||
};
|
||||
}
|
||||
|
|
|
|||
16
src/main.ts
16
src/main.ts
|
|
@ -3,6 +3,7 @@ import path from 'path';
|
|||
import os from 'os';
|
||||
import * as context from './context';
|
||||
import * as dagger from './dagger';
|
||||
import * as stateHelper from './state-helper';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
|
|
@ -34,10 +35,23 @@ async function run(): Promise<void> {
|
|||
process.chdir(inputs.workdir);
|
||||
}
|
||||
|
||||
stateHelper.setCleanup(inputs.cleanup);
|
||||
await exec.exec(`${daggerBin} ${inputs.args} --log-format pretty`);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
async function cleanup(): Promise<void> {
|
||||
if (!stateHelper.cleanup) {
|
||||
return;
|
||||
}
|
||||
core.info(`Removing ${path.join(os.homedir(), '.dagger')}`);
|
||||
fs.rmdirSync(path.join(os.homedir(), '.dagger'), {recursive: true});
|
||||
}
|
||||
|
||||
if (!stateHelper.IsPost) {
|
||||
run();
|
||||
} else {
|
||||
cleanup();
|
||||
}
|
||||
|
|
|
|||
12
src/state-helper.ts
Normal file
12
src/state-helper.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import * as core from '@actions/core';
|
||||
|
||||
export const IsPost = !!process.env['STATE_isPost'];
|
||||
export const cleanup = /true/i.test(process.env['STATE_cleanup'] || '');
|
||||
|
||||
export function setCleanup(cleanup: boolean) {
|
||||
core.saveState('cleanup', cleanup);
|
||||
}
|
||||
|
||||
if (!IsPost) {
|
||||
core.saveState('isPost', 'true');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue