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
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
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ if (process.env.TRAVIS) {

event = 'push'
pull_request_number = process.env.CI_PR_NUMBER
sha=process.env.CI_COMMIT_ID,
sha=process.env.CI_COMMIT_ID,
buildUrl=process.env.CI_BUILD_URL

ci = 'codeship'
} else if (process.env.GITHUB_ACTION) {
// GitHub Actions
Expand All @@ -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...

ci = 'github_actions'
} else if (process.env.NETLIFY) {
// Reference: https://www.netlify.com/docs/continuous-deployment/#environment-variables
Expand Down