Skip to content

Commit

Permalink
Add git-config-global input (#103)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max and crazy-max committed Aug 10, 2021
1 parent dd220e9 commit ae17b9f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -20,6 +20,9 @@ jobs:
strategy:
fail-fast: false
matrix:
global:
- false
- true
os:
- ubuntu-latest
- macOS-latest
Expand All @@ -44,6 +47,7 @@ jobs:
with:
gpg-private-key: ${{ steps.test.outputs.pgp }}
passphrase: ${{ steps.test.outputs.passphrase }}
git-config-global: ${{ matrix.global }}
git-user-signingkey: true
git-commit-gpgsign: true
git-tag-gpgsign: true
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -133,6 +133,7 @@ Following inputs can be used as `step.with` keys
|---------------------------------------|---------|------------------------------------------------|
| `gpg-private-key` | String | GPG private key exported as an ASCII armored version or its base64 encoding (**required**) |
| `passphrase` | String | Passphrase of the GPG private key |
| `git-config-global` | Bool | Set Git config global (default `false`) |
| `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`) |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -13,6 +13,10 @@ inputs:
passphrase:
description: 'Passphrase of the GPG private key'
required: false
git-config-global:
description: 'Set Git config global'
default: 'false'
required: false
git-user-signingkey:
description: 'Set GPG signing keyID for this Git repository'
default: 'false'
Expand Down
22 changes: 14 additions & 8 deletions dist/index.js

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

2 changes: 2 additions & 0 deletions src/context.ts
Expand Up @@ -4,6 +4,7 @@ import {issueCommand} from '@actions/core/lib/command';
export interface Inputs {
gpgPrivateKey: string;
passphrase: string;
gitConfigGlobal: boolean;
gitUserSigningkey: boolean;
gitCommitGpgsign: boolean;
gitTagGpgsign: boolean;
Expand All @@ -17,6 +18,7 @@ export async function getInputs(): Promise<Inputs> {
return {
gpgPrivateKey: core.getInput('gpg-private-key', {required: true}),
passphrase: core.getInput('passphrase'),
gitConfigGlobal: core.getBooleanInput('git-config-global'),
gitUserSigningkey: core.getBooleanInput('git-user-signingkey'),
gitCommitGpgsign: core.getBooleanInput('git-commit-gpgsign'),
gitTagGpgsign: core.getBooleanInput('git-tag-gpgsign'),
Expand Down
9 changes: 7 additions & 2 deletions src/git.ts
Expand Up @@ -14,6 +14,11 @@ const git = async (args: string[] = []): Promise<string> => {
});
};

export async function setConfig(key: string, value: string): Promise<void> {
await git(['config', key, value]);
export async function setConfig(key: string, value: string, global: boolean): Promise<void> {
let args: Array<string> = ['config'];
if (global) {
args.push('--global');
}
args.push(key, value);
await git(args);
}
12 changes: 6 additions & 6 deletions src/main.ts
Expand Up @@ -63,7 +63,7 @@ async function run(): Promise<void> {

if (inputs.gitUserSigningkey) {
core.info('πŸ” Setting GPG signing keyID for this Git repository');
await git.setConfig('user.signingkey', privateKey.keyID);
await git.setConfig('user.signingkey', privateKey.keyID, inputs.gitConfigGlobal);

const userEmail = inputs.gitCommitterEmail || privateKey.email;
const userName = inputs.gitCommitterName || privateKey.name;
Expand All @@ -74,20 +74,20 @@ async function run(): Promise<void> {
}

core.info(`πŸ”¨ Configuring Git committer (${userName} <${userEmail}>)`);
await git.setConfig('user.name', userName);
await git.setConfig('user.email', userEmail);
await git.setConfig('user.name', userName, inputs.gitConfigGlobal);
await git.setConfig('user.email', userEmail, inputs.gitConfigGlobal);

if (inputs.gitCommitGpgsign) {
core.info('πŸ’Ž Sign all commits automatically');
await git.setConfig('commit.gpgsign', 'true');
await git.setConfig('commit.gpgsign', 'true', inputs.gitConfigGlobal);
}
if (inputs.gitTagGpgsign) {
core.info('πŸ’Ž Sign all tags automatically');
await git.setConfig('tag.gpgsign', 'true');
await git.setConfig('tag.gpgsign', 'true', inputs.gitConfigGlobal);
}
if (inputs.gitPushGpgsign) {
core.info('πŸ’Ž Sign all pushes automatically');
await git.setConfig('push.gpgsign', inputs.gitPushGpgsign);
await git.setConfig('push.gpgsign', inputs.gitPushGpgsign, inputs.gitConfigGlobal);
}
}
} catch (error) {
Expand Down

0 comments on commit ae17b9f

Please sign in to comment.