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 authored and GitHub committed 2021-01-11 22:39:43 -08:00
1 parent 8887daa3e7
commit 15eaa15a0e
16 files changed
+492 -107

No files matched your search

+4 -4
View File
@@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: docker://golangci/golangci-lint:v1.23.8 - uses: golangci/golangci-lint-action@v2
with:
args: golangci-lint run
env: env:
CGO_ENABLED: 0 CGO_ENABLED: 0
with:
version: v1.32.2
test: test:
name: Test name: Test
@@ -35,7 +35,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: GoReleaser - name: GoReleaser
uses: goreleaser/goreleaser-action@v1 uses: goreleaser/goreleaser-action@v2
with: with:
version: latest version: latest
args: release --snapshot --rm-dist args: release --snapshot --rm-dist
+1
View File
@@ -8,6 +8,7 @@ env:
KEY_WITH_UNDERSCORES: value_with_underscores KEY_WITH_UNDERSCORES: value_with_underscores
SOMETHING_TRUE: true SOMETHING_TRUE: true
SOMETHING_FALSE: false SOMETHING_FALSE: false
ACT: true
jobs: jobs:
+4 -1
View File
@@ -1,7 +1,10 @@
run:
timeout: 3m
linters-settings: linters-settings:
gocyclo: gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20) # minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 15 mi-complexity: 15
gocritic: gocritic:
disabled-checks: disabled-checks:
- ifElseChain - ifElseChain
+11 -6
View File
@@ -11,7 +11,7 @@ import (
"github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/common"
fswatch "github.com/andreaskoch/go-fswatch" "github.com/andreaskoch/go-fswatch"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"github.com/nektos/act/pkg/model" "github.com/nektos/act/pkg/model"
"github.com/nektos/act/pkg/runner" "github.com/nektos/act/pkg/runner"
@@ -79,7 +79,12 @@ func readArgsFile(file string) []string {
if err != nil { if err != nil {
return args return args
} }
defer f.Close() defer func() {
err := f.Close()
if err != nil {
log.Errorf("Failed to close args file: %v", err)
}
}()
scanner := bufio.NewScanner(f) scanner := bufio.NewScanner(f)
for scanner.Scan() { for scanner.Scan() {
arg := scanner.Text() arg := scanner.Text()
@@ -91,7 +96,7 @@ func readArgsFile(file string) []string {
} }
func setupLogging(cmd *cobra.Command, args []string) { func setupLogging(cmd *cobra.Command, _ []string) {
verbose, _ := cmd.Flags().GetBool("verbose") verbose, _ := cmd.Flags().GetBool("verbose")
if verbose { if verbose {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
@@ -189,7 +194,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
Platforms: input.newPlatforms(), Platforms: input.newPlatforms(),
Privileged: input.privileged, Privileged: input.privileged,
} }
runner, err := runner.New(config) r, err := runner.New(config)
if err != nil { if err != nil {
return err return err
} }
@@ -198,10 +203,10 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
if watch, err := cmd.Flags().GetBool("watch"); err != nil { if watch, err := cmd.Flags().GetBool("watch"); err != nil {
return err return err
} else if watch { } else if watch {
return watchAndRun(ctx, runner.NewPlanExecutor(plan)) return watchAndRun(ctx, r.NewPlanExecutor(plan))
} }
return runner.NewPlanExecutor(plan)(ctx) return r.NewPlanExecutor(plan)(ctx)
} }
} }
+24 -27
View File
@@ -5,50 +5,47 @@ go 1.14
require ( require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/MichaelTJones/walk v0.0.0-20161122175330-4748e29d5718 // indirect github.com/MichaelTJones/walk v0.0.0-20161122175330-4748e29d5718 // indirect
github.com/Microsoft/go-winio v0.4.14 // indirect github.com/Microsoft/go-winio v0.4.15 // indirect
github.com/Microsoft/hcsshim v0.8.6 // indirect github.com/Microsoft/hcsshim v0.8.10 // indirect
github.com/andreaskoch/go-fswatch v1.0.0 github.com/andreaskoch/go-fswatch v1.0.0
github.com/containerd/containerd v1.3.3 // indirect github.com/containerd/containerd v1.4.1 // indirect
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc // indirect github.com/containerd/continuity v0.0.0-20200928162600-f2cc35102c2a // indirect
github.com/docker/cli v0.0.0-20200617172703-0ed913b885c8 github.com/docker/cli v20.10.0-rc1+incompatible
github.com/docker/distribution v2.7.1+incompatible // indirect github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v17.12.0-ce-rc1.0.20200618181300-9dc6525e6118+incompatible github.com/docker/docker v17.12.0-ce-rc1.0.20200618181300-9dc6525e6118+incompatible
github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/go-git/go-billy/v5 v5.0.0 github.com/go-git/go-billy/v5 v5.0.0
github.com/go-git/go-git/v5 v5.1.0 github.com/go-git/go-git/v5 v5.2.0
github.com/go-ini/ini v1.41.0 github.com/go-ini/ini v1.62.0
github.com/gogo/protobuf v1.2.1 // indirect github.com/golang/protobuf v1.4.3 // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorilla/mux v1.7.0 // indirect github.com/gorilla/mux v1.7.0 // indirect
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c
github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/imdario/mergo v0.3.11 // indirect
github.com/joho/godotenv v1.3.0 github.com/joho/godotenv v1.3.0
github.com/jtolds/gls v4.2.1+incompatible // indirect github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/mgutz/str v1.2.0 // indirect github.com/mgutz/str v1.2.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v0.1.1 github.com/opencontainers/runc v0.1.1 // indirect
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.9.1
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94 github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94
github.com/sirupsen/logrus v1.4.1 github.com/sirupsen/logrus v1.7.0
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect github.com/spf13/cobra v1.1.1
github.com/spf13/cobra v0.0.3
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 github.com/xanzy/ssh-agent v0.3.0 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 // indirect
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c // indirect golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb // indirect golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
google.golang.org/grpc v1.20.1 // indirect golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221
google.golang.org/genproto v0.0.0-20201117123952-62d171c70ae1 // indirect
google.golang.org/grpc v1.33.2 // indirect
gopkg.in/godo.v2 v2.0.9 gopkg.in/godo.v2 v2.0.9
gopkg.in/ini.v1 v1.41.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
gotest.tools v2.2.0+incompatible // indirect
gotest.tools/v3 v3.0.2 gotest.tools/v3 v3.0.2
) )
+339 -28
View File
File diff suppressed because it is too large. Load diff
-1
View File
@@ -43,7 +43,6 @@ type styleDef struct {
var styleDefs = []styleDef{ var styleDefs = []styleDef{
{"\u2554", "\u2557", "\u255a", "\u255d", "\u2550", "\u2551"}, {"\u2554", "\u2557", "\u255a", "\u255d", "\u2550", "\u2551"},
//{"\u250c", "\u2510", "\u2514", "\u2518", "\u2500", "\u2502"},
{"\u256d", "\u256e", "\u2570", "\u256f", "\u2500", "\u2502"}, {"\u256d", "\u256e", "\u2570", "\u256f", "\u2500", "\u2502"},
{"\u250c", "\u2510", "\u2514", "\u2518", "\u254c", "\u254e"}, {"\u250c", "\u2510", "\u2514", "\u2518", "\u254c", "\u254e"},
{" ", " ", " ", " ", " ", " "}, {" ", " ", " ", " ", " ", " "},
-1
View File
@@ -157,7 +157,6 @@ func findGitDirectory(fromFile string) (string, error) {
return "", err return "", err
} }
//log.Debugf("Searching for git directory in %s", absPath)
fi, err := os.Stat(absPath) fi, err := os.Stat(absPath)
if err != nil { if err != nil {
return "", err return "", err
+62 -7
View File
@@ -2,6 +2,7 @@ package container
import ( import (
"archive/tar" "archive/tar"
"bufio"
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
@@ -9,6 +10,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"github.com/go-git/go-billy/v5/helper/polyfill" "github.com/go-git/go-billy/v5/helper/polyfill"
@@ -24,7 +26,7 @@ import (
"github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/common"
"github.com/pkg/errors" "github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/term"
) )
// NewContainerInput the input for the New function // NewContainerInput the input for the New function
@@ -58,6 +60,7 @@ type Container interface {
Pull(forcePull bool) common.Executor Pull(forcePull bool) common.Executor
Start(attach bool) common.Executor Start(attach bool) common.Executor
Exec(command []string, env map[string]string) common.Executor Exec(command []string, env map[string]string) common.Executor
UpdateFromGithubEnv(env *map[string]string) common.Executor
Remove() common.Executor Remove() common.Executor
} }
@@ -116,6 +119,10 @@ func (cr *containerReference) CopyDir(destPath string, srcPath string) common.Ex
).IfNot(common.Dryrun) ).IfNot(common.Dryrun)
} }
func (cr *containerReference) UpdateFromGithubEnv(env *map[string]string) common.Executor {
return cr.extractGithubEnv(env).IfNot(common.Dryrun)
}
func (cr *containerReference) Exec(command []string, env map[string]string) common.Executor { func (cr *containerReference) Exec(command []string, env map[string]string) common.Executor {
return common.NewPipelineExecutor( return common.NewPipelineExecutor(
@@ -196,10 +203,10 @@ func (cr *containerReference) find() common.Executor {
return errors.WithStack(err) return errors.WithStack(err)
} }
for _, container := range containers { for _, c := range containers {
for _, name := range container.Names { for _, name := range c.Names {
if name[1:] == cr.input.Name { if name[1:] == cr.input.Name {
cr.id = container.ID cr.id = c.ID
return nil return nil
} }
} }
@@ -237,7 +244,7 @@ func (cr *containerReference) create() common.Executor {
return nil return nil
} }
logger := common.Logger(ctx) logger := common.Logger(ctx)
isTerminal := terminal.IsTerminal(int(os.Stdout.Fd())) isTerminal := term.IsTerminal(int(os.Stdout.Fd()))
input := cr.input input := cr.input
config := &container.Config{ config := &container.Config{
@@ -275,11 +282,59 @@ func (cr *containerReference) create() common.Executor {
} }
} }
var singleLineEnvPattern, mulitiLineEnvPattern *regexp.Regexp
func (cr *containerReference) extractGithubEnv(env *map[string]string) common.Executor {
if singleLineEnvPattern == nil {
singleLineEnvPattern = regexp.MustCompile("^([^=]+)=([^=]+)$")
mulitiLineEnvPattern = regexp.MustCompile(`^([^<]+)<<(\w+)$`)
}
localEnv := *env
return func(ctx context.Context) error {
githubEnvTar, _, err := cr.cli.CopyFromContainer(ctx, cr.id, localEnv["GITHUB_ENV"])
if err != nil {
return nil
}
reader := tar.NewReader(githubEnvTar)
_, err = reader.Next()
if err != nil && err != io.EOF {
return errors.WithStack(err)
}
s := bufio.NewScanner(reader)
multiLineEnvKey := ""
multiLineEnvDelimiter := ""
multiLineEnvContent := ""
for s.Scan() {
line := s.Text()
if singleLineEnv := singleLineEnvPattern.FindStringSubmatch(line); singleLineEnv != nil {
localEnv[singleLineEnv[1]] = singleLineEnv[2]
}
if line == multiLineEnvDelimiter {
localEnv[multiLineEnvKey] = multiLineEnvContent
multiLineEnvKey, multiLineEnvDelimiter, multiLineEnvContent = "", "", ""
}
if multiLineEnvKey != "" && multiLineEnvDelimiter != "" {
if multiLineEnvContent != "" {
multiLineEnvContent += "\n"
}
multiLineEnvContent += line
}
if mulitiLineEnvStart := mulitiLineEnvPattern.FindStringSubmatch(line); mulitiLineEnvStart != nil {
multiLineEnvKey = mulitiLineEnvStart[1]
multiLineEnvDelimiter = mulitiLineEnvStart[2]
}
}
env = &localEnv
return nil
}
}
func (cr *containerReference) exec(cmd []string, env map[string]string) common.Executor { func (cr *containerReference) exec(cmd []string, env map[string]string) common.Executor {
return func(ctx context.Context) error { return func(ctx context.Context) error {
logger := common.Logger(ctx) logger := common.Logger(ctx)
logger.Debugf("Exec command '%s'", cmd) logger.Debugf("Exec command '%s'", cmd)
isTerminal := terminal.IsTerminal(int(os.Stdout.Fd())) isTerminal := term.IsTerminal(int(os.Stdout.Fd()))
envList := make([]string, 0) envList := make([]string, 0)
for k, v := range env { for k, v := range env {
envList = append(envList, fmt.Sprintf("%s=%s", k, v)) envList = append(envList, fmt.Sprintf("%s=%s", k, v))
@@ -492,7 +547,7 @@ func (cr *containerReference) attach() common.Executor {
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
isTerminal := terminal.IsTerminal(int(os.Stdout.Fd())) isTerminal := term.IsTerminal(int(os.Stdout.Fd()))
var outWriter io.Writer var outWriter io.Writer
outWriter = cr.input.Stdout outWriter = cr.input.Stdout
+3 -3
View File
@@ -283,13 +283,13 @@ const (
// StepTypeRun is all steps that have a `run` attribute // StepTypeRun is all steps that have a `run` attribute
StepTypeRun StepType = iota StepTypeRun StepType = iota
//StepTypeUsesDockerURL is all steps that have a `uses` that is of the form `docker://...` // StepTypeUsesDockerURL is all steps that have a `uses` that is of the form `docker://...`
StepTypeUsesDockerURL StepTypeUsesDockerURL
//StepTypeUsesActionLocal is all steps that have a `uses` that is a local action in a subdirectory // StepTypeUsesActionLocal is all steps that have a `uses` that is a local action in a subdirectory
StepTypeUsesActionLocal StepTypeUsesActionLocal
//StepTypeUsesActionRemote is all steps that have a `uses` that is a reference to a github repo // StepTypeUsesActionRemote is all steps that have a `uses` that is a reference to a github repo
StepTypeUsesActionRemote StepTypeUsesActionRemote
) )
+3 -3
View File
@@ -13,7 +13,7 @@ var commandPatternADO *regexp.Regexp
func init() { func init() {
commandPatternGA = regexp.MustCompile("^::([^ ]+)( (.+))?::([^\r\n]*)[\r\n]+$") commandPatternGA = regexp.MustCompile("^::([^ ]+)( (.+))?::([^\r\n]*)[\r\n]+$")
commandPatternADO = regexp.MustCompile("^##\\[([^ ]+)( (.+))?\\]([^\r\n]*)[\r\n]+$") commandPatternADO = regexp.MustCompile("^##\\[([^ ]+)( (.+))?]([^\r\n]*)[\r\n]+$")
} }
func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler { func (rc *RunContext) commandHandler(ctx context.Context) common.LineHandler {
@@ -103,7 +103,7 @@ func unescapeCommandData(arg string) string {
"%0A": "\n", "%0A": "\n",
} }
for k, v := range escapeMap { for k, v := range escapeMap {
arg = strings.Replace(arg, k, v, -1) arg = strings.ReplaceAll(arg, k, v)
} }
return arg return arg
} }
@@ -116,7 +116,7 @@ func unescapeCommandProperty(arg string) string {
"%2C": ",", "%2C": ",",
} }
for k, v := range escapeMap { for k, v := range escapeMap {
arg = strings.Replace(arg, k, v, -1) arg = strings.ReplaceAll(arg, k, v)
} }
return arg return arg
} }
+19 -19
View File
@@ -8,17 +8,17 @@ import (
) )
func TestSetEnv(t *testing.T) { func TestSetEnv(t *testing.T) {
assert := assert.New(t) a := assert.New(t)
ctx := context.Background() ctx := context.Background()
rc := new(RunContext) rc := new(RunContext)
handler := rc.commandHandler(ctx) handler := rc.commandHandler(ctx)
handler("::set-env name=x::valz\n") handler("::set-env name=x::valz\n")
assert.Equal("valz", rc.Env["x"]) a.Equal("valz", rc.Env["x"])
} }
func TestSetOutput(t *testing.T) { func TestSetOutput(t *testing.T) {
assert := assert.New(t) a := assert.New(t)
ctx := context.Background() ctx := context.Background()
rc := new(RunContext) rc := new(RunContext)
rc.StepResults = make(map[string]*stepResult) rc.StepResults = make(map[string]*stepResult)
@@ -29,62 +29,62 @@ func TestSetOutput(t *testing.T) {
Outputs: make(map[string]string), Outputs: make(map[string]string),
} }
handler("::set-output name=x::valz\n") 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") 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") 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") 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") 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") 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) { func TestAddpath(t *testing.T) {
assert := assert.New(t) a := assert.New(t)
ctx := context.Background() ctx := context.Background()
rc := new(RunContext) rc := new(RunContext)
handler := rc.commandHandler(ctx) handler := rc.commandHandler(ctx)
handler("::add-path::/zoo\n") handler("::add-path::/zoo\n")
assert.Equal("/zoo", rc.ExtraPath[0]) a.Equal("/zoo", rc.ExtraPath[0])
handler("::add-path::/boo\n") handler("::add-path::/boo\n")
assert.Equal("/boo", rc.ExtraPath[1]) a.Equal("/boo", rc.ExtraPath[1])
} }
func TestStopCommands(t *testing.T) { func TestStopCommands(t *testing.T) {
assert := assert.New(t) a := assert.New(t)
ctx := context.Background() ctx := context.Background()
rc := new(RunContext) rc := new(RunContext)
handler := rc.commandHandler(ctx) handler := rc.commandHandler(ctx)
handler("::set-env name=x::valz\n") 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("::stop-commands::my-end-token\n")
handler("::set-env name=x::abcd\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("::my-end-token::\n")
handler("::set-env name=x::abcd\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) { func TestAddpathADO(t *testing.T) {
assert := assert.New(t) a := assert.New(t)
ctx := context.Background() ctx := context.Background()
rc := new(RunContext) rc := new(RunContext)
handler := rc.commandHandler(ctx) handler := rc.commandHandler(ctx)
handler("##[add-path]/zoo\n") handler("##[add-path]/zoo\n")
assert.Equal("/zoo", rc.ExtraPath[0]) a.Equal("/zoo", rc.ExtraPath[0])
handler("##[add-path]/boo\n") handler("##[add-path]/boo\n")
assert.Equal("/boo", rc.ExtraPath[1]) a.Equal("/boo", rc.ExtraPath[1])
} }
-1
View File
@@ -185,7 +185,6 @@ func TestInterpolate(t *testing.T) {
func updateTestExpressionWorkflow(t *testing.T, tables []struct { func updateTestExpressionWorkflow(t *testing.T, tables []struct {
in string in string
out string out string
//wantErr bool
}, rc *RunContext) { }, rc *RunContext) {
var envs string var envs string
+3 -3
View File
@@ -12,11 +12,11 @@ import (
"github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/common"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/term"
) )
const ( const (
//nocolor = 0 // nocolor = 0
red = 31 red = 31
green = 32 green = 32
yellow = 33 yellow = 33
@@ -126,7 +126,7 @@ func (f *stepLogFormatter) isColored(entry *logrus.Entry) bool {
func checkIfTerminal(w io.Writer) bool { func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) { switch v := w.(type) {
case *os.File: case *os.File:
return terminal.IsTerminal(int(v.Fd())) return term.IsTerminal(int(v.Fd()))
default: default:
return false return false
} }
+18 -2
View File
@@ -125,6 +125,10 @@ func (rc *RunContext) startJobContainer() common.Executor {
Name: "workflow/event.json", Name: "workflow/event.json",
Mode: 0644, Mode: 0644,
Body: rc.EventJSON, Body: rc.EventJSON,
}, &container.FileEntry{
Name: "workflow/envs.txt",
Mode: 0644,
Body: "",
}, &container.FileEntry{ }, &container.FileEntry{
Name: "home/.act", Name: "home/.act",
Mode: 0644, Mode: 0644,
@@ -199,6 +203,13 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
} }
_ = sc.setupEnv()(ctx) _ = sc.setupEnv()(ctx)
if sc.Env != nil {
err := rc.JobContainer.UpdateFromGithubEnv(&sc.Env)(ctx)
if err != nil {
return err
}
}
rc.ExprEval = sc.NewExpressionEvaluator() rc.ExprEval = sc.NewExpressionEvaluator()
runStep, err := rc.EvalBool(sc.Step.If) runStep, err := rc.EvalBool(sc.Step.If)
@@ -267,14 +278,17 @@ func (rc *RunContext) isEnabled(ctx context.Context) bool {
return true return true
} }
var splitPattern *regexp.Regexp
// EvalBool evaluates an expression against current run context // EvalBool evaluates an expression against current run context
func (rc *RunContext) EvalBool(expr string) (bool, error) { func (rc *RunContext) EvalBool(expr string) (bool, error) {
if splitPattern == nil {
splitPattern = regexp.MustCompile(fmt.Sprintf(`%s|%s|\S+`, expressionPattern.String(), operatorPattern.String()))
}
if strings.HasPrefix(strings.TrimSpace(expr), "!") { if strings.HasPrefix(strings.TrimSpace(expr), "!") {
return false, errors.New("expressions starting with ! must be wrapped in ${{ }}") return false, errors.New("expressions starting with ! must be wrapped in ${{ }}")
} }
if expr != "" { if expr != "" {
splitPattern := regexp.MustCompile(fmt.Sprintf(`%s|%s|\S+`, expressionPattern.String(), operatorPattern.String()))
parts := splitPattern.FindAllString(expr, -1) parts := splitPattern.FindAllString(expr, -1)
var evaluatedParts []string var evaluatedParts []string
for i, part := range parts { for i, part := range parts {
@@ -550,6 +564,8 @@ func (rc *RunContext) withGithubEnv(env map[string]string) map[string]string {
github := rc.getGithubContext() github := rc.getGithubContext()
env["CI"] = "true" env["CI"] = "true"
env["HOME"] = "/github/home" env["HOME"] = "/github/home"
env["GITHUB_ENV"] = "/github/workflow/envs.txt"
env["GITHUB_WORKFLOW"] = github.Workflow env["GITHUB_WORKFLOW"] = github.Workflow
env["GITHUB_RUN_ID"] = github.RunID env["GITHUB_RUN_ID"] = github.RunID
env["GITHUB_RUN_NUMBER"] = github.RunNumber env["GITHUB_RUN_NUMBER"] = github.RunNumber
+1 -1
View File
@@ -92,7 +92,7 @@ func TestRunEvent(t *testing.T) {
{"testdata", "matrix-include-exclude", "push", "", platforms}, {"testdata", "matrix-include-exclude", "push", "", platforms},
{"testdata", "commands", "push", "", platforms}, {"testdata", "commands", "push", "", platforms},
{"testdata", "workdir", "push", "", platforms}, {"testdata", "workdir", "push", "", platforms},
//{"testdata", "issue-228", "push", "", platforms}, // TODO [igni]: Remove this once everything passes // {"testdata", "issue-228", "push", "", platforms}, // TODO [igni]: Remove this once everything passes
{"testdata", "defaults-run", "push", "", platforms}, {"testdata", "defaults-run", "push", "", platforms},
} }
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)