Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle if-asked for git-push-gpgsign input #100

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/ghaction-import-gpg.png
Loading
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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: core.getBooleanInput('git-user-signingkey'),
gitCommitGpgsign: core.getBooleanInput('git-commit-gpgsign'),
gitTagGpgsign: core.getBooleanInput('git-tag-gpgsign'),
gitPushGpgsign: core.getBooleanInput('git-push-gpgsign'),
gitPushGpgsign: core.getInput('git-push-gpgsign') || 'if-asked',
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
Original file line number Diff line number Diff line change
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