Skip to content

Commit

Permalink
Merge pull request #38 from kichristensen/changeToGithub
Browse files Browse the repository at this point in the history
Change from Azure DevOps environment variables to Github environment variables
  • Loading branch information
schristoff authored May 9, 2024
2 parents 9816193 + a91957a commit b12b395
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions releases/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ func getBranchName() string {
func pickBranchName(refs []string) string {
var branch string

if b, ok := os.LookupEnv("SYSTEM_PULLREQUEST_SOURCEBRANCH"); ok {
if b, ok := os.LookupEnv("GITHUB_HEAD_REF"); ok {
// pull request
branch = b
} else if b, ok := os.LookupEnv("BUILD_SOURCEBRANCH"); ok && !strings.HasPrefix(b, "refs/tags/") {
} else if b, ok := os.LookupEnv("GITHUB_REF"); ok && !strings.HasPrefix(b, "refs/tags/") {
// branch build
// BUILD_SOURCEBRANCHNAME has the short name, e.g. main. BUILD_SOURCEBRANCH has the full name, e.g. refs/heads/main
// GITHUB_REF_NAME has the short name, e.g. main. GITHUB_REF has the full name, e.g. refs/heads/main
// They are populated for both tags and branches
branch = os.Getenv("BUILD_SOURCEBRANCHNAME")
branch = os.Getenv("GITHUB_REF_NAME")
} else {
// tag build
// Detect if this was a tag on main or a release
Expand Down Expand Up @@ -138,7 +138,7 @@ func pickBranchName(refs []string) string {

func getPermalink() (string, bool) {
// Use dev for pull requests
if _, pr := os.LookupEnv("SYSTEM_PULLREQUEST_SOURCEBRANCH"); pr {
if _, pr := os.LookupEnv("GITHUB_HEAD_REF"); pr {
return "dev", false
}

Expand Down
34 changes: 17 additions & 17 deletions releases/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

func TestPickBranchName(t *testing.T) {
// These aren't set locally but are set on a CI run
os.Unsetenv("SYSTEM_PULLREQUEST_SOURCEBRANCH")
os.Unsetenv("BUILD_SOURCEBRANCHNAME")
os.Unsetenv("BUILD_SOURCEBRANCH")
os.Unsetenv("GITHUB_HEAD_REF")
os.Unsetenv("GITHUB_REF_NAME")
os.Unsetenv("GITHUB_REF")

t.Run("origin/main", func(t *testing.T) {
refs := []string{
Expand All @@ -36,8 +36,8 @@ func TestPickBranchName(t *testing.T) {
})

t.Run("pull request", func(t *testing.T) {
os.Setenv("SYSTEM_PULLREQUEST_SOURCEBRANCH", "patch-1")
defer os.Unsetenv("SYSTEM_PULLREQUEST_SOURCEBRANCH")
os.Setenv("GITHUB_HEAD_REF", "patch-1")
defer os.Unsetenv("GITHUB_HEAD_REF")

refs := []string{
"refs/remotes/origin/foo",
Expand All @@ -48,10 +48,10 @@ func TestPickBranchName(t *testing.T) {
})

t.Run("branch build", func(t *testing.T) {
os.Setenv("BUILD_SOURCEBRANCHNAME", "foo")
os.Setenv("BUILD_SOURCEBRANCH", "refs/heads/foo")
defer os.Unsetenv("BUILD_SOURCEBRANCHNAME")
defer os.Unsetenv("BUILD_SOURCEBRANCH")
os.Setenv("GITHUB_REF_NAME", "foo")
os.Setenv("GITHUB_REF", "refs/heads/foo")
defer os.Unsetenv("GITHUB_REF_NAME")
defer os.Unsetenv("GITHUB_REF")

refs := []string{
"refs/remotes/origin/foo",
Expand All @@ -62,10 +62,10 @@ func TestPickBranchName(t *testing.T) {
})

t.Run("tagged release on v1", func(t *testing.T) {
os.Setenv("BUILD_SOURCEBRANCHNAME", "v1.0.0-alpha.1")
os.Setenv("BUILD_SOURCEBRANCH", "refs/tags/v1.0.0-alpha.1")
defer os.Unsetenv("BUILD_SOURCEBRANCHNAME")
defer os.Unsetenv("BUILD_SOURCEBRANCH")
os.Setenv("GITHUB_REF_NAME", "v1.0.0-alpha.1")
os.Setenv("GITHUB_REF", "refs/tags/v1.0.0-alpha.1")
defer os.Unsetenv("GITHUB_REF_NAME")
defer os.Unsetenv("GITHUB_REF")

refs := []string{
"refs/heads/release/v1",
Expand All @@ -77,10 +77,10 @@ func TestPickBranchName(t *testing.T) {
})

t.Run("tagged release on main", func(t *testing.T) {
os.Setenv("BUILD_SOURCEBRANCHNAME", "v0.38.3")
os.Setenv("BUILD_SOURCEBRANCH", "refs/tags/v0.38.3")
defer os.Unsetenv("BUILD_SOURCEBRANCHNAME")
defer os.Unsetenv("BUILD_SOURCEBRANCH")
os.Setenv("GITHUB_REF_NAME", "v0.38.3")
os.Setenv("GITHUB_REF", "refs/tags/v0.38.3")
defer os.Unsetenv("GITHUB_REF_NAME")
defer os.Unsetenv("GITHUB_REF")

refs := []string{
"refs/heads/release/v1",
Expand Down

0 comments on commit b12b395

Please sign in to comment.