Skip to content

Commit

Permalink
Add branch detection for more CI providers (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlewis authored Jan 23, 2023
1 parent af206b8 commit a9d3dc5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD

- Add support for GitHub Actions env vars (https://github.com/heroku/hatchet/pull/189)

## 7.4.0

- Supports "basic" scaledown (https://github.com/heroku/hatchet/pull/193)
Expand Down
9 changes: 9 additions & 0 deletions lib/hatchet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ module Hatchet
Runner = Hatchet::GitApp

def self.git_branch
# https://circleci.com/docs/variables
return ENV['CIRCLE_BRANCH'] if ENV['CIRCLE_BRANCH']
# https://docs.github.com/en/actions/learn-github-actions/environment-variables
# GITHUB_HEAD_REF is provided for PRs, but blank for branch actions.
return ENV['GITHUB_HEAD_REF'] if !ENV['GITHUB_HEAD_REF'].empty?
# GITHUB_REF_NAME is incorrect on PRs (`1371/merge`), but correct for branch actions.
return ENV['GITHUB_REF_NAME'] if ENV['GITHUB_REF_NAME']
# https://devcenter.heroku.com/articles/heroku-ci#immutable-environment-variables
return ENV['HEROKU_TEST_RUN_BRANCH'] if ENV['HEROKU_TEST_RUN_BRANCH']
# TRAVIS_BRANCH works fine unless the build is a pull-request. In that case, it will contain the target branch
# not the actual pull-request branch! TRAVIS_PULL_REQUEST_BRANCH contains the correct branch but will be empty
# for push builds. See: https://docs.travis-ci.com/user/environment-variables/
Expand Down
2 changes: 1 addition & 1 deletion lib/hatchet/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class App
"https://github.com/heroku/heroku-buildpack-ruby.git"
}
}
HATCHET_BUILDPACK_BRANCH = -> { ENV['HATCHET_BUILDPACK_BRANCH'] || ENV['HEROKU_TEST_RUN_BRANCH'] || Hatchet.git_branch }
HATCHET_BUILDPACK_BRANCH = -> { ENV['HATCHET_BUILDPACK_BRANCH'] || Hatchet.git_branch }

attr_reader :name, :stack, :repo_name, :app_config, :buildpacks, :reaper, :max_retries_count

Expand Down

0 comments on commit a9d3dc5

Please sign in to comment.