1
1
mirror of https://github.com/nektos/act.git synced 2024-09-11 12:35:25 +03:00

update to latest version of action parser

This commit is contained in:
Casey Lee 2019-01-31 16:36:28 -08:00
parent bc5c23e8e4
commit 3e04312912
No known key found for this signature in database
GPG Key ID: 1899120ECD0A1784
10 changed files with 89 additions and 46 deletions

View File

@ -1,7 +1,6 @@
package actions
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -60,12 +59,14 @@ func (runner *runnerImpl) setupWorkflows() error {
defer workflowReader.Close()
runner.workflowConfig, err = parser.Parse(workflowReader)
if err != nil {
parserError := err.(*parser.ParserError)
for _, e := range parserError.Errors {
fmt.Fprintln(os.Stderr, e)
/*
if err != nil {
parserError := err.(*parser.ParserError)
for _, e := range parserError.Errors {
fmt.Fprintln(os.Stderr, e)
}
}
}
*/
return err
}

View File

@ -95,10 +95,18 @@ func (runner *runnerImpl) newActionExecutor(actionName string) common.Executor {
for k, v := range env {
envList = append(envList, fmt.Sprintf("%s=%s", k, v))
}
var cmd, entrypoint []string
if action.Args != nil {
cmd = action.Args.Split()
}
if action.Runs != nil {
entrypoint = action.Runs.Split()
}
executors = append(executors, container.NewDockerRunExecutor(container.NewDockerRunExecutorInput{
DockerExecutorInput: in,
Cmd: action.Args.Parsed,
Entrypoint: action.Runs.Parsed,
Cmd: cmd,
Entrypoint: entrypoint,
Image: image,
WorkingDir: "/github/workspace",
Env: envList,

2
go.mod
View File

@ -4,7 +4,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.4.11 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/actions/workflow-parser v0.0.0-20190130154146-aac54e2ba131
github.com/actions/workflow-parser v0.0.0-20190131180005-9cb71d183680
github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 // indirect
github.com/docker/distribution v2.7.0+incompatible // indirect
github.com/docker/docker v1.13.1

6
go.sum
View File

@ -5,8 +5,10 @@ github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/actions/workflow-parser v0.0.0-20190130154146-aac54e2ba131 h1:f81A6l1wPc9LdSZ85yJb+YuZxHiweb6D3p1l/bKDbJg=
github.com/actions/workflow-parser v0.0.0-20190130154146-aac54e2ba131/go.mod h1:jz9ZVl8zUIcjMfDQearQjvUHIBhx9l1ys4keDd6be34=
github.com/actions/workflow-parser v0.0.0-20190131170132-f9c507444936 h1:n7QhjGKV6TSvqiSJdRx2yZ7go8FihDG7ksqi/M1RUF8=
github.com/actions/workflow-parser v0.0.0-20190131170132-f9c507444936/go.mod h1:jz9ZVl8zUIcjMfDQearQjvUHIBhx9l1ys4keDd6be34=
github.com/actions/workflow-parser v0.0.0-20190131180005-9cb71d183680 h1:MIHTh+XAfOwshi2enD7FwYkGgFpNWYx2mSzYG9LJQeg=
github.com/actions/workflow-parser v0.0.0-20190131180005-9cb71d183680/go.mod h1:jz9ZVl8zUIcjMfDQearQjvUHIBhx9l1ys4keDd6be34=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=

View File

@ -0,0 +1,38 @@
package model
import (
"strings"
)
// Command represents the optional "runs" and "args" attributes.
// Each one takes one of two forms:
// - runs="entrypoint arg1 arg2 ..."
// - runs=[ "entrypoint", "arg1", "arg2", ... ]
type Command interface {
isCommand()
Split() []string
}
// StringCommand represents the string based form of the "runs" or "args"
// attribute.
// - runs="entrypoint arg1 arg2 ..."
type StringCommand struct {
Value string
}
// ListCommand represents the list based form of the "runs" or "args" attribute.
// - runs=[ "entrypoint", "arg1", "arg2", ... ]
type ListCommand struct {
Values []string
}
func (s *StringCommand) isCommand() {}
func (l *ListCommand) isCommand() {}
func (s *StringCommand) Split() []string {
return strings.Fields(s.Value)
}
func (l *ListCommand) Split() []string {
return l.Values
}

View File

@ -10,25 +10,12 @@ type Configuration struct {
type Action struct {
Identifier string
Uses Uses
Runs, Args ActionCommand
Runs, Args Command
Needs []string
Env map[string]string
Secrets []string
}
// ActionCommand represents the optional "runs" and "args" attributes.
// Each one takes one of two forms:
// - runs="entrypoint arg1 arg2 ..."
// - runs=[ "entrypoint", "arg1", "arg2", ... ]
// If the user uses the string form, "Raw" contains that value, and
// "Parsed" contains an array of the string value split at whitespace.
// If the user uses the array form, "Raw" is empty, and "Parsed" contains
// the array.
type ActionCommand struct {
Raw string
Parsed []string
}
// Workflow represents a single "workflow" stanza in a .workflow file.
type Workflow struct {
Identifier string

View File

@ -12,7 +12,7 @@ func IsAllowedEventType(eventType string) bool {
// IsMatchingEventType checks to see if the "flowOn" string from a flow's on attribute matches the incoming webhook of type eventType.
func IsMatchingEventType(flowOn, eventType string) bool {
return strings.ToLower(flowOn) == strings.ToLower(eventType)
return strings.EqualFold(flowOn, eventType)
}
// https://developer.github.com/actions/creating-workflows/workflow-configuration-options/#events-supported-in-workflow-files

View File

@ -1,6 +1,7 @@
package parser
import (
"bytes"
"fmt"
"sort"
"strconv"
@ -17,7 +18,13 @@ type ParserError struct {
}
func (p *ParserError) Error() string {
return p.message
buffer := bytes.NewBuffer(nil)
buffer.WriteString(p.message)
for _, e := range p.Errors {
buffer.WriteString("\n ")
buffer.WriteString(e.Error())
}
return buffer.String()
}
// Error represents an error identified by the parser, either syntactic

View File

@ -43,7 +43,7 @@ func Parse(reader io.Reader, options ...OptionFunc) (*model.Configuration, error
pos := ErrorPos{File: pe.Pos.Filename, Line: pe.Pos.Line, Column: pe.Pos.Column}
errors := ErrorList{newFatal(pos, pe.Err.Error())}
return nil, &ParserError{
message: pe.Err.Error(),
message: "unable to parse",
Errors: errors,
}
}
@ -548,24 +548,25 @@ func (ps *parseState) parseActionAttribute(name string, action *model.Action, va
case "uses":
ps.parseUses(action, val)
case "needs":
needs, ok := ps.literalToStringArray(val, true)
if ok {
if needs, ok := ps.literalToStringArray(val, true); ok {
action.Needs = needs
ps.posMap[&action.Needs] = val
}
case "runs":
ps.parseCommand(action, &action.Runs, name, val, false)
if runs := ps.parseCommand(action, action.Runs, name, val, false); runs != nil {
action.Runs = runs
}
case "args":
ps.parseCommand(action, &action.Args, name, val, true)
if args := ps.parseCommand(action, action.Args, name, val, true); args != nil {
action.Args = args
}
case "env":
env := ps.literalToStringMap(val)
if env != nil {
if env := ps.literalToStringMap(val); env != nil {
action.Env = env
}
ps.posMap[&action.Env] = val
case "secrets":
secrets, ok := ps.literalToStringArray(val, false)
if ok {
if secrets, ok := ps.literalToStringArray(val, false); ok {
action.Secrets = secrets
ps.posMap[&action.Secrets] = val
}
@ -621,11 +622,11 @@ func (ps *parseState) parseUses(action *model.Action, node ast.Node) {
}
}
// parseUses sets the action.Runs or action.Command value based on the
// parseUses sets the action.Runs or action.Args value based on the
// contents of the AST node. This function enforces formatting
// requirements on the value.
func (ps *parseState) parseCommand(action *model.Action, dest *model.ActionCommand, name string, node ast.Node, allowBlank bool) {
if len(dest.Parsed) > 0 {
func (ps *parseState) parseCommand(action *model.Action, cmd model.Command, name string, node ast.Node, allowBlank bool) model.Command {
if cmd != nil {
ps.addWarning(node, "`%s' redefined in action `%s'", name, action.Identifier)
// continue, allowing the redefinition
}
@ -633,9 +634,9 @@ func (ps *parseState) parseCommand(action *model.Action, dest *model.ActionComma
// Is it a list?
if _, ok := node.(*ast.ListType); ok {
if parsed, ok := ps.literalToStringArray(node, false); ok {
dest.Parsed = parsed
return &model.ListCommand{Values: parsed}
}
return
return nil
}
// If not, parse a whitespace-separated string into a list.
@ -643,14 +644,13 @@ func (ps *parseState) parseCommand(action *model.Action, dest *model.ActionComma
var ok bool
if raw, ok = ps.literalToString(node); !ok {
ps.addError(node, "The `%s' attribute must be a string or a list", name)
return
return nil
}
if raw == "" && !allowBlank {
ps.addError(node, "`%s' value in action `%s' cannot be blank", name, action.Identifier)
return
return nil
}
dest.Raw = raw
dest.Parsed = strings.Fields(raw)
return &model.StringCommand{Value: raw}
}
func typename(val interface{}) string {

2
vendor/modules.txt vendored
View File

@ -1,6 +1,6 @@
# github.com/Microsoft/go-winio v0.4.11
github.com/Microsoft/go-winio
# github.com/actions/workflow-parser v0.0.0-20190130154146-aac54e2ba131
# github.com/actions/workflow-parser v0.0.0-20190131180005-9cb71d183680
github.com/actions/workflow-parser/model
github.com/actions/workflow-parser/parser
# github.com/containerd/continuity v0.0.0-20181203112020-004b46473808