From f5631011c605ccc5a19265ebdd46cf2d5d5f1218 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 3 May 2020 21:22:08 +0200 Subject: [PATCH] Read private key on cleanup --- dist/index.js | 6 +++--- src/main.ts | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 93483af..ea03e7c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -111,7 +111,6 @@ const core = __importStar(__webpack_require__(470)); const gpg_1 = __webpack_require__(207); const openpgp_1 = __webpack_require__(781); const stateHelper = __importStar(__webpack_require__(153)); -let privateKey; function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -122,7 +121,7 @@ function run() { core.debug(`SIGNING_KEY: ${process.env.SIGNING_KEY}`); core.debug(`PASSPHRASE: ${process.env.PASSPHRASE}`); core.info('🔮 Checking signing key...'); - privateKey = yield openpgp_1.readPrivateKey(process.env.SIGNING_KEY); + const privateKey = yield openpgp_1.readPrivateKey(process.env.SIGNING_KEY); core.debug(`key.fingerprint=${privateKey.fingerprint}`); core.debug(`key.keyID=${privateKey.keyID}`); core.debug(`key.userID=${privateKey.userID}`); @@ -137,12 +136,13 @@ function run() { } function cleanup() { return __awaiter(this, void 0, void 0, function* () { - if (!privateKey) { + if (!process.env.SIGNING_KEY) { core.debug('Private key is not defined. Skipping cleanup.'); return; } try { core.info('🚿 Removing keys from GnuPG...'); + const privateKey = yield openpgp_1.readPrivateKey(process.env.SIGNING_KEY); yield gpg_1.deleteKey(privateKey.fingerprint); } catch (error) { diff --git a/src/main.ts b/src/main.ts index eea3645..3a5d0e4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,10 +1,8 @@ import * as core from '@actions/core'; import {deleteKey, importKey} from './gpg'; -import {PrivateKey, readPrivateKey} from './openpgp'; +import {readPrivateKey} from './openpgp'; import * as stateHelper from './state-helper'; -let privateKey: PrivateKey | undefined; - async function run(): Promise { try { if (!process.env.SIGNING_KEY) { @@ -16,7 +14,7 @@ async function run(): Promise { core.debug(`PASSPHRASE: ${process.env.PASSPHRASE}`); core.info('🔮 Checking signing key...'); - privateKey = await readPrivateKey(process.env.SIGNING_KEY); + const privateKey = await readPrivateKey(process.env.SIGNING_KEY); core.debug(`key.fingerprint=${privateKey.fingerprint}`); core.debug(`key.keyID=${privateKey.keyID}`); core.debug(`key.userID=${privateKey.userID}`); @@ -30,12 +28,13 @@ async function run(): Promise { } async function cleanup(): Promise { - if (!privateKey) { + if (!process.env.SIGNING_KEY) { core.debug('Private key is not defined. Skipping cleanup.'); return; } try { core.info('🚿 Removing keys from GnuPG...'); + const privateKey = await readPrivateKey(process.env.SIGNING_KEY); await deleteKey(privateKey.fingerprint); } catch (error) { core.warning(error.message);