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

@ -16,7 +16,7 @@ import gpg = require('../src/gpg');
describe('gpg tests', () => { describe('gpg tests', () => {
beforeEach(async () => { beforeEach(async () => {
await io.mkdirP(tempDir); await io.mkdirP(tempDir);
}, 300000); });
afterAll(async () => { afterAll(async () => {
try { try {

View File

@ -21,18 +21,22 @@ inputs:
description: 'Path to where the compressed JDK is located. The path could description: 'Path to where the compressed JDK is located. The path could
be in your source repository or a local path on the agent.' be in your source repository or a local path on the agent.'
required: false required: false
default: ''
server-id: server-id:
description: 'ID of the distributionManagement repository in the pom.xml description: 'ID of the distributionManagement repository in the pom.xml
file. Default is `github`' file. Default is `github`'
required: false required: false
default: 'github'
server-username: server-username:
description: 'Environment variable name for the username for authentication description: 'Environment variable name for the username for authentication
to the Apache Maven repository. Default is $GITHUB_ACTOR' to the Apache Maven repository. Default is $GITHUB_ACTOR'
required: false required: false
default: 'GITHUB_ACTOR'
server-password: server-password:
description: 'Environment variable name for password or token for description: 'Environment variable name for password or token for
authentication to the Apache Maven repository. Default is $GITHUB_TOKEN' authentication to the Apache Maven repository. Default is $GITHUB_TOKEN'
required: false required: false
default: 'GITHUB_TOKEN'
settings-path: settings-path:
description: 'Path to where the settings.xml file will be written. Default is ~/.m2.' description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
required: false required: false
@ -43,6 +47,7 @@ inputs:
description: 'Environment variable name for the GPG private key passphrase. Default is description: 'Environment variable name for the GPG private key passphrase. Default is
$GPG_PASSPHRASE.' $GPG_PASSPHRASE.'
required: false required: false
default: 'GPG_PASSHPRASE'
outputs: outputs:
path: path:
description: 'Path to where the java environment has been installed (same as $JAVA_HOME)' description: 'Path to where the java environment has been installed (same as $JAVA_HOME)'

29
dist/cleanup/index.js vendored
View File

@ -946,6 +946,28 @@ module.exports = require("os");
module.exports = require("child_process"); module.exports = require("child_process");
/***/ }),
/***/ 211:
/***/ (function(__unusedmodule, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.INPUT_VERSION = 'version';
exports.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_ARCHITECTURE = 'architecture';
exports.INPUT_JAVA_PACKAGE = 'java-package';
exports.INPUT_JDK_FILE = 'jdkFile';
exports.INPUT_SERVER_ID = 'server-id';
exports.INPUT_SERVER_USERNAME = 'server-username';
exports.INPUT_SERVER_PASSWORD = 'server-password';
exports.INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
exports.INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
exports.INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
/***/ }), /***/ }),
/***/ 219: /***/ 219:
@ -972,12 +994,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const gpg = __importStar(__webpack_require__(884)); const gpg = __importStar(__webpack_require__(884));
const constants = __importStar(__webpack_require__(211));
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (core.getInput('gpg-private-key', { required: false })) { if (core.getInput(constants.INPUT_GPG_PRIVATE_KEY, { required: false })) {
console.log('removing private key from keychain'); core.info('removing private key from keychain');
try { try {
const keyFingerprint = core.getState('gpg-private-key-fingerprint'); const keyFingerprint = core.getState(constants.STATE_GPG_PRIVATE_KEY_FINGERPRINT);
yield gpg.deleteKey(keyFingerprint); yield gpg.deleteKey(keyFingerprint);
} }
catch (error) { catch (error) {

68
dist/setup/index.js vendored
View File

@ -25645,6 +25645,28 @@ function range(n, m) {
exports.range = range; exports.range = range;
//# sourceMappingURL=Set.js.map //# sourceMappingURL=Set.js.map
/***/ }),
/***/ 694:
/***/ (function(__unusedmodule, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.INPUT_VERSION = 'version';
exports.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_ARCHITECTURE = 'architecture';
exports.INPUT_JAVA_PACKAGE = 'java-package';
exports.INPUT_JDK_FILE = 'jdkFile';
exports.INPUT_SERVER_ID = 'server-id';
exports.INPUT_SERVER_USERNAME = 'server-username';
exports.INPUT_SERVER_PASSWORD = 'server-password';
exports.INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
exports.INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
exports.INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
/***/ }), /***/ }),
/***/ 695: /***/ 695:
@ -28650,40 +28672,46 @@ const core = __importStar(__webpack_require__(470));
const installer = __importStar(__webpack_require__(923)); const installer = __importStar(__webpack_require__(923));
const auth = __importStar(__webpack_require__(331)); const auth = __importStar(__webpack_require__(331));
const gpg = __importStar(__webpack_require__(884)); const gpg = __importStar(__webpack_require__(884));
const constants = __importStar(__webpack_require__(694));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
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';
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
let version = core.getInput('version'); let version = core.getInput(constants.INPUT_VERSION);
if (!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 arch = core.getInput(constants.INPUT_ARCHITECTURE, { required: true });
const javaPackage = core.getInput('java-package', { required: true }); const javaPackage = core.getInput(constants.INPUT_JAVA_PACKAGE, {
const jdkFile = core.getInput('jdkFile', { required: false }) || ''; required: true
});
const jdkFile = core.getInput(constants.INPUT_JDK_FILE, { required: false });
yield installer.getJava(version, arch, jdkFile, javaPackage); yield installer.getJava(version, arch, jdkFile, javaPackage);
const matchersPath = path.join(__dirname, '..', '..', '.github'); 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 id = core.getInput(constants.INPUT_SERVER_ID, { required: false });
const username = core.getInput('server-username', { required: false }) || DEFAULT_USERNAME; const username = core.getInput(constants.INPUT_SERVER_USERNAME, {
const password = core.getInput('server-password', { required: false }) || DEFAULT_PASSWORD; required: false
const gpgPrivateKey = core.getInput('gpg-private-key', { required: false }) || });
DEFAULT_GPG_PRIVATE_KEY; const password = core.getInput(constants.INPUT_SERVER_PASSWORD, {
const gpgPassphrase = core.getInput('gpg-passphrase', { required: false }) || required: false
(gpgPrivateKey ? DEFAULT_GPG_PASSPHRASE : undefined); });
const gpgPrivateKey = core.getInput(constants.INPUT_GPG_PRIVATE_KEY, {
required: false
});
const gpgPassphrase = core.getInput(constants.INPUT_GPG_PASSPHRASE, { required: false }) ||
(gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined);
if (gpgPrivateKey) { if (gpgPrivateKey) {
core.setSecret(gpgPrivateKey); core.setSecret(gpgPrivateKey);
} }
if (gpgPassphrase) {
core.setSecret(gpgPassphrase);
}
yield auth.configAuthentication(id, username, password, gpgPassphrase); yield auth.configAuthentication(id, username, password, gpgPassphrase);
if (gpgPrivateKey) { if (gpgPrivateKey) {
console.log('importing private key'); core.info('importing private key');
const keyFingerprint = (yield gpg.importKey(gpgPrivateKey)) || ''; const keyFingerprint = (yield gpg.importKey(gpgPrivateKey)) || '';
core.saveState('gpg-private-key-fingerprint', keyFingerprint); core.saveState(constants.STATE_GPG_PRIVATE_KEY_FINGERPRINT, keyFingerprint);
} }
} }
catch (error) { catch (error) {

View File

@ -1,11 +1,14 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as gpg from './gpg'; import * as gpg from './gpg';
import * as constants from './constants';
async function run() { async function run() {
if (core.getInput('gpg-private-key', {required: false})) { if (core.getInput(constants.INPUT_GPG_PRIVATE_KEY, {required: false})) {
console.log('removing private key from keychain'); core.info('removing private key from keychain');
try { try {
const keyFingerprint = core.getState('gpg-private-key-fingerprint'); const keyFingerprint = core.getState(
constants.STATE_GPG_PRIVATE_KEY_FINGERPRINT
);
await gpg.deleteKey(keyFingerprint); await gpg.deleteKey(keyFingerprint);
} catch (error) { } catch (error) {
core.setFailed(error.message); 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 installer from './installer';
import * as auth from './auth'; import * as auth from './auth';
import * as gpg from './gpg'; import * as gpg from './gpg';
import * as constants from './constants';
import * as path from 'path'; 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() { async function run() {
try { try {
let version = core.getInput('version'); let version = core.getInput(constants.INPUT_VERSION);
if (!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 arch = core.getInput(constants.INPUT_ARCHITECTURE, {required: true});
const javaPackage = core.getInput('java-package', {required: true}); const javaPackage = core.getInput(constants.INPUT_JAVA_PACKAGE, {
const jdkFile = core.getInput('jdkFile', {required: false}) || ''; required: true
});
const jdkFile = core.getInput(constants.INPUT_JDK_FILE, {required: false});
await installer.getJava(version, arch, jdkFile, javaPackage); await installer.getJava(version, arch, jdkFile, javaPackage);
const matchersPath = path.join(__dirname, '..', '..', '.github'); 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 id = core.getInput(constants.INPUT_SERVER_ID, {required: false});
const username = const username = core.getInput(constants.INPUT_SERVER_USERNAME, {
core.getInput('server-username', {required: false}) || DEFAULT_USERNAME; required: false
const password = });
core.getInput('server-password', {required: false}) || DEFAULT_PASSWORD; const password = core.getInput(constants.INPUT_SERVER_PASSWORD, {
const gpgPrivateKey = required: false
core.getInput('gpg-private-key', {required: false}) || });
DEFAULT_GPG_PRIVATE_KEY; const gpgPrivateKey = core.getInput(constants.INPUT_GPG_PRIVATE_KEY, {
required: false
});
const gpgPassphrase = const gpgPassphrase =
core.getInput('gpg-passphrase', {required: false}) || core.getInput(constants.INPUT_GPG_PASSPHRASE, {required: false}) ||
(gpgPrivateKey ? DEFAULT_GPG_PASSPHRASE : undefined); (gpgPrivateKey ? constants.INPUT_DEFAULT_GPG_PASSPHRASE : undefined);
if (gpgPrivateKey) { if (gpgPrivateKey) {
core.setSecret(gpgPrivateKey); core.setSecret(gpgPrivateKey);
} }
if (gpgPassphrase) {
core.setSecret(gpgPassphrase);
}
await auth.configAuthentication(id, username, password, gpgPassphrase); await auth.configAuthentication(id, username, password, gpgPassphrase);
if (gpgPrivateKey) { if (gpgPrivateKey) {
console.log('importing private key'); core.info('importing private key');
const keyFingerprint = (await gpg.importKey(gpgPrivateKey)) || ''; const keyFingerprint = (await gpg.importKey(gpgPrivateKey)) || '';
core.saveState('gpg-private-key-fingerprint', keyFingerprint); core.saveState(
constants.STATE_GPG_PRIVATE_KEY_FINGERPRINT,
keyFingerprint
);
} }
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);