addressed most of the feedback

This commit is contained in:
Jared Petersen
2020-07-15 19:53:39 -06:00
parent 01f44229d4
commit 7f2382879a
7 changed files with 130 additions and 51 deletions

View File

@ -1,11 +1,14 @@
import * as core from '@actions/core';
import * as gpg from './gpg';
import * as constants from './constants';
async function run() {
if (core.getInput('gpg-private-key', {required: false})) {
console.log('removing private key from keychain');
if (core.getInput(constants.INPUT_GPG_PRIVATE_KEY, {required: false})) {
core.info('removing private key from keychain');
try {
const keyFingerprint = core.getState('gpg-private-key-fingerprint');
const keyFingerprint = core.getState(
constants.STATE_GPG_PRIVATE_KEY_FINGERPRINT
);
await gpg.deleteKey(keyFingerprint);
} catch (error) {
core.setFailed(error.message);

14
src/constants.ts Normal file
View File

@ -0,0 +1,14 @@
export const INPUT_VERSION = 'version';
export const INPUT_JAVA_VERSION = 'java-version';
export const INPUT_ARCHITECTURE = 'architecture';
export const INPUT_JAVA_PACKAGE = 'java-package';
export const INPUT_JDK_FILE = 'jdkFile';
export const INPUT_SERVER_ID = 'server-id';
export const INPUT_SERVER_USERNAME = 'server-username';
export const INPUT_SERVER_PASSWORD = 'server-password';
export const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
export const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
export const INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
export const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';

View File

@ -2,51 +2,57 @@ import * as core from '@actions/core';
import * as installer from './installer';
import * as auth from './auth';
import * as gpg from './gpg';
import * as constants from './constants';
import * as path from 'path';
const DEFAULT_ID = 'github';
const DEFAULT_USERNAME = 'GITHUB_ACTOR';
const DEFAULT_PASSWORD = 'GITHUB_TOKEN';
const DEFAULT_GPG_PRIVATE_KEY = undefined;
const DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
async function run() {
try {
let version = core.getInput('version');
let version = core.getInput(constants.INPUT_VERSION);
if (!version) {
version = core.getInput('java-version', {required: true});
version = core.getInput(constants.INPUT_JAVA_VERSION, {required: true});
}
const arch = core.getInput('architecture', {required: true});
const javaPackage = core.getInput('java-package', {required: true});
const jdkFile = core.getInput('jdkFile', {required: false}) || '';
const arch = core.getInput(constants.INPUT_ARCHITECTURE, {required: true});
const javaPackage = core.getInput(constants.INPUT_JAVA_PACKAGE, {
required: true
});
const jdkFile = core.getInput(constants.INPUT_JDK_FILE, {required: false});
await installer.getJava(version, arch, jdkFile, javaPackage);
const matchersPath = path.join(__dirname, '..', '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
const id = core.getInput('server-id', {required: false}) || DEFAULT_ID;
const username =
core.getInput('server-username', {required: false}) || DEFAULT_USERNAME;
const password =
core.getInput('server-password', {required: false}) || DEFAULT_PASSWORD;
const gpgPrivateKey =
core.getInput('gpg-private-key', {required: false}) ||
DEFAULT_GPG_PRIVATE_KEY;
const id = core.getInput(constants.INPUT_SERVER_ID, {required: false});
const username = core.getInput(constants.INPUT_SERVER_USERNAME, {
required: false
});
const password = core.getInput(constants.INPUT_SERVER_PASSWORD, {
required: false
});
const gpgPrivateKey = core.getInput(constants.INPUT_GPG_PRIVATE_KEY, {
required: false
});
const gpgPassphrase =
core.getInput('gpg-passphrase', {required: false}) ||
(gpgPrivateKey ? DEFAULT_GPG_PASSPHRASE : undefined);
core.getInput(constants.INPUT_GPG_PASSPHRASE, {required: false}) ||
(gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined);
if (gpgPrivateKey) {
core.setSecret(gpgPrivateKey);
}
if (gpgPassphrase) {
core.setSecret(gpgPassphrase);
}
await auth.configAuthentication(id, username, password, gpgPassphrase);
if (gpgPrivateKey) {
console.log('importing private key');
core.info('importing private key');
const keyFingerprint = (await gpg.importKey(gpgPrivateKey)) || '';
core.saveState('gpg-private-key-fingerprint', keyFingerprint);
core.saveState(
constants.STATE_GPG_PRIVATE_KEY_FINGERPRINT,
keyFingerprint
);
}
} catch (error) {
core.setFailed(error.message);