-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the environment package. It currently contains one function that is used to determine whether or not the app is running in CI. For most popular CI products this assertion is made by including an environment variable called `CI`. IsCI checks for the existence of this environment variable. If it is set to true then we return a boolean true.
- Loading branch information
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Package environment provides helper methods for working with the | ||
// current environment. | ||
package environment | ||
|
||
import "os" | ||
|
||
// IsCI returns true if the CI environment variable is set to true. | ||
// This is used for most CI systems. | ||
func IsCI() bool { | ||
return os.Getenv("CI") == "true" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package environment_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/chelnak/gh-changelog/internal/environment" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsCIReturnsTrueWhenRunningInCI(t *testing.T) { | ||
_ = os.Setenv("CI", "true") | ||
defer func() { | ||
_ = os.Unsetenv("CI") | ||
}() | ||
assert.True(t, environment.IsCI()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters