Skip to content

Commit

Permalink
Handle if-asked for git-push-gpgsign input
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Aug 10, 2021
1 parent 5d41f45 commit 983aafb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 107 deletions.
Binary file modified .github/ghaction-import-gpg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -47,7 +47,7 @@ jobs:
git-user-signingkey: true
git-commit-gpgsign: true
git-tag-gpgsign: true
git-push-gpgsign: true
git-push-gpgsign: if-asked
-
name: GPG user IDs
run: |
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
git-user-signingkey: true
git-commit-gpgsign: true
git-tag-gpgsign: true
git-push-gpgsign: true
git-push-gpgsign: if-asked
-
name: GPG user IDs
run: |
Expand Down
53 changes: 0 additions & 53 deletions Dockerfile.dev

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -53,7 +53,8 @@ gpg --armor --export-secret-key joe@foo.bar | xclip -selection clipboard -i
gpg --armor --export-secret-key joe@foo.bar | xclip
```

Paste your clipboard as a [`secret`](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) named `GPG_PRIVATE_KEY` for example. Create another secret with the `PASSPHRASE` if applicable.
Paste your clipboard as a [`secret`](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets)
named `GPG_PRIVATE_KEY` for example. Create another secret with the `PASSPHRASE` if applicable.

## Usage

Expand Down Expand Up @@ -135,7 +136,7 @@ Following inputs can be used as `step.with` keys
| `git-user-signingkey` | Bool | Set GPG signing keyID for this Git repository (default `false`) |
| `git-commit-gpgsign`**ยน** | Bool | Sign all commits automatically. (default `false`) |
| `git-tag-gpgsign`**ยน** | Bool | Sign all tags automatically. (default `false`) |
| `git-push-gpgsign`**ยน** | Bool | Sign all pushes automatically. (default `false`) |
| `git-push-gpgsign`**ยน** | String | Sign all pushes automatically. (default `if-asked`) |
| `git-committer-name`**ยน** | String | Set commit author's name (defaults to the name associated with the GPG key) |
| `git-committer-email`**ยน** | String | Set commit author's email (defaults to the email address associated with the GPG key) |
| `workdir` | String | Working directory (below repository root) (default `.`) |
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Expand Up @@ -27,7 +27,7 @@ inputs:
required: false
git-push-gpgsign:
description: 'Sign all pushes automatically. git-user-signingkey needs to be enabled'
default: 'false'
default: 'if-asked'
required: false
git-committer-name:
description: 'Commit author''s name'
Expand Down
53 changes: 29 additions & 24 deletions dist/index.js

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

4 changes: 2 additions & 2 deletions src/context.ts
Expand Up @@ -7,7 +7,7 @@ export interface Inputs {
gitUserSigningkey: boolean;
gitCommitGpgsign: boolean;
gitTagGpgsign: boolean;
gitPushGpgsign: boolean;
gitPushGpgsign: string;
gitCommitterName: string;
gitCommitterEmail: string;
workdir: string;
Expand All @@ -20,7 +20,7 @@ export async function getInputs(): Promise<Inputs> {
gitUserSigningkey: /true/i.test(core.getInput('git-user-signingkey')),
gitCommitGpgsign: /true/i.test(core.getInput('git-commit-gpgsign')),
gitTagGpgsign: /true/i.test(core.getInput('git-tag-gpgsign')),
gitPushGpgsign: /true/i.test(core.getInput('git-push-gpgsign')),
gitPushGpgsign: core.getInput('git-push-gpgsign'),
gitCommitterName: core.getInput('git-committer-name'),
gitCommitterEmail: core.getInput('git-committer-email'),
workdir: core.getInput('workdir') || '.'
Expand Down
51 changes: 28 additions & 23 deletions src/main.ts
Expand Up @@ -15,39 +15,44 @@ async function run(): Promise<void> {
process.chdir(inputs.workdir);
}

core.info('๐Ÿ“ฃ 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}`);
await core.group(`๐Ÿ“ฃ GnuPG info`, async () => {
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');
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');
await gpg.importKey(inputs.gpgPrivateKey).then(stdout => {
core.debug(stdout);
await core.group(`๐Ÿ”ฎ Checking GPG private key`, async () => {
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}`);
});

await core.group(`๐Ÿ”‘ Importing GPG private key`, async () => {
await gpg.importKey(inputs.gpgPrivateKey).then(stdout => {
core.info(stdout);
});
});

if (inputs.passphrase) {
core.info('โš™๏ธ Configuring GnuPG agent');
await gpg.configureAgent(gpg.agentConfig);

core.info('๐Ÿ“Œ Getting keygrips');
for (let keygrip of await gpg.getKeygrips(privateKey.fingerprint)) {
core.info(`๐Ÿ”“ Presetting passphrase for ${keygrip}`);
await gpg.presetPassphrase(keygrip, inputs.passphrase).then(stdout => {
core.debug(stdout);
});
}
await core.group(`๐Ÿ“Œ Getting keygrips`, async () => {
for (let keygrip of await gpg.getKeygrips(privateKey.fingerprint)) {
core.info(`๐Ÿ”“ Presetting passphrase for ${keygrip}`);
await gpg.presetPassphrase(keygrip, inputs.passphrase).then(stdout => {
core.debug(stdout);
});
}
});
}

core.info('๐Ÿ›’ Setting outputs...');
Expand Down Expand Up @@ -82,7 +87,7 @@ async function run(): Promise<void> {
}
if (inputs.gitPushGpgsign) {
core.info('๐Ÿ’Ž Sign all pushes automatically');
await git.setConfig('push.gpgsign', 'true');
await git.setConfig('push.gpgsign', inputs.gitPushGpgsign);
}
}
} catch (error) {
Expand Down

0 comments on commit 983aafb

Please sign in to comment.