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

Add git-config-global input #103

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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