Commit 73b3c304 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

ci-pkgs: added travis and jenkins ci pkgs

parent 01283b92
// 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(v EnvVar) bool {
return os.Getenv(string(VarNoFuse)) == "1"
}
// Returns whether TEST_VERBOSE is enabled.
func Verbose(v EnvVar) bool {
return os.Getenv(string(VarVerbose)) == "1"
}
// 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 TravisCI 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)
}
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")
}
}
// 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)
}
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")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment