Skip to content

Commit

Permalink
Console output review
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed May 7, 2021
1 parent e30550d commit 0223489
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 56 deletions.
60 changes: 33 additions & 27 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/gpg.ts
Expand Up @@ -32,7 +32,7 @@ const getGnupgHome = async (): Promise<string> => {
};

const gpgConnectAgent = async (command: string): Promise<string> => {
return await exec.exec(`gpg-connect-agent "${command}" /bye`, [], true).then(res => {
return await exec.exec(`gpg-connect-agent "${command}" /bye`, [], false).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
Expand Down
62 changes: 34 additions & 28 deletions src/main.ts
Expand Up @@ -11,53 +11,57 @@ async function run(): Promise<void> {
stateHelper.setGpgPrivateKey(inputs.gpgPrivateKey);

if (inputs.workdir && inputs.workdir !== '.') {
core.info(`📂 Using ${inputs.workdir} as working directory...`);
core.info(`Using ${inputs.workdir} as working`);
process.chdir(inputs.workdir);
}

core.info('📣 GnuPG info');
core.startGroup('GnuPG info');
const version = await gpg.getVersion();
const dirs = await gpg.getDirs();
core.info(`Version : ${version.gnupg} (libgcrypt ${version.libgcrypt})`);
core.info(`Libdir : ${dirs.libdir}`);
core.info(`Libexecdir : ${dirs.libexecdir}`);
core.info(`Datadir : ${dirs.datadir}`);
core.info(`Homedir : ${dirs.homedir}`);

core.info('🔮 Checking GPG private key');
core.info(`Version: ${version.gnupg} (libgcrypt ${version.libgcrypt})`);
core.info(`Libdir: ${dirs.libdir}`);
core.info(`Libexecdir: ${dirs.libexecdir}`);
core.info(`Datadir: ${dirs.datadir}`);
core.info(`Homedir: ${dirs.homedir}`);
core.endGroup();

core.startGroup('Checking GPG private key');
const privateKey = await openpgp.readPrivateKey(inputs.gpgPrivateKey);
core.debug(`Fingerprint : ${privateKey.fingerprint}`);
core.debug(`KeyID : ${privateKey.keyID}`);
core.debug(`Name : ${privateKey.name}`);
core.debug(`Email : ${privateKey.email}`);
core.debug(`CreationTime : ${privateKey.creationTime}`);

core.info('🔑 Importing GPG private key');
core.info(`Fingerprint: ${privateKey.fingerprint}`);
core.info(`KeyID: ${privateKey.keyID}`);
core.info(`Name: ${privateKey.name}`);
core.info(`Email: ${privateKey.email}`);
core.info(`CreationTime: ${privateKey.creationTime}`);
core.endGroup();

core.startGroup('Importing GPG private key');
await gpg.importKey(inputs.gpgPrivateKey).then(stdout => {
core.debug(stdout);
core.info(stdout);
});
core.endGroup();

if (inputs.passphrase) {
core.info('⚙️ Configuring GnuPG agent');
core.startGroup('Configuring GnuPG agent');
await gpg.configureAgent(gpg.agentConfig);
core.endGroup();

core.info('📌 Getting keygrips');
core.startGroup('Getting keygrips');
for (let keygrip of await gpg.getKeygrips(privateKey.fingerprint)) {
core.info(`🔓 Presetting passphrase for ${keygrip}`);
core.info(`Presetting passphrase for ${keygrip}`);
await gpg.presetPassphrase(keygrip, inputs.passphrase).then(stdout => {
core.debug(stdout);
});
}
core.endGroup();
}

core.info('🛒 Setting outputs...');
core.setOutput('fingerprint', privateKey.fingerprint);
core.setOutput('keyid', privateKey.keyID);
core.setOutput('name', privateKey.name);
core.setOutput('email', privateKey.email);

if (inputs.gitUserSigningkey) {
core.info('🔐 Setting GPG signing keyID for this Git repository');
core.startGroup('Setting GPG signing keyID for this Git repository');
await git.setConfig('user.signingkey', privateKey.keyID);

const userEmail = inputs.gitCommitterEmail || privateKey.email;
Expand All @@ -68,22 +72,23 @@ async function run(): Promise<void> {
return;
}

core.info(`🔨 Configuring Git committer (${userName} <${userEmail}>)`);
core.info(`Configuring Git committer (${userName} <${userEmail}>)`);
await git.setConfig('user.name', userName);
await git.setConfig('user.email', userEmail);

if (inputs.gitCommitGpgsign) {
core.info('💎 Sign all commits automatically');
core.info('Sign all commits automatically');
await git.setConfig('commit.gpgsign', 'true');
}
if (inputs.gitTagGpgsign) {
core.info('💎 Sign all tags automatically');
core.info('Sign all tags automatically');
await git.setConfig('tag.gpgsign', 'true');
}
if (inputs.gitPushGpgsign) {
core.info('💎 Sign all pushes automatically');
core.info('Sign all pushes automatically');
await git.setConfig('push.gpgsign', 'true');
}
core.endGroup();
}
} catch (error) {
core.setFailed(error.message);
Expand All @@ -96,12 +101,13 @@ async function cleanup(): Promise<void> {
return;
}
try {
core.info('🚿 Removing keys');
core.info('Removing keys');
const privateKey = await openpgp.readPrivateKey(stateHelper.gpgPrivateKey);
await gpg.deleteKey(privateKey.fingerprint);

core.info('💀 Killing GnuPG agent');
core.startGroup('Killing GnuPG agent');
await gpg.killAgent();
core.endGroup();
} catch (error) {
core.warning(error.message);
}
Expand Down

0 comments on commit 0223489

Please sign in to comment.