Skip to content

Commit

Permalink
feat(library): add build deployment env vars (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: Kelly Merrick <[email protected]>
  • Loading branch information
jbrockopp and KellyMerrick authored Apr 27, 2020
1 parent 8b4d7c7 commit 30488b4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func (b *Build) Environment() map[string]string {
envs["VELA_PULL_REQUEST"] = number
}

// check if the Build event is deployment
if strings.EqualFold(b.GetEvent(), constants.EventDeploy) {
// capture the deployment target
target := ToString(b.GetDeploy())

// add the deployment target to the list
envs["VELA_BUILD_TARGET"] = target
envs["VELA_DEPLOYMENT"] = target
}

// check if the Build event is pull_request
if strings.EqualFold(b.GetEvent(), constants.EventPull) {
// capture the pull request number
Expand Down
59 changes: 59 additions & 0 deletions library/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func TestLibrary_Build_Environment(t *testing.T) {
_comment.SetEvent("comment")
_comment.SetRef("refs/pulls/1/head")

_deploy := testBuild()
_deploy.SetEvent("deployment")
_deploy.SetDeploy("production")

_pull := testBuild()
_pull.SetEvent("pull_request")
_pull.SetRef("refs/pulls/1/head")
Expand Down Expand Up @@ -138,6 +142,61 @@ func TestLibrary_Build_Environment(t *testing.T) {
"BUILD_WORKSPACE": "TODO",
},
},
{
build: _deploy,
want: map[string]string{
"VELA_BUILD_AUTHOR": "OctoKitty",
"VELA_BUILD_AUTHOR_EMAIL": "[email protected]",
"VELA_BUILD_BASE_REF": "",
"VELA_BUILD_BRANCH": "master",
"VELA_BUILD_CHANNEL": "TODO",
"VELA_BUILD_CLONE": "https://github.com/github/octocat.git",
"VELA_BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163",
"VELA_BUILD_CREATED": "1563474076",
"VELA_BUILD_DISTRIBUTION": "linux",
"VELA_BUILD_ENQUEUED": "1563474077",
"VELA_BUILD_EVENT": "deployment",
"VELA_BUILD_FINISHED": "1563474079",
"VELA_BUILD_HOST": "example.company.com",
"VELA_BUILD_LINK": "https://example.company.com/github/octocat/1",
"VELA_BUILD_MESSAGE": "First commit...",
"VELA_BUILD_NUMBER": "1",
"VELA_BUILD_PARENT": "1",
"VELA_BUILD_REF": "refs/heads/master",
"VELA_BUILD_RUNTIME": "docker",
"VELA_BUILD_SENDER": "OctoKitty",
"VELA_BUILD_STARTED": "1563474078",
"VELA_BUILD_SOURCE": "https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163",
"VELA_BUILD_STATUS": "running",
"VELA_BUILD_TARGET": "production",
"VELA_BUILD_TITLE": "push received from https://github.com/github/octocat",
"VELA_BUILD_WORKSPACE": "TODO",
"VELA_DEPLOYMENT": "production",
"BUILD_AUTHOR": "OctoKitty",
"BUILD_AUTHOR_EMAIL": "[email protected]",
"BUILD_BASE_REF": "",
"BUILD_BRANCH": "master",
"BUILD_CHANNEL": "TODO",
"BUILD_CLONE": "https://github.com/github/octocat.git",
"BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163",
"BUILD_CREATED": "1563474076",
"BUILD_ENQUEUED": "1563474077",
"BUILD_EVENT": "deployment",
"BUILD_FINISHED": "1563474079",
"BUILD_HOST": "example.company.com",
"BUILD_LINK": "https://example.company.com/github/octocat/1",
"BUILD_MESSAGE": "First commit...",
"BUILD_NUMBER": "1",
"BUILD_PARENT": "1",
"BUILD_REF": "refs/heads/master",
"BUILD_SENDER": "OctoKitty",
"BUILD_STARTED": "1563474078",
"BUILD_SOURCE": "https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163",
"BUILD_STATUS": "running",
"BUILD_TITLE": "push received from https://github.com/github/octocat",
"BUILD_WORKSPACE": "TODO",
},
},
{
build: _pull,
want: map[string]string{
Expand Down

0 comments on commit 30488b4

Please sign in to comment.