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

When running on a schedule, make a better guess about whether we're analyzing the default branch. #1211

Merged
merged 1 commit into from Aug 25, 2022

Conversation

chrisgavin
Copy link
Contributor

@chrisgavin chrisgavin commented Aug 25, 2022

When running on a schedule, the event payload does not contain any repository information such as the default branch name. This means we incorrectly say that we're not analyzing the default branch when we actually are.

Fortunately we know that when running on a schedule the event is triggered against the default branch, hence the default branch is in GITHUB_REF.

Note it's not quite sufficient to assume that just because the event was schedule we're analyzing the default branch though. The user may have configured the workflow to check out and analyze a different branch. Therefore we cannot just always return true when we're running on a schedule, we do have to still compare GITHUB_REF against any user-provided ref input.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary. (I'm assuming the changelog does not need to be updated, as this mostly only affects an feature that's not fully shipped yet, but let me know if you disagree.)

@chrisgavin chrisgavin marked this pull request as ready for review August 25, 2022 11:30
@chrisgavin chrisgavin requested a review from a team as a code owner August 25, 2022 11:30
Copy link
Contributor

@edoardopirovano edoardopirovano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding and fixing!

@chrisgavin chrisgavin merged commit 21bf308 into main Aug 25, 2022
@chrisgavin chrisgavin deleted the get-default-branch-correctly-schedule branch August 25, 2022 12:06
@github-actions github-actions bot mentioned this pull request Aug 25, 2022
6 tasks
Comment on lines +877 to +879
if (process.env.GITHUB_EVENT_NAME === "schedule") {
defaultBranch = removeRefsHeadsPrefix(getRequiredEnvParam("GITHUB_REF"));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit late on this, but aren't we guaranteed to be running on the default branch if we are in a scheduled run?

  if (process.env.GITHUB_EVENT_NAME === "schedule") {
    return true;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because you can always check out and analyze whatever you want. e.g. you could analyze all your release branches.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants