mirror of
https://github.com/crazy-max/ghaction-import-gpg.git
synced 2024-12-24 12:12:08 -05:00
Add git-config-global
input (#103)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
dd220e93c3
commit
ae17b9f8de
7 changed files with 38 additions and 16 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -20,6 +20,9 @@ jobs:
|
|||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
global:
|
||||
- false
|
||||
- true
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macOS-latest
|
||||
|
@ -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
|
||||
|
|
|
@ -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`) |
|
||||
|
|
|
@ -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'
|
||||
|
|
22
dist/index.js
generated
vendored
22
dist/index.js
generated
vendored
|
@ -44,6 +44,7 @@ function getInputs() {
|
|||
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'),
|
||||
|
@ -113,9 +114,14 @@ const git = (args = []) => __awaiter(void 0, void 0, void 0, function* () {
|
|||
return res.stdout.trim();
|
||||
});
|
||||
});
|
||||
function setConfig(key, value) {
|
||||
function setConfig(key, value, global) {
|
||||
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;
|
||||
|
@ -430,7 +436,7 @@ function run() {
|
|||
context.setOutput('email', privateKey.email);
|
||||
if (inputs.gitUserSigningkey) {
|
||||
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 userName = inputs.gitCommitterName || privateKey.name;
|
||||
if (userEmail != privateKey.email) {
|
||||
|
@ -438,19 +444,19 @@ function run() {
|
|||
return;
|
||||
}
|
||||
core.info(`🔨 Configuring Git committer (${userName} <${userEmail}>)`);
|
||||
yield git.setConfig('user.name', userName);
|
||||
yield git.setConfig('user.email', userEmail);
|
||||
yield git.setConfig('user.name', userName, inputs.gitConfigGlobal);
|
||||
yield git.setConfig('user.email', userEmail, inputs.gitConfigGlobal);
|
||||
if (inputs.gitCommitGpgsign) {
|
||||
core.info('💎 Sign all commits automatically');
|
||||
yield git.setConfig('commit.gpgsign', 'true');
|
||||
yield git.setConfig('commit.gpgsign', 'true', inputs.gitConfigGlobal);
|
||||
}
|
||||
if (inputs.gitTagGpgsign) {
|
||||
core.info('💎 Sign all tags automatically');
|
||||
yield git.setConfig('tag.gpgsign', 'true');
|
||||
yield git.setConfig('tag.gpgsign', 'true', inputs.gitConfigGlobal);
|
||||
}
|
||||
if (inputs.gitPushGpgsign) {
|
||||
core.info('💎 Sign all pushes automatically');
|
||||
yield git.setConfig('push.gpgsign', inputs.gitPushGpgsign);
|
||||
yield git.setConfig('push.gpgsign', inputs.gitPushGpgsign, inputs.gitConfigGlobal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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'),
|
||||
|
|
|
@ -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
src/main.ts
12
src/main.ts
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue