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

fix branch returning incorrect value for GitHub Actions #29

Merged
merged 2 commits into from
Nov 2, 2019
Merged

fix branch returning incorrect value for GitHub Actions #29

merged 2 commits into from
Nov 2, 2019

Conversation

mohsinulhaq
Copy link
Contributor

Fixes #28

process.env.GITHUB_ACTIONS is set to true, which is the true check for GitHub actions environment.

image

For commits, I found no straightforward way to get the branch name.

@mohsinulhaq
Copy link
Contributor Author

https://help.github.com/en/articles/virtual-environments-for-github-actions#default-environment-variables
Although it says GITHUB_HEAD_REF is set only for forked repositories. I tried with my personal repository and it was always available for pull requests.

@mohsinulhaq
Copy link
Contributor Author

@siddharthkp can we merge this?

@kuldeepkeshwar
Copy link
Collaborator

@mohsinulhaq I couldn't find GITHUB_ACTIONS anywhere in docs. They might be using it for internal purpose.
whereas GITHUB_ACTION is always set to a unique id(IMO it is better to rely on GITHUB_ACTION).

@kuldeepkeshwar
Copy link
Collaborator

@mohsinulhaq Thanks 👍

@kuldeepkeshwar kuldeepkeshwar merged commit 641da79 into siddharthkp:master Nov 2, 2019
@mohsinulhaq
Copy link
Contributor Author

@kuldeepkeshwar can you also review this one: siddharthkp/bundlesize#349
both PRs are kinda related

@kuldeepkeshwar
Copy link
Collaborator

@mohsinulhaq I am sorry I don't have complete context here('bundlesize'). @Haroenv maybe the right person to complete the review.

PS still I will give it a try

@mohsinulhaq
Copy link
Contributor Author

@kuldeepkeshwar can we have a new release with the fix? It's blocking our github actions pull request discovery.

@@ -79,7 +79,8 @@ if (process.env.TRAVIS) {
event = process.env.GITHUB_EVENT_NAME
commit_message = ''
pull_request_number = ''
branch = process.env.GITHUB_REF
// GITHUB_HEAD_REF for pull requests. For commits, GITHUB_REF is of the form refs/heads/master, for example
branch = process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF && process.env.GITHUB_REF.split('/')[2]
Copy link

Choose a reason for hiding this comment

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

Fwiw, process.env.GITHUB_REF.split('/')[2] will almost certainly break various things.

By default, @dependabot uses / a lot in its branch names:

Dependabot generates a branch for each pull request. Each branch name includes dependabot, and the package manager and dependency that are updated. By default, these parts are separated by a / symbol, for example: dependabot/npm_and_yarn/next_js/acorn-6.4.1.

https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates#pull-request-branch-nameseparator

(And random people can use it as well, especially people in large organizations.)

I'm only mentioning this because my GitHub workflow broke when someone used / and I didn't have the right branch flags...

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.

branch not returning the expected value for GitHub Actions
3 participants