Skip to content

Commit

Permalink
Merge pull request #49 from gruntwork-io/caitlin/update-token
Browse files Browse the repository at this point in the history
Add the ability to provide a separate auth token vs. patcher update token
  • Loading branch information
ceschae authored Nov 15, 2024
2 parents d8e117a + fc47115 commit b1d692e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
24 changes: 15 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13703,12 +13703,12 @@ function getPatcherEnvVars(gitCommiter, token) {
GIT_AUTHOR_EMAIL: gitCommiter.email,
};
}
async function runPatcher(gitCommiter, command, { specFile, includeDirs, excludeDirs, updateStrategy, prBranch, prTitle, dependency, workingDir, token, dryRun, noColor, }) {
async function runPatcher(gitCommiter, command, { specFile, includeDirs, excludeDirs, updateStrategy, prBranch, prTitle, dependency, workingDir, updateToken, dryRun, noColor, }) {
switch (command) {
case REPORT_COMMAND: {
core.startGroup("Running 'patcher report'");
const reportOutput = await exec.getExecOutput("patcher", reportArgs(specFile, includeDirs, excludeDirs, workingDir, noColor), {
env: getPatcherEnvVars(gitCommiter, token),
env: getPatcherEnvVars(gitCommiter, updateToken),
});
core.endGroup();
core.startGroup("Setting upgrade spec output");
Expand All @@ -13729,7 +13729,7 @@ async function runPatcher(gitCommiter, command, { specFile, includeDirs, exclude
}
core.startGroup(groupName);
const updateOutput = await exec.getExecOutput("patcher", updateArgs(specFile, updateStrategy, prBranch, prTitle, dependency, workingDir, dryRun, noColor), {
env: getPatcherEnvVars(gitCommiter, token),
env: getPatcherEnvVars(gitCommiter, updateToken),
});
core.endGroup();
core.startGroup("Setting 'updateResult' output");
Expand Down Expand Up @@ -13768,7 +13768,8 @@ async function validateAccessToPatcherCli(octokit) {
}
}
async function run() {
const token = core.getInput("github_token");
const gruntworkToken = core.getInput("github_token");
const patcherUpdateToken = core.getInput("update_token");
const command = core.getInput("patcher_command");
const updateStrategy = core.getInput("update_strategy");
const dependency = core.getInput("dependency");
Expand All @@ -13781,10 +13782,15 @@ async function run() {
const prTitle = core.getInput("pull_request_title");
const dryRun = core.getBooleanInput("dry_run");
const noColor = core.getBooleanInput("no_color");
// Always mask the `token` string in the logs.
core.setSecret(token);
// if the user didn't specify a token specifically for `patcher update`,
// that's ok, we can try to use the github token instead. doing this adoption
// is for back compatibility reasons
const updateToken = patcherUpdateToken ? patcherUpdateToken : gruntworkToken;
// Always mask the token strings in the logs.
core.setSecret(gruntworkToken);
core.setSecret(updateToken);
// Only run the action if the user has access to Patcher. Otherwise, the download won't work.
const octokit = github.getOctokit(token);
const octokit = github.getOctokit(gruntworkToken);
await validateAccessToPatcherCli(octokit);
// Validate if the 'patcher_command' provided is valid.
if (!isPatcherCommandValid(command)) {
Expand All @@ -13794,7 +13800,7 @@ async function run() {
// Validate if 'commit_author' has a valid format.
const gitCommiter = parseCommitAuthor(commitAuthor);
core.startGroup("Downloading Patcher and patch tools");
await downloadAndSetupTooling(octokit, token);
await downloadAndSetupTooling(octokit, gruntworkToken);
core.endGroup();
await runPatcher(gitCommiter, command, {
specFile,
Expand All @@ -13805,7 +13811,7 @@ async function run() {
prTitle,
dependency,
workingDir,
token,
updateToken,
dryRun,
noColor,
});
Expand Down
27 changes: 17 additions & 10 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type PatcherCliArgs = {
prTitle: string;
dependency: string;
workingDir: string;
token: string;
updateToken: string;
dryRun: boolean;
noColor: boolean;
};
Expand Down Expand Up @@ -289,7 +289,7 @@ async function runPatcher(
prTitle,
dependency,
workingDir,
token,
updateToken,
dryRun,
noColor,
}: PatcherCliArgs
Expand All @@ -301,7 +301,7 @@ async function runPatcher(
"patcher",
reportArgs(specFile, includeDirs, excludeDirs, workingDir, noColor),
{
env: getPatcherEnvVars(gitCommiter, token),
env: getPatcherEnvVars(gitCommiter, updateToken),
}
);
core.endGroup();
Expand Down Expand Up @@ -329,7 +329,7 @@ async function runPatcher(
"patcher",
updateArgs(specFile, updateStrategy, prBranch, prTitle, dependency, workingDir, dryRun, noColor),
{
env: getPatcherEnvVars(gitCommiter, token),
env: getPatcherEnvVars(gitCommiter, updateToken),
}
);
core.endGroup();
Expand Down Expand Up @@ -379,7 +379,8 @@ async function validateAccessToPatcherCli(octokit: GitHub) {
}

export async function run() {
const token = core.getInput("github_token");
const gruntworkToken = core.getInput("github_token");
const patcherUpdateToken = core.getInput("update_token");
const command = core.getInput("patcher_command");
const updateStrategy = core.getInput("update_strategy");
const dependency = core.getInput("dependency");
Expand All @@ -393,11 +394,17 @@ export async function run() {
const dryRun = core.getBooleanInput("dry_run");
const noColor = core.getBooleanInput("no_color");

// Always mask the `token` string in the logs.
core.setSecret(token);
// if the user didn't specify a token specifically for `patcher update`,
// that's ok, we can try to use the github token instead. doing this adoption
// is for back compatibility reasons
const updateToken = patcherUpdateToken ? patcherUpdateToken : gruntworkToken;

// Always mask the token strings in the logs.
core.setSecret(gruntworkToken);
core.setSecret(updateToken);

// Only run the action if the user has access to Patcher. Otherwise, the download won't work.
const octokit = github.getOctokit(token);
const octokit = github.getOctokit(gruntworkToken);
await validateAccessToPatcherCli(octokit);

// Validate if the 'patcher_command' provided is valid.
Expand All @@ -410,7 +417,7 @@ export async function run() {
const gitCommiter = parseCommitAuthor(commitAuthor);

core.startGroup("Downloading Patcher and patch tools");
await downloadAndSetupTooling(octokit, token);
await downloadAndSetupTooling(octokit, gruntworkToken);
core.endGroup();

await runPatcher(gitCommiter, command, {
Expand All @@ -422,7 +429,7 @@ export async function run() {
prTitle,
dependency,
workingDir,
token,
updateToken,
dryRun,
noColor,
});
Expand Down

0 comments on commit b1d692e

Please sign in to comment.