Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to provide a separate auth token vs. patcher update token #49

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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