mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 18:06:45 +00:00
Added support for GPG
This commit is contained in:
parent
5c87b70ffe
commit
d94db22179
17 changed files with 37442 additions and 5142 deletions
58
src/gpg.ts
Normal file
58
src/gpg.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as io from '@actions/io';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as util from './util';
|
||||
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
||||
|
||||
export const PRIVATE_KEY_FILE = path.join(util.getTempDir(), 'private-key.asc');
|
||||
|
||||
const PRIVATE_KEY_FINGERPRINT_REGEX = /\w{40}/;
|
||||
|
||||
export async function importKey(privateKey: string) {
|
||||
fs.writeFileSync(PRIVATE_KEY_FILE, privateKey, {
|
||||
encoding: 'utf-8',
|
||||
flag: 'w'
|
||||
});
|
||||
|
||||
let output = '';
|
||||
|
||||
const options: ExecOptions = {
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
output += data.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await exec.exec(
|
||||
'gpg',
|
||||
[
|
||||
'--batch',
|
||||
'--import-options',
|
||||
'import-show',
|
||||
'--import',
|
||||
PRIVATE_KEY_FILE
|
||||
],
|
||||
options
|
||||
);
|
||||
|
||||
await io.rmRF(PRIVATE_KEY_FILE);
|
||||
|
||||
const match = output.match(PRIVATE_KEY_FINGERPRINT_REGEX);
|
||||
return match && match[0];
|
||||
}
|
||||
|
||||
export async function deleteKey(keyFingerprint: string) {
|
||||
await exec.exec(
|
||||
'gpg',
|
||||
['--batch', '--yes', '--delete-secret-keys', keyFingerprint],
|
||||
{silent: true}
|
||||
);
|
||||
await exec.exec(
|
||||
'gpg',
|
||||
['--batch', '--yes', '--delete-keys', keyFingerprint],
|
||||
{silent: true}
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue