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

Check if on default branch before uploading database #563

Merged
merged 1 commit into from
Jun 16, 2021

Conversation

robertbrignull
Copy link
Contributor

(Note this is merging into a feature branch, and not into main)

We only want to upload a CodeQL database if analyzing the default branch, and this will avoid unnecessary uploads and help ensure we always have a recent database uploaded. For now we don't care about other branches and don't want them polluting the cache of databases for the default branch.

I initially thought we would have to check this on the github side, but turns out we can easily find out the default branch of the repository from the action.

I have tested this by running this branch of the action from a branch, a PR, and on master, and confirmed the behaviour in each case.

Copy link
Contributor

@rneatherway rneatherway left a comment

Choose a reason for hiding this comment

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

Perfect, looks good

@robertbrignull robertbrignull merged commit 366b68e into upload-database Jun 16, 2021
@robertbrignull robertbrignull deleted the robertbrignull/check_default_branch branch June 16, 2021 14:11
Comment on lines +704 to +706
const eventJson = JSON.parse(
fs.readFileSync(getRequiredEnvParam("GITHUB_EVENT_PATH"), "utf-8")
);
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 comment, but I'd suggest wrapping this in a try catch block, just in case the file doesn't exist or it's malformed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a huge deal as the file is supposed to be there, but this is just for safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, although what would it be able to do in this case? I think we'd be limited to just throwing an error with a better message, which is certainly still a valid thing to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

It might also be valid to return false, but probably safer to throw.

This was referenced Jun 21, 2021
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.

3 participants