GitHub env file support (#426)

* Upgrade to the official golangci-lint action and fix some issues it found

* Update deps

* Remove a shadow warning

* Initialize the splitPattern only once

* Initial attempt at supporting $GITHUB_ENV

Needs some polishing and tests

* Now it's actually working

* Replace golang.org/x/crypto/ssh/terminal with golang.org/x/term

* Disable the issue-228 test again

* The linter is picky

* Discovered that the workflow/envs.txt had to exist in certain cases

* Fix small linter issue
This commit is contained in:
Torbjørn Vatn
2021-01-12 07:39:43 +01:00
committed by GitHub
parent 8887daa3e7
commit 15eaa15a0e
16 changed files with 492 additions and 107 deletions

View File

@@ -8,17 +8,17 @@ import (
)
func TestSetEnv(t *testing.T) {
assert := assert.New(t)
a := assert.New(t)
ctx := context.Background()
rc := new(RunContext)
handler := rc.commandHandler(ctx)
handler("::set-env name=x::valz\n")
assert.Equal("valz", rc.Env["x"])
a.Equal("valz", rc.Env["x"])
}
func TestSetOutput(t *testing.T) {
assert := assert.New(t)
a := assert.New(t)
ctx := context.Background()
rc := new(RunContext)
rc.StepResults = make(map[string]*stepResult)
@@ -29,62 +29,62 @@ func TestSetOutput(t *testing.T) {
Outputs: make(map[string]string),
}
handler("::set-output name=x::valz\n")
assert.Equal("valz", rc.StepResults["my-step"].Outputs["x"])
a.Equal("valz", rc.StepResults["my-step"].Outputs["x"])
handler("::set-output name=x::percent2%25\n")
assert.Equal("percent2%", rc.StepResults["my-step"].Outputs["x"])
a.Equal("percent2%", rc.StepResults["my-step"].Outputs["x"])
handler("::set-output name=x::percent2%25%0Atest\n")
assert.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x"])
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x"])
handler("::set-output name=x::percent2%25%0Atest another3%25test\n")
assert.Equal("percent2%\ntest another3%test", rc.StepResults["my-step"].Outputs["x"])
a.Equal("percent2%\ntest another3%test", rc.StepResults["my-step"].Outputs["x"])
handler("::set-output name=x%3A::percent2%25%0Atest\n")
assert.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:"])
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:"])
handler("::set-output name=x%3A%2C%0A%25%0D%3A::percent2%25%0Atest\n")
assert.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:,\n%\r:"])
a.Equal("percent2%\ntest", rc.StepResults["my-step"].Outputs["x:,\n%\r:"])
}
func TestAddpath(t *testing.T) {
assert := assert.New(t)
a := assert.New(t)
ctx := context.Background()
rc := new(RunContext)
handler := rc.commandHandler(ctx)
handler("::add-path::/zoo\n")
assert.Equal("/zoo", rc.ExtraPath[0])
a.Equal("/zoo", rc.ExtraPath[0])
handler("::add-path::/boo\n")
assert.Equal("/boo", rc.ExtraPath[1])
a.Equal("/boo", rc.ExtraPath[1])
}
func TestStopCommands(t *testing.T) {
assert := assert.New(t)
a := assert.New(t)
ctx := context.Background()
rc := new(RunContext)
handler := rc.commandHandler(ctx)
handler("::set-env name=x::valz\n")
assert.Equal("valz", rc.Env["x"])
a.Equal("valz", rc.Env["x"])
handler("::stop-commands::my-end-token\n")
handler("::set-env name=x::abcd\n")
assert.Equal("valz", rc.Env["x"])
a.Equal("valz", rc.Env["x"])
handler("::my-end-token::\n")
handler("::set-env name=x::abcd\n")
assert.Equal("abcd", rc.Env["x"])
a.Equal("abcd", rc.Env["x"])
}
func TestAddpathADO(t *testing.T) {
assert := assert.New(t)
a := assert.New(t)
ctx := context.Background()
rc := new(RunContext)
handler := rc.commandHandler(ctx)
handler("##[add-path]/zoo\n")
assert.Equal("/zoo", rc.ExtraPath[0])
a.Equal("/zoo", rc.ExtraPath[0])
handler("##[add-path]/boo\n")
assert.Equal("/boo", rc.ExtraPath[1])
a.Equal("/boo", rc.ExtraPath[1])
}