2020-05-03 20:46:05 +02:00
|
|
|
import * as core from '@actions/core';
|
2020-05-03 21:33:19 +02:00
|
|
|
import * as gpg from './gpg';
|
|
|
|
import * as openpgp from './openpgp';
|
2020-05-03 20:46:05 +02:00
|
|
|
import * as stateHelper from './state-helper';
|
|
|
|
|
|
|
|
async function run(): Promise<void> {
|
|
|
|
try {
|
|
|
|
if (!process.env.SIGNING_KEY) {
|
|
|
|
core.setFailed('Signing key required');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-03 21:33:19 +02:00
|
|
|
core.info('📣 GnuPG info');
|
|
|
|
const version = await gpg.getVersion();
|
|
|
|
core.info(`GnuPG version: ${version.gnupg}`);
|
|
|
|
core.info(`libgcrypt version: ${version.libgcrypt}`);
|
2020-05-03 20:46:05 +02:00
|
|
|
|
|
|
|
core.info('🔮 Checking signing key...');
|
2020-05-03 21:33:19 +02:00
|
|
|
const privateKey = await openpgp.readPrivateKey(process.env.SIGNING_KEY);
|
2020-05-03 20:46:05 +02:00
|
|
|
core.debug(`key.fingerprint=${privateKey.fingerprint}`);
|
|
|
|
core.debug(`key.keyID=${privateKey.keyID}`);
|
|
|
|
core.debug(`key.userID=${privateKey.userID}`);
|
2020-05-03 21:17:25 +02:00
|
|
|
core.debug(`key.creationTime=${privateKey.creationTime}`);
|
2020-05-03 20:46:05 +02:00
|
|
|
|
|
|
|
core.info('🔑 Importing secret key...');
|
2020-05-03 21:33:19 +02:00
|
|
|
await gpg.importKey(process.env.SIGNING_KEY);
|
2020-05-03 20:46:05 +02:00
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function cleanup(): Promise<void> {
|
2020-05-03 21:22:08 +02:00
|
|
|
if (!process.env.SIGNING_KEY) {
|
2020-05-03 21:17:25 +02:00
|
|
|
core.debug('Private key is not defined. Skipping cleanup.');
|
2020-05-03 20:46:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
core.info('🚿 Removing keys from GnuPG...');
|
2020-05-03 21:33:19 +02:00
|
|
|
const privateKey = await openpgp.readPrivateKey(process.env.SIGNING_KEY);
|
|
|
|
await gpg.deleteKey(privateKey.fingerprint);
|
2020-05-03 20:46:05 +02:00
|
|
|
} catch (error) {
|
|
|
|
core.warning(error.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Main
|
|
|
|
if (!stateHelper.IsPost) {
|
|
|
|
run();
|
|
|
|
}
|
|
|
|
// Post
|
|
|
|
else {
|
|
|
|
cleanup();
|
|
|
|
}
|