Skip to content

Commit e097cc9

Browse files
committed
Add git_tag_gpgsign and git_push_gpgsign inputs
Some inputs and secrets have been renamed
1 parent a71299c commit e097cc9

File tree

4 files changed

+86
-41
lines changed

4 files changed

+86
-41
lines changed

โ€Ž.github/workflows/ci.ymlโ€Ž

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ jobs:
3434
run: |
3535
env|sort
3636
-
37-
name: Import GPG key
37+
name: Import GPG private key
3838
uses: ./
3939
with:
40-
git_gpgsign: true
40+
git_user_gpgsign: true
41+
git_commit_gpgsign: true
42+
git_tag_gpgsign: true
43+
git_push_gpgsign: true
4144
git_committer_name: Joe Tester
4245
git_committer_email: joe@foo.bar
4346
env:
44-
SIGNING_KEY: ${{ secrets.SIGNING_KEY_TEST }}
47+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY_TEST }}
4548
PASSPHRASE: ${{ secrets.PASSPHRASE_TEST }}

โ€ŽREADME.mdโ€Ž

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ On your local machine, export the GPG private key as an ASCII armored version:
2828
gpg --armor --export-secret-key --output key.pgp joe@foo.bar
2929
```
3030

31-
Copy the content of `key.pgp` file as a [`secret`](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) named `SIGNING_KEY` for example. Create another secret with your `PASSPHRASE` if applicable.
31+
Copy the content of `key.pgp` file 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 your `PASSPHRASE` if applicable.
3232

3333
```yaml
3434
name: import-gpg
@@ -48,10 +48,19 @@ jobs:
4848
name: Import GPG key
4949
uses: crazy-max/ghaction-import-gpg@v1
5050
with:
51-
git_gpgsign: true
51+
git_user_signingkey: true
52+
git_commit_gpgsign: true
53+
git_tag_gpgsign: true
5254
env:
53-
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
55+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
5456
PASSPHRASE: ${{ secrets.PASSPHRASE }}
57+
-
58+
name: Sign commit and push changes
59+
run: |
60+
echo foo > bar.txt
61+
git add .
62+
git commit -S -m "This commit is signed!"
63+
git push
5564
```
5665
5766
## Customizing
@@ -62,18 +71,21 @@ Following inputs can be used as `step.with` keys
6271

6372
| Name | Type | Description |
6473
|------------------------|---------|----------------------------------------------------------|
65-
| `git_gpgsign` | Bool | Enable signing for this Git repository (default `false`) |
74+
| `git_user_signingkey` | Bool | Set GPG signing keyID for this Git repository (default `false`) |
75+
| `git_commit_gpgsign` | Bool | Sign all commits automatically. `git_user_signingkey` needs to be enabled. (default `false`) |
76+
| `git_tag_gpgsign` | Bool | Sign all tags automatically. `git_user_signingkey` needs to be enabled. (default `false`) |
77+
| `git_push_gpgsign` | Bool | Sign all pushes automatically. `git_user_signingkey` needs to be enabled. (default `false`) |
6678
| `git_committer_name` | String | Commit author's name (default [GITHUB_ACTOR](https://help.github.com/en/github/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables) or `github-actions`) |
6779
| `git_committer_email` | String | Commit author's email (default `<committer_name>@users.noreply.github.com`) |
6880

6981
### environment variables
7082

7183
Following environment variables can be used as `step.env` keys
7284

73-
| Name | Description |
74-
|----------------|---------------------------------------|
75-
| `SIGNING_KEY` | GPG private key exported as an ASCII armored version |
76-
| `PASSPHRASE` | Passphrase of your GPG key if setted for your `SIGNING_KEY` |
85+
| Name | Description |
86+
|--------------------|---------------------------------------|
87+
| `GPG_PRIVATE_KEY` | GPG private key exported as an ASCII armored version |
88+
| `PASSPHRASE` | Passphrase of your `GPG_PRIVATE_KEY` key if setted |
7789

7890
## How can I help?
7991

โ€Ždist/index.jsโ€Ž

Lines changed: 29 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

โ€Žsrc/main.tsโ€Ž

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import * as stateHelper from './state-helper';
66

77
async function run(): Promise<void> {
88
try {
9-
if (!process.env.SIGNING_KEY) {
10-
core.setFailed('Signing key required');
9+
if (!process.env.GPG_PRIVATE_KEY) {
10+
core.setFailed('GPG private key required');
1111
return;
1212
}
1313

14-
const git_gpgsign = /true/i.test(core.getInput('git_gpgsign'));
14+
const git_commit_gpgsign = /true/i.test(core.getInput('git_commit_gpgsign'));
15+
const git_tag_gpgsign = /true/i.test(core.getInput('git_tag_gpgsign'));
16+
const git_push_gpgsign = /true/i.test(core.getInput('git_push_gpgsign'));
17+
const git_user_signingkey = /true/i.test(core.getInput('git_user_signingkey'));
1518
const git_committer_name: string =
1619
core.getInput('git_committer_name') || process.env['GITHUB_ACTOR'] || 'github-actions';
1720
const git_committer_email: string =
@@ -26,16 +29,16 @@ async function run(): Promise<void> {
2629
core.info(`Datadir : ${dirs.datadir}`);
2730
core.info(`Homedir : ${dirs.homedir}`);
2831

29-
core.info('๐Ÿ”ฎ Checking signing key');
30-
const privateKey = await openpgp.readPrivateKey(process.env.SIGNING_KEY);
32+
core.info('๐Ÿ”ฎ Checking GPG private key');
33+
const privateKey = await openpgp.readPrivateKey(process.env.GPG_PRIVATE_KEY);
3134
core.debug(`Fingerprint : ${privateKey.fingerprint}`);
3235
core.debug(`KeyID : ${privateKey.keyID}`);
3336
core.debug(`Name : ${privateKey.name}`);
3437
core.debug(`Email : ${privateKey.email}`);
3538
core.debug(`CreationTime : ${privateKey.creationTime}`);
3639

37-
core.info('๐Ÿ”‘ Importing secret key');
38-
await gpg.importKey(process.env.SIGNING_KEY).then(stdout => {
40+
core.info('๐Ÿ”‘ Importing GPG private key');
41+
await gpg.importKey(process.env.GPG_PRIVATE_KEY).then(stdout => {
3942
core.debug(stdout);
4043
});
4144

@@ -53,32 +56,45 @@ async function run(): Promise<void> {
5356
});
5457
}
5558

56-
if (git_gpgsign) {
57-
core.info(`๐Ÿ”จ Configuring Git committer (${git_committer_name} <${git_committer_email}>)`);
59+
if (git_user_signingkey) {
60+
core.info('๐Ÿ” Setting GPG signing keyID for this Git repository');
61+
await git.setConfig('user.signingkey', privateKey.keyID);
62+
5863
if (git_committer_email != privateKey.email) {
5964
core.setFailed('Committer email does not match GPG key user address');
6065
return;
6166
}
67+
68+
core.info(`๐Ÿ”จ Configuring Git committer (${git_committer_name} <${git_committer_email}>)`);
6269
await git.setConfig('user.name', git_committer_name);
6370
await git.setConfig('user.email', git_committer_email);
6471

65-
core.info('๐Ÿ’Ž Enable signing for this Git repository');
66-
await git.setConfig('commit.gpgsign', 'true');
67-
await git.setConfig('user.signingkey', privateKey.keyID);
72+
if (git_commit_gpgsign) {
73+
core.info('๐Ÿ’Ž Sign all commits automatically');
74+
await git.setConfig('commit.gpgsign', 'true');
75+
}
76+
if (git_tag_gpgsign) {
77+
core.info('๐Ÿ’Ž Sign all tags automatically');
78+
await git.setConfig('tag.gpgsign', 'true');
79+
}
80+
if (git_push_gpgsign) {
81+
core.info('๐Ÿ’Ž Sign all pushes automatically');
82+
await git.setConfig('push.gpgsign', 'true');
83+
}
6884
}
6985
} catch (error) {
7086
core.setFailed(error.message);
7187
}
7288
}
7389

7490
async function cleanup(): Promise<void> {
75-
if (!process.env.SIGNING_KEY) {
76-
core.debug('Signing key is not defined. Skipping cleanup.');
91+
if (!process.env.GPG_PRIVATE_KEY) {
92+
core.debug('GPG private key is not defined. Skipping cleanup.');
7793
return;
7894
}
7995
try {
8096
core.info('๐Ÿšฟ Removing keys');
81-
const privateKey = await openpgp.readPrivateKey(process.env.SIGNING_KEY);
97+
const privateKey = await openpgp.readPrivateKey(process.env.GPG_PRIVATE_KEY);
8298
await gpg.deleteKey(privateKey.fingerprint);
8399

84100
core.info('๐Ÿ’€ Killing GnuPG agent');

0 commit comments

Comments
ย (0)