Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose custom env vars for run step runner for custom steps #229

Closed
wants to merge 5 commits into from
Closed

expose custom env vars for run step runner for custom steps #229

wants to merge 5 commits into from

Conversation

mootpt
Copy link
Contributor

@mootpt mootpt commented Aug 18, 2018

No description provided.

@codecov
Copy link

codecov bot commented Aug 18, 2018

Codecov Report

Merging #229 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
+ Coverage   70.07%   70.15%   +0.07%     
==========================================
  Files          61       61              
  Lines        3579     3588       +9     
==========================================
+ Hits         2508     2517       +9     
  Misses        892      892              
  Partials      179      179
Impacted Files Coverage Δ
server/events/runtime/run_step_runner.go 100% <100%> (ø) ⬆️
server/events/runtime/init_step_runner.go 83.33% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64cbb2e...d9c9951. Read the comment docs.

@@ -34,6 +34,9 @@ func (r *RunStepRunner) Run(ctx models.ProjectCommandContext, command []string,
fmt.Sprintf("ATLANTIS_TERRAFORM_VERSION=%s", tfVersion),
fmt.Sprintf("DIR=%s", path),
fmt.Sprintf("PLANFILE=%s", filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectConfig))),
fmt.Sprintf("REPO_OWNER=%s", ctx.BaseRepo.Owner),
fmt.Sprintf("REPO_NAME=%s", ctx.BaseRepo.Name),
fmt.Sprintf("BRANCH_NAME=%s", ctx.Pull.Branch),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get everything in there:

	baseEnvVars := os.Environ()
	customEnvVars := map[string]string{
		"WORKSPACE":                  ctx.Workspace,
		"ATLANTIS_TERRAFORM_VERSION": tfVersion,
		"DIR":              path,
		"PLANFILE":         filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectConfig)),
		"BASE_REPO_NAME":   ctx.BaseRepo.Name,
		"BASE_REPO_OWNER":  ctx.BaseRepo.Owner,
		"HEAD_REPO_NAME":   ctx.HeadRepo.Name,
		"HEAD_REPO_OWNER":  ctx.HeadRepo.Owner,
		"HEAD_BRANCH_NAME": ctx.Pull.Branch,
		"PULL_NUM":         fmt.Sprintf("%d", ctx.Pull.Num),
		"PULL_AUTHOR":      ctx.Pull.Author,
	}
	finalEnvVars := baseEnvVars
	for key, val := range customEnvVars {
		finalEnvVars = append(finalEnvVars, fmt.Sprintf("%s=%s", key, val))
	}
	cmd.Env = finalEnvVars

We also need to update the tests. Can do something like the last case of run_step_runner_test.go:

		{
			Command: "echo workspace=$WORKSPACE version=$ATLANTIS_TERRAFORM_VERSION dir=$DIR planfile=$PLANFILE",
			ExpOut:  "workspace=myworkspace version=0.11.0 dir=$DIR planfile=$DIR/myworkspace.tfplan\n",
		},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. I'll make the additions and push it up later this evening.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

@mootpt
Copy link
Contributor Author

mootpt commented Aug 18, 2018

Thanks for the suggestions @lkysow. This should do it.

@mootpt mootpt changed the title expose repo name, owner, and branch to run step runner for custom steps expose custom env vars for run step runner for custom steps Aug 18, 2018
@lkysow
Copy link
Member

lkysow commented Aug 20, 2018

Thanks! This is great. I added a small change to the tests and squashed your commits in #232. This will be in the next release.

@lkysow lkysow closed this Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants