-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #565 from jbenet/ci-pkgs
testutil ci pkgs check env vars
- Loading branch information
Showing
10 changed files
with
217 additions
and
21 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
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
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
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
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
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,52 @@ | ||
// Package ci implements some helper functions to use during | ||
// tests. Many times certain facilities are not available, or tests | ||
// must run differently. | ||
package ci | ||
|
||
import ( | ||
"os" | ||
|
||
jenkins "github.com/jbenet/go-ipfs/util/testutil/ci/jenkins" | ||
travis "github.com/jbenet/go-ipfs/util/testutil/ci/travis" | ||
) | ||
|
||
// EnvVar is a type to use travis-only env var names with | ||
// the type system. | ||
type EnvVar string | ||
|
||
// Environment variables that TravisCI uses. | ||
const ( | ||
VarCI EnvVar = "TEST_NO_FUSE" | ||
VarNoFuse EnvVar = "TEST_NO_FUSE" | ||
VarVerbose EnvVar = "TEST_VERBOSE" | ||
) | ||
|
||
// IsRunning attempts to determine whether this process is | ||
// running on CI. This is done by checking any of: | ||
// | ||
// CI=true | ||
// travis.IsRunning() | ||
// jenkins.IsRunning() | ||
// | ||
func IsRunning() bool { | ||
if os.Getenv(string(VarCI)) == "true" { | ||
return true | ||
} | ||
|
||
return travis.IsRunning() || jenkins.IsRunning() | ||
} | ||
|
||
// Env returns the value of a CI env variable. | ||
func Env(v EnvVar) string { | ||
return os.Getenv(string(v)) | ||
} | ||
|
||
// Returns whether FUSE is explicitly disabled wiht TEST_NO_FUSE. | ||
func NoFuse() bool { | ||
return os.Getenv(string(VarNoFuse)) == "1" | ||
} | ||
|
||
// Returns whether TEST_VERBOSE is enabled. | ||
func Verbose() bool { | ||
return os.Getenv(string(VarVerbose)) == "1" | ||
} |
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,58 @@ | ||
// Package jenkins implements some helper functions to use during | ||
// tests. Many times certain facilities are not available, or tests | ||
// must run differently. | ||
package jenkins | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
// EnvVar is a type to use travis-only env var names with | ||
// the type system. | ||
type EnvVar string | ||
|
||
// Environment variables that Jenkins uses. | ||
const ( | ||
VarBuildNumber EnvVar = "BUILD_NUMBER" | ||
VarBuildId EnvVar = "BUILD_ID" | ||
VarBuildUrl EnvVar = "BUILD_URL" | ||
VarNodeName EnvVar = "NODE_NAME" | ||
VarJobName EnvVar = "JOB_NAME" | ||
VarBuildTag EnvVar = "BUILD_TAG" | ||
VarJenkinsUrl EnvVar = "JENKINS_URL" | ||
VarExecutorNumber EnvVar = "EXECUTOR_NUMBER" | ||
VarJavaHome EnvVar = "JAVA_HOME" | ||
VarWorkspace EnvVar = "WORKSPACE" | ||
VarSvnRevision EnvVar = "SVN_REVISION" | ||
VarCvsBranch EnvVar = "CVS_BRANCH" | ||
VarGitCommit EnvVar = "GIT_COMMIT" | ||
VarGitUrl EnvVar = "GIT_URL" | ||
VarGitBranch EnvVar = "GIT_BRANCH" | ||
) | ||
|
||
// IsRunning attempts to determine whether this process is | ||
// running on Jenkins CI. This is done by checking any of the | ||
// following: | ||
// | ||
// JENKINS_URL is set | ||
// BuildTag has prefix "jenkins-" | ||
// | ||
func IsRunning() bool { | ||
return len(Env(VarJenkinsUrl)) > 0 || strings.HasPrefix(Env(VarBuildTag), "jenkins-") | ||
} | ||
|
||
// Env returns the value of a travis env variable. | ||
func Env(v EnvVar) string { | ||
return os.Getenv(string(v)) | ||
} | ||
|
||
// JobName returns the jenkins JOB_NAME of this build. | ||
func JobName() string { | ||
return Env(VarJobName) | ||
} | ||
|
||
// BuildTag returns the jenkins BUILD_TAG. | ||
func BuildTag() string { | ||
return Env(VarBuildTag) | ||
} |
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,16 @@ | ||
package jenkins | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestIsRunning(t *testing.T) { | ||
hasPrefix := strings.HasPrefix(os.Getenv("BUILD_TAG"), "jenkins-") | ||
tr := len(os.Getenv("JENKINS_URL")) > 0 || hasPrefix | ||
|
||
if tr != IsRunning() { | ||
t.Error("IsRunning() does not match TRAVIS && CI env var check") | ||
} | ||
} |
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,57 @@ | ||
// Package travis implements some helper functions to use during | ||
// tests. Many times certain facilities are not available, or tests | ||
// must run differently. | ||
package travis | ||
|
||
import "os" | ||
|
||
// EnvVar is a type to use travis-only env var names with | ||
// the type system. | ||
type EnvVar string | ||
|
||
// Environment variables that TravisCI uses. | ||
const ( | ||
VarCI EnvVar = "CI" | ||
VarTravis EnvVar = "TRAVIS" | ||
VarBranch EnvVar = "TRAVIS_BRANCH" | ||
VarBuildDir EnvVar = "TRAVIS_BUILD_DIR" | ||
VarBuildId EnvVar = "TRAVIS_BUILD_ID" | ||
VarBuildNumber EnvVar = "TRAVIS_BUILD_NUMBER" | ||
VarCommit EnvVar = "TRAVIS_COMMIT" | ||
VarCommitRange EnvVar = "TRAVIS_COMMIT_RANGE" | ||
VarJobId EnvVar = "TRAVIS_JOB_ID" | ||
VarJobNumber EnvVar = "TRAVIS_JOB_NUMBER" | ||
VarPullRequest EnvVar = "TRAVIS_PULL_REQUEST" | ||
VarSecureEnvVars EnvVar = "TRAVIS_SECURE_ENV_VARS" | ||
VarRepoSlug EnvVar = "TRAVIS_REPO_SLUG" | ||
VarOsName EnvVar = "TRAVIS_OS_NAME" | ||
VarTag EnvVar = "TRAVIS_TAG" | ||
VarGoVersion EnvVar = "TRAVIS_GO_VERSION" | ||
) | ||
|
||
// IsRunning attempts to determine whether this process is | ||
// running on Travis-CI. This is done by checking ALL of the | ||
// following env vars are set: | ||
// | ||
// CI=true | ||
// TRAVIS=true | ||
// | ||
// Note: cannot just check CI. | ||
func IsRunning() bool { | ||
return Env(VarCI) == "true" && Env(VarTravis) == "true" | ||
} | ||
|
||
// Env returns the value of a travis env variable. | ||
func Env(v EnvVar) string { | ||
return os.Getenv(string(v)) | ||
} | ||
|
||
// JobId returns the travis JOB_ID of this build. | ||
func JobId() string { | ||
return Env(VarJobId) | ||
} | ||
|
||
// JobNumber returns the travis JOB_NUMBER of this build. | ||
func JobNumber() string { | ||
return Env(VarJobNumber) | ||
} |
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,13 @@ | ||
package travis | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestIsRunning(t *testing.T) { | ||
tr := os.Getenv("TRAVIS") == "true" && os.Getenv("CI") == "true" | ||
if tr != IsRunning() { | ||
t.Error("IsRunning() does not match TRAVIS && CI env var check") | ||
} | ||
} |