Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Check for required input variables
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Dec 16, 2019
1 parent 8476771 commit 7a8fe4c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,48 @@ const MAVEN_SETTINGS_PATH = path.join(__dirname, "settings.xml");
*/
const log = msg => console.log(`\n${msg}`); // eslint-disable-line no-console

/**
* Exits the current process with an error code and message
*/
const exit = msg => {
console.error(msg);
process.exit(1);
};

/**
* Executes the provided shell command and redirects stdout/stderr to the console
*/
const run = cmd => execSync(cmd, { encoding: "utf8", stdio: "inherit" });

/**
* Returns the value for an environment variable (or `null` if it's not defined)
*/
const getEnv = name => process.env[name.toUpperCase()] || null;

/**
* Returns the value for an input variable (or `null` if it's not defined). If the variable is
* required and doesn't have a value, abort the action
*/
const getInput = (name, required) => {
const value = getEnv(`INPUT_${name}`);
if (required && !value) {
exit(`"${name}" input variable is not defined`);
}
return value;
};

/**
* Runs the deployment
*/
const runAction = () => {
// Make sure the required input variables are provided
getInput("gpg_passphrase", true);
getInput("nexus_username", true);
getInput("nexus_password", true);

// Import GPG key into keychain
log("Importing GPG key…");
writeFileSync(GPG_KEY_PATH, process.env.INPUT_GPG_PRIVATE_KEY);
writeFileSync(GPG_KEY_PATH, getInput("gpg_private_key", true));
run(`gpg --import --batch ${GPG_KEY_PATH}`);
unlinkSync(GPG_KEY_PATH);

Expand Down

0 comments on commit 7a8fe4c

Please sign in to comment.