Documentation ¶
Overview ¶
Package ci provides helpers for interacting with the underlying CI system. Built-in build providers are: AzureBuildProvider, and GitHubBuildProvider.
Index ¶
Examples ¶
Constants ¶
const ( // GitHubCIEnvVar is the environment variable used to detect the // GitHubBuildProvider. GitHubCIEnvVar = "GITHUB_ACTIONS" // GitHubVariablesEnvVar is a GitHub environment variable that contains the // path to a file where you can set variable assignments. GitHubVariablesEnvVar = "GITHUB_ENV" // GitHubPathEnvVar is a GitHub environment variable that contains the path // to a file where you can prepend PATH values. GitHubPathEnvVar = "GITHUB_PATH" )
const AzureCIEnvVar = "TF_BUILD"
AzureCIEnvVar is the environment variable used to detect the AzureBuildProvider.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AzureBuildProvider ¶
type AzureBuildProvider struct{}
AzureBuildProvider supports Azure DevOps Pipelines.
func (AzureBuildProvider) IsDetected ¶
func (AzureBuildProvider) IsDetected() bool
IsDetected determines if this build provider was detected and is available to use.
func (AzureBuildProvider) PrependPath ¶
func (AzureBuildProvider) PrependPath(value string) error
PrependPath adds the specified path to the beginning of the PATH environment variable. Changes from this command become available in subsequent steps in the CI pipeline. You must call os.SetEnv if you want to use the PATH environment variable in the current process.
Example ¶
p := AzureBuildProvider{} p.PrependPath("/usr/bin") p.PrependPath("/home/me/bin")
Output: ##vso[task.prependpath]/usr/bin ##vso[task.prependpath]/home/me/bin
func (AzureBuildProvider) SetEnv ¶
func (AzureBuildProvider) SetEnv(name string, value string) error
SetEnv exports an environment variable. Changes from this command become available in subsequent steps in the CI pipeline. You must call os.SetEnv if you want to use the environment variable in the current process.
Example ¶
p := AzureBuildProvider{} p.SetEnv("FOO", "1") p.SetEnv("BAR", "A")
Output: ##vso[task.setvariable variable=FOO]1 ##vso[task.setvariable variable=BAR]A
type BuildProvider ¶
type BuildProvider interface { // SetEnv exports an environment variable. Changes from this command become // available in subsequent steps in the CI pipeline. You must call os.SetEnv // if you want to use the environment variable in the current process. SetEnv(name string, value string) error // PrependPath adds the specified path to the beginning of the PATH // environment variable. Changes from this command become available in // subsequent steps in the CI pipeline. You must call os.SetEnv if you want // to use the PATH environment variable in the current process. PrependPath(value string) error // IsDetected determines if this build provider was detected and is available // to use. IsDetected() bool }
BuildProvider is a common interface to interact with a CI build provider such as GitHub Actions, or Azure DevOps.
func DetectBuildProvider ¶
func DetectBuildProvider(providers ...BuildProvider) (BuildProvider, bool)
DetectBuildProvider determines the current build provider that the code is executing upon, returning a NoopBuildProvider and false when nothing is detected. By default, only build providers implemented in this package are included in the search. Specify additional providers with the providers argument.
Example ¶
package main import ( "fmt" "github.com/carolynvs/magex/ci" ) func main() { // Figure out if you are on a build provider that is supported p, detected := ci.DetectBuildProvider() if !detected { fmt.Println("no build provider was detected, using a noop implementation") } // Set the LOG_LEVEL environment variable p.SetEnv("LOG_LEVEL", "3") // Add the gopath bin directory to the beginning of the PATH environment variable p.PrependPath("/go/bin") }
Output:
type GitHubBuildProvider ¶
type GitHubBuildProvider struct{}
GitHubBuildProvider supports GitHub Actions.
func (GitHubBuildProvider) IsDetected ¶
func (p GitHubBuildProvider) IsDetected() bool
IsDetected determines if this build provider was detected and is available to use.
func (GitHubBuildProvider) PrependPath ¶
func (p GitHubBuildProvider) PrependPath(value string) error
PrependPath adds the specified path to the beginning of the PATH environment variable. Changes from this command become available in subsequent steps in the CI pipeline. You must call os.SetEnv if you want to use the PATH environment variable in the current process.
func (GitHubBuildProvider) SetEnv ¶
func (p GitHubBuildProvider) SetEnv(name string, value string) error
SetEnv exports an environment variable. Changes from this command become available in subsequent steps in the CI pipeline. You must call os.SetEnv if you want to use the environment variable in the current process.
type NoopBuildProvider ¶
type NoopBuildProvider struct{}
NoopBuildProvider is a build provider that does nothing.
func (NoopBuildProvider) IsDetected ¶
func (n NoopBuildProvider) IsDetected() bool
IsDetected always returns false.
func (NoopBuildProvider) PrependPath ¶
func (n NoopBuildProvider) PrependPath(string) error
PrependPath does nothing.