Add git-config-global input (#103)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-08-10 09:28:13 +02:00 committed by GitHub
parent dd220e93c3
commit ae17b9f8de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 16 deletions

View file

@ -20,6 +20,9 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
global:
- false
- true
os: os:
- ubuntu-latest - ubuntu-latest
- macOS-latest - macOS-latest
@ -44,6 +47,7 @@ jobs:
with: with:
gpg-private-key: ${{ steps.test.outputs.pgp }} gpg-private-key: ${{ steps.test.outputs.pgp }}
passphrase: ${{ steps.test.outputs.passphrase }} passphrase: ${{ steps.test.outputs.passphrase }}
git-config-global: ${{ matrix.global }}
git-user-signingkey: true git-user-signingkey: true
git-commit-gpgsign: true git-commit-gpgsign: true
git-tag-gpgsign: true git-tag-gpgsign: true

View file

@ -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**) | | `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 | | `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-user-signingkey` | Bool | Set GPG signing keyID for this Git repository (default `false`) |
| `git-commit-gpgsign`**¹** | Bool | Sign all commits automatically. (default `false`) | | `git-commit-gpgsign`**¹** | Bool | Sign all commits automatically. (default `false`) |
| `git-tag-gpgsign`**¹** | Bool | Sign all tags automatically. (default `false`) | | `git-tag-gpgsign`**¹** | Bool | Sign all tags automatically. (default `false`) |

View file

@ -13,6 +13,10 @@ inputs:
passphrase: passphrase:
description: 'Passphrase of the GPG private key' description: 'Passphrase of the GPG private key'
required: false required: false
git-config-global:
description: 'Set Git config global'
default: 'false'
required: false
git-user-signingkey: git-user-signingkey:
description: 'Set GPG signing keyID for this Git repository' description: 'Set GPG signing keyID for this Git repository'
default: 'false' default: 'false'

22
dist/index.js generated vendored
View file

@ -44,6 +44,7 @@ function getInputs() {
return { return {
gpgPrivateKey: core.getInput('gpg-private-key', { required: true }), gpgPrivateKey: core.getInput('gpg-private-key', { required: true }),
passphrase: core.getInput('passphrase'), passphrase: core.getInput('passphrase'),
gitConfigGlobal: core.getBooleanInput('git-config-global'),
gitUserSigningkey: core.getBooleanInput('git-user-signingkey'), gitUserSigningkey: core.getBooleanInput('git-user-signingkey'),
gitCommitGpgsign: core.getBooleanInput('git-commit-gpgsign'), gitCommitGpgsign: core.getBooleanInput('git-commit-gpgsign'),
gitTagGpgsign: core.getBooleanInput('git-tag-gpgsign'), gitTagGpgsign: core.getBooleanInput('git-tag-gpgsign'),
@ -113,9 +114,14 @@ const git = (args = []) => __awaiter(void 0, void 0, void 0, function* () {
return res.stdout.trim(); return res.stdout.trim();
}); });
}); });
function setConfig(key, value) { function setConfig(key, value, global) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
yield git(['config', key, value]); let args = ['config'];
if (global) {
args.push('--global');
}
args.push(key, value);
yield git(args);
}); });
} }
exports.setConfig = setConfig; exports.setConfig = setConfig;
@ -430,7 +436,7 @@ function run() {
context.setOutput('email', privateKey.email); context.setOutput('email', privateKey.email);
if (inputs.gitUserSigningkey) { if (inputs.gitUserSigningkey) {
core.info('🔐 Setting GPG signing keyID for this Git repository'); core.info('🔐 Setting GPG signing keyID for this Git repository');
yield git.setConfig('user.signingkey', privateKey.keyID); yield git.setConfig('user.signingkey', privateKey.keyID, inputs.gitConfigGlobal);
const userEmail = inputs.gitCommitterEmail || privateKey.email; const userEmail = inputs.gitCommitterEmail || privateKey.email;
const userName = inputs.gitCommitterName || privateKey.name; const userName = inputs.gitCommitterName || privateKey.name;
if (userEmail != privateKey.email) { if (userEmail != privateKey.email) {
@ -438,19 +444,19 @@ function run() {
return; return;
} }
core.info(`🔨 Configuring Git committer (${userName} <${userEmail}>)`); core.info(`🔨 Configuring Git committer (${userName} <${userEmail}>)`);
yield git.setConfig('user.name', userName); yield git.setConfig('user.name', userName, inputs.gitConfigGlobal);
yield git.setConfig('user.email', userEmail); yield git.setConfig('user.email', userEmail, inputs.gitConfigGlobal);
if (inputs.gitCommitGpgsign) { if (inputs.gitCommitGpgsign) {
core.info('💎 Sign all commits automatically'); core.info('💎 Sign all commits automatically');
yield git.setConfig('commit.gpgsign', 'true'); yield git.setConfig('commit.gpgsign', 'true', inputs.gitConfigGlobal);
} }
if (inputs.gitTagGpgsign) { if (inputs.gitTagGpgsign) {
core.info('💎 Sign all tags automatically'); core.info('💎 Sign all tags automatically');
yield git.setConfig('tag.gpgsign', 'true'); yield git.setConfig('tag.gpgsign', 'true', inputs.gitConfigGlobal);
} }
if (inputs.gitPushGpgsign) { if (inputs.gitPushGpgsign) {
core.info('💎 Sign all pushes automatically'); core.info('💎 Sign all pushes automatically');
yield git.setConfig('push.gpgsign', inputs.gitPushGpgsign); yield git.setConfig('push.gpgsign', inputs.gitPushGpgsign, inputs.gitConfigGlobal);
} }
} }
} }

View file

@ -4,6 +4,7 @@ import {issueCommand} from '@actions/core/lib/command';
export interface Inputs { export interface Inputs {
gpgPrivateKey: string; gpgPrivateKey: string;
passphrase: string; passphrase: string;
gitConfigGlobal: boolean;
gitUserSigningkey: boolean; gitUserSigningkey: boolean;
gitCommitGpgsign: boolean; gitCommitGpgsign: boolean;
gitTagGpgsign: boolean; gitTagGpgsign: boolean;
@ -17,6 +18,7 @@ export async function getInputs(): Promise<Inputs> {
return { return {
gpgPrivateKey: core.getInput('gpg-private-key', {required: true}), gpgPrivateKey: core.getInput('gpg-private-key', {required: true}),
passphrase: core.getInput('passphrase'), passphrase: core.getInput('passphrase'),
gitConfigGlobal: core.getBooleanInput('git-config-global'),
gitUserSigningkey: core.getBooleanInput('git-user-signingkey'), gitUserSigningkey: core.getBooleanInput('git-user-signingkey'),
gitCommitGpgsign: core.getBooleanInput('git-commit-gpgsign'), gitCommitGpgsign: core.getBooleanInput('git-commit-gpgsign'),
gitTagGpgsign: core.getBooleanInput('git-tag-gpgsign'), gitTagGpgsign: core.getBooleanInput('git-tag-gpgsign'),

View file

@ -14,6 +14,11 @@ const git = async (args: string[] = []): Promise<string> => {
}); });
}; };
export async function setConfig(key: string, value: string): Promise<void> { export async function setConfig(key: string, value: string, global: boolean): Promise<void> {
await git(['config', key, value]); let args: Array<string> = ['config'];
if (global) {
args.push('--global');
}
args.push(key, value);
await git(args);
} }

View file

@ -63,7 +63,7 @@ async function run(): Promise<void> {
if (inputs.gitUserSigningkey) { if (inputs.gitUserSigningkey) {
core.info('🔐 Setting GPG signing keyID for this Git repository'); 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 userEmail = inputs.gitCommitterEmail || privateKey.email;
const userName = inputs.gitCommitterName || privateKey.name; const userName = inputs.gitCommitterName || privateKey.name;
@ -74,20 +74,20 @@ async function run(): Promise<void> {
} }
core.info(`🔨 Configuring Git committer (${userName} <${userEmail}>)`); core.info(`🔨 Configuring Git committer (${userName} <${userEmail}>)`);
await git.setConfig('user.name', userName); await git.setConfig('user.name', userName, inputs.gitConfigGlobal);
await git.setConfig('user.email', userEmail); await git.setConfig('user.email', userEmail, inputs.gitConfigGlobal);
if (inputs.gitCommitGpgsign) { if (inputs.gitCommitGpgsign) {
core.info('💎 Sign all commits automatically'); core.info('💎 Sign all commits automatically');
await git.setConfig('commit.gpgsign', 'true'); await git.setConfig('commit.gpgsign', 'true', inputs.gitConfigGlobal);
} }
if (inputs.gitTagGpgsign) { if (inputs.gitTagGpgsign) {
core.info('💎 Sign all tags automatically'); core.info('💎 Sign all tags automatically');
await git.setConfig('tag.gpgsign', 'true'); await git.setConfig('tag.gpgsign', 'true', inputs.gitConfigGlobal);
} }
if (inputs.gitPushGpgsign) { if (inputs.gitPushGpgsign) {
core.info('💎 Sign all pushes automatically'); core.info('💎 Sign all pushes automatically');
await git.setConfig('push.gpgsign', inputs.gitPushGpgsign); await git.setConfig('push.gpgsign', inputs.gitPushGpgsign, inputs.gitConfigGlobal);
} }
} }
} catch (error) { } catch (error) {