From 297fd4647b1e6e3f43b7edc335045cfb0f8cf3cd Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 3 May 2020 21:42:55 +0200 Subject: [PATCH] Fix tmp path for signing key --- dist/index.js | 23 +++++++++++++++-------- src/gpg.ts | 13 ++++++++----- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/dist/index.js b/dist/index.js index c252284..05d5345 100644 --- a/dist/index.js +++ b/dist/index.js @@ -178,14 +178,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -const fs_1 = __webpack_require__(747); -const child_process_1 = __importDefault(__webpack_require__(129)); +const child_process = __importStar(__webpack_require__(129)); +const fs = __importStar(__webpack_require__(747)); +const path = __importStar(__webpack_require__(622)); +const os = __importStar(__webpack_require__(87)); const gpg = (args = []) => __awaiter(void 0, void 0, void 0, function* () { - return child_process_1.default + return child_process .execSync(`gpg ${args.join(' ')}`, { encoding: 'utf8' }) @@ -213,10 +219,11 @@ exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () { }; }); exports.importKey = (armoredText) => __awaiter(void 0, void 0, void 0, function* () { - const keyPath = `${process.env.HOME}/key.pgp`; - fs_1.writeFileSync(keyPath, armoredText, { mode: 0o600 }); + const keyFolder = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-import-gpg-')); + const keyPath = `${keyFolder}/key.pgp`; + fs.writeFileSync(keyPath, armoredText, { mode: 0o600 }); yield gpg(['--import', '--batch', '--yes', keyPath]).finally(() => { - fs_1.unlinkSync(keyPath); + fs.unlinkSync(keyPath); }); }); exports.deleteKey = (fingerprint) => __awaiter(void 0, void 0, void 0, function* () { diff --git a/src/gpg.ts b/src/gpg.ts index 726eb65..80732f4 100644 --- a/src/gpg.ts +++ b/src/gpg.ts @@ -1,5 +1,7 @@ -import {unlinkSync, writeFileSync} from 'fs'; -import child_process from 'child_process'; +import * as child_process from 'child_process'; +import * as fs from 'fs'; +import * as path from 'path'; +import * as os from 'os'; export interface Version { gnupg: string; @@ -37,11 +39,12 @@ export const getVersion = async (): Promise => { }; export const importKey = async (armoredText: string): Promise => { - const keyPath: string = `${process.env.HOME}/key.pgp`; - writeFileSync(keyPath, armoredText, {mode: 0o600}); + const keyFolder: string = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-import-gpg-')); + const keyPath: string = `${keyFolder}/key.pgp`; + fs.writeFileSync(keyPath, armoredText, {mode: 0o600}); await gpg(['--import', '--batch', '--yes', keyPath]).finally(() => { - unlinkSync(keyPath); + fs.unlinkSync(keyPath); }); };