@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/hcl"
|
||||
"github.com/hashicorp/hcl/hcl/ast"
|
||||
@@ -54,7 +55,7 @@ func cleanWorkflowsAST(node ast.Node) (ast.Node, bool) {
|
||||
}
|
||||
quote := literalType.Token.Text[0]
|
||||
for _, part := range parts {
|
||||
part = fmt.Sprintf("%c%s%c", quote, part, quote)
|
||||
part = fmt.Sprintf("%c%s%c", quote, strings.Replace(part, "\\", "\\\\", -1), quote)
|
||||
listType.Add(&ast.LiteralType{
|
||||
Token: token.Token{
|
||||
Type: token.STRING,
|
||||
|
@@ -13,40 +13,50 @@ func TestParseWorkflowsFile(t *testing.T) {
|
||||
|
||||
conf := `
|
||||
workflow "build-and-deploy" {
|
||||
on = "push"
|
||||
resolves = ["deploy"]
|
||||
on = "push"
|
||||
resolves = ["deploy"]
|
||||
}
|
||||
|
||||
action "build" {
|
||||
uses = "./action1"
|
||||
args = "echo 'build'"
|
||||
uses = "./action1"
|
||||
args = "echo 'build'"
|
||||
}
|
||||
|
||||
action "test" {
|
||||
uses = "docker://ubuntu:18.04"
|
||||
runs = "echo 'test'"
|
||||
needs = ["build"]
|
||||
uses = "docker://ubuntu:18.04"
|
||||
runs = "echo 'test'"
|
||||
needs = ["build"]
|
||||
}
|
||||
|
||||
action "deploy" {
|
||||
uses = "./action2"
|
||||
args = ["echo","deploy"]
|
||||
needs = ["test"]
|
||||
uses = "./action2"
|
||||
args = ["echo","deploy"]
|
||||
needs = ["test"]
|
||||
}
|
||||
|
||||
action "docker-login" {
|
||||
uses = "docker://docker"
|
||||
runs = ["sh", "-c", "echo $DOCKER_AUTH | docker login --username $REGISTRY_USER --password-stdin"]
|
||||
secrets = ["DOCKER_AUTH"]
|
||||
env = {
|
||||
REGISTRY_USER = "username"
|
||||
}
|
||||
uses = "docker://docker"
|
||||
runs = ["sh", "-c", "echo $DOCKER_AUTH | docker login --username $REGISTRY_USER --password-stdin"]
|
||||
secrets = ["DOCKER_AUTH"]
|
||||
env = {
|
||||
REGISTRY_USER = "username"
|
||||
}
|
||||
}
|
||||
|
||||
action "unit-tests" {
|
||||
uses = "./scripts/github_actions"
|
||||
runs = "yarn test:ci-unittest || echo \"Unit tests failed, but running danger to present the results!\" 2>&1"
|
||||
}
|
||||
uses = "./scripts/github_actions"
|
||||
runs = "yarn test:ci-unittest || echo \"Unit tests failed, but running danger to present the results!\" 2>&1"
|
||||
}
|
||||
|
||||
action "regex-in-args" {
|
||||
uses = "actions/bin/filter@master"
|
||||
args = "tag v?[0-9]+\\.[0-9]+\\.[0-9]+"
|
||||
}
|
||||
|
||||
action "regex-in-args-array" {
|
||||
uses = "actions/bin/filter@master"
|
||||
args = ["tag","v?[0-9]+\\.[0-9]+\\.[0-9]+"]
|
||||
}
|
||||
`
|
||||
|
||||
workflows, err := parseWorkflowsFile(strings.NewReader(conf))
|
||||
@@ -101,6 +111,20 @@ func TestParseWorkflowsFile(t *testing.T) {
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
{"regex-in-args",
|
||||
"actions/bin/filter@master",
|
||||
nil,
|
||||
nil,
|
||||
[]string{"tag", `v?[0-9]+\.[0-9]+\.[0-9]+`},
|
||||
nil,
|
||||
},
|
||||
{"regex-in-args-array",
|
||||
"actions/bin/filter@master",
|
||||
nil,
|
||||
nil,
|
||||
[]string{"tag", `v?[0-9]+\.[0-9]+\.[0-9]+`},
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, exp := range actions {
|
||||
|
@@ -128,11 +128,11 @@ func (runner *runnerImpl) applyEnvironment(env map[string]string) {
|
||||
env["GITHUB_REPOSITORY"] = repo
|
||||
}
|
||||
|
||||
branch, err := common.FindGitBranch(repoPath)
|
||||
ref, err := common.FindGitRef(repoPath)
|
||||
if err != nil {
|
||||
log.Warningf("unable to get git branch: %v", err)
|
||||
log.Warningf("unable to get git ref: %v", err)
|
||||
} else {
|
||||
env["GITHUB_REF"] = fmt.Sprintf("refs/heads/%s", branch)
|
||||
env["GITHUB_REF"] = ref
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user