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

Commit

Permalink
feat: Add run_for_branch option (#8)
Browse files Browse the repository at this point in the history
We want to be able to run the action on release branches as well.
This adds a new option` run_for_branch` which can be set to overwrite the default `isMainBranch` detection.

When this is set to `'true'`, it will run size limit for the given branch without any comparison. Set it to unset or `''` to revert to the default main branch detection.
  • Loading branch information
mydea authored Feb 20, 2023
1 parent 6c57d92 commit ef0a56c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ inputs:
required: false
default: master
description: "The name of the main/protected branch"
run_for_branch:
required: false
description: "This can be set to override the `main_branch` detection."
threshold:
required: false
default: 0.0125
Expand Down
13 changes: 9 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21925,8 +21925,13 @@ function run() {
const { payload, repo } = github_1.context;
const pr = payload.pull_request;
const mainBranch = getInput("main_branch");
const isMainBranch = github_1.context.ref.includes(mainBranch);
if (!isMainBranch && !pr) {
const runForBranchInput = getInput("run_for_branch");
const runForBranch = runForBranchInput === "true"
? true
: runForBranchInput === "false"
? false
: github_1.context.ref.includes(mainBranch);
if (!runForBranch && !pr) {
throw new Error("No PR found. Only pull_request workflows are supported.");
}
const skipStep = getInput("skip_step");
Expand All @@ -21941,7 +21946,7 @@ function run() {
const limit = new SizeLimit_1.default();
const artifactClient = artifact.create();
const resultsFilePath = path_1.default.resolve(__dirname, RESULTS_FILE);
if (isMainBranch) {
if (runForBranch) {
let base;
const { output: baseOutput } = yield term.execSizeLimit(skipStep, buildScript, cleanScript, windowsVerbatimArguments, directory);
try {
Expand Down Expand Up @@ -21969,7 +21974,7 @@ function run() {
try {
// Ignore failures here as it is likely that this only happens when introducing size-limit
// and this has not been run on the main branch yet
yield (0, github_fetch_workflow_artifact_1.default)(octokit, Object.assign(Object.assign({}, repo), { artifactName: ARTIFACT_NAME, branch: mainBranch, downloadPath: __dirname, workflowEvent: 'push', workflowName: `${process.env.GITHUB_WORKFLOW || ""}` }));
yield (0, github_fetch_workflow_artifact_1.default)(octokit, Object.assign(Object.assign({}, repo), { artifactName: ARTIFACT_NAME, branch: mainBranch, downloadPath: __dirname, workflowEvent: "push", workflowName: `${process.env.GITHUB_WORKFLOW || ""}` }));
base = JSON.parse(yield fs_1.promises.readFile(resultsFilePath, { encoding: "utf8" }));
}
catch (error) {
Expand Down
15 changes: 11 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@ async function run() {
const { payload, repo } = context;
const pr = payload.pull_request;
const mainBranch = getInput("main_branch");
const isMainBranch = context.ref.includes(mainBranch);
const runForBranchInput = getInput("run_for_branch");

if (!isMainBranch && !pr) {
const runForBranch =
runForBranchInput === "true"
? true
: runForBranchInput === "false"
? false
: context.ref.includes(mainBranch);

if (!runForBranch && !pr) {
throw new Error(
"No PR found. Only pull_request workflows are supported."
);
Expand All @@ -63,7 +70,7 @@ async function run() {
const artifactClient = artifact.create();
const resultsFilePath = path.resolve(__dirname, RESULTS_FILE);

if (isMainBranch) {
if (runForBranch) {
let base;
const { output: baseOutput } = await term.execSizeLimit(
skipStep,
Expand Down Expand Up @@ -108,7 +115,7 @@ async function run() {
artifactName: ARTIFACT_NAME,
branch: mainBranch,
downloadPath: __dirname,
workflowEvent: 'push',
workflowEvent: "push",
workflowName: `${process.env.GITHUB_WORKFLOW || ""}`,
});
base = JSON.parse(
Expand Down

0 comments on commit ef0a56c

Please sign in to comment.