2020-02-04 18:38:41 -06:00
|
|
|
package runner
|
2019-01-31 01:53:39 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-02-10 17:27:05 -06:00
|
|
|
"fmt"
|
2020-03-06 14:30:24 -06:00
|
|
|
"os"
|
2020-02-24 12:56:49 -06:00
|
|
|
"path/filepath"
|
2019-01-31 01:53:39 -06:00
|
|
|
"testing"
|
|
|
|
|
2020-03-06 14:30:24 -06:00
|
|
|
"github.com/joho/godotenv"
|
2020-02-10 17:27:05 -06:00
|
|
|
"github.com/nektos/act/pkg/model"
|
|
|
|
|
2019-01-31 01:53:39 -06:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"gotest.tools/assert"
|
|
|
|
)
|
|
|
|
|
2019-04-08 06:01:49 -05:00
|
|
|
func TestGraphEvent(t *testing.T) {
|
2020-02-10 17:27:05 -06:00
|
|
|
planner, err := model.NewWorkflowPlanner("testdata/basic")
|
2019-04-08 06:01:49 -05:00
|
|
|
assert.NilError(t, err)
|
|
|
|
|
2020-02-10 17:27:05 -06:00
|
|
|
plan := planner.PlanEvent("push")
|
2019-04-08 06:01:49 -05:00
|
|
|
assert.NilError(t, err)
|
2020-02-19 21:20:47 -06:00
|
|
|
assert.Equal(t, len(plan.Stages), 3, "stages")
|
2020-02-10 17:27:05 -06:00
|
|
|
assert.Equal(t, len(plan.Stages[0].Runs), 1, "stage0.runs")
|
|
|
|
assert.Equal(t, len(plan.Stages[1].Runs), 1, "stage1.runs")
|
2020-02-19 21:20:47 -06:00
|
|
|
assert.Equal(t, len(plan.Stages[2].Runs), 1, "stage2.runs")
|
|
|
|
assert.Equal(t, plan.Stages[0].Runs[0].JobID, "check", "jobid")
|
|
|
|
assert.Equal(t, plan.Stages[1].Runs[0].JobID, "build", "jobid")
|
|
|
|
assert.Equal(t, plan.Stages[2].Runs[0].JobID, "test", "jobid")
|
2019-04-08 06:01:49 -05:00
|
|
|
|
2020-02-10 17:27:05 -06:00
|
|
|
plan = planner.PlanEvent("release")
|
|
|
|
assert.Equal(t, len(plan.Stages), 0, "stages")
|
2019-04-08 06:01:49 -05:00
|
|
|
}
|
|
|
|
|
2019-01-31 01:53:39 -06:00
|
|
|
func TestRunEvent(t *testing.T) {
|
2019-02-07 11:09:19 -06:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping integration test")
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:53:39 -06:00
|
|
|
tables := []struct {
|
|
|
|
workflowPath string
|
|
|
|
eventName string
|
|
|
|
errorMessage string
|
|
|
|
}{
|
2020-02-12 01:55:20 -06:00
|
|
|
{"basic", "push", ""},
|
|
|
|
{"fail", "push", "exit with `FAILURE`: 1"},
|
2020-02-10 17:27:05 -06:00
|
|
|
{"runs-on", "push", ""},
|
2020-02-12 01:55:20 -06:00
|
|
|
{"job-container", "push", ""},
|
|
|
|
{"uses-docker-url", "push", ""},
|
|
|
|
{"remote-action-docker", "push", ""},
|
|
|
|
{"remote-action-js", "push", ""},
|
|
|
|
{"local-action-docker-url", "push", ""},
|
|
|
|
{"local-action-dockerfile", "push", ""},
|
2020-02-27 01:29:43 -06:00
|
|
|
{"matrix", "push", ""},
|
|
|
|
{"commands", "push", ""},
|
2019-01-31 01:53:39 -06:00
|
|
|
}
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
|
2020-02-10 17:27:05 -06:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-01-31 01:53:39 -06:00
|
|
|
for _, table := range tables {
|
2019-05-22 23:39:57 -05:00
|
|
|
table := table
|
|
|
|
t.Run(table.workflowPath, func(t *testing.T) {
|
2020-02-19 21:20:47 -06:00
|
|
|
platforms := map[string]string{
|
2020-02-22 00:19:59 -06:00
|
|
|
"ubuntu-latest": "node:12.6-buster-slim",
|
2020-02-19 21:20:47 -06:00
|
|
|
}
|
2020-02-24 12:56:49 -06:00
|
|
|
|
|
|
|
workdir, err := filepath.Abs("testdata")
|
|
|
|
assert.NilError(t, err, table.workflowPath)
|
2020-02-10 17:27:05 -06:00
|
|
|
runnerConfig := &Config{
|
2020-02-24 12:56:49 -06:00
|
|
|
Workdir: workdir,
|
2020-02-12 01:38:30 -06:00
|
|
|
EventName: table.eventName,
|
2020-02-19 21:20:47 -06:00
|
|
|
Platforms: platforms,
|
2020-02-22 00:19:59 -06:00
|
|
|
ReuseContainers: false,
|
2019-05-22 23:39:57 -05:00
|
|
|
}
|
2020-02-10 17:27:05 -06:00
|
|
|
runner, err := New(runnerConfig)
|
2019-01-31 01:53:39 -06:00
|
|
|
assert.NilError(t, err, table.workflowPath)
|
2019-05-22 23:39:57 -05:00
|
|
|
|
2020-02-10 17:27:05 -06:00
|
|
|
planner, err := model.NewWorkflowPlanner(fmt.Sprintf("testdata/%s", table.workflowPath))
|
|
|
|
assert.NilError(t, err, table.workflowPath)
|
|
|
|
|
|
|
|
plan := planner.PlanEvent(table.eventName)
|
|
|
|
|
|
|
|
err = runner.NewPlanExecutor(plan)(ctx)
|
2019-05-22 23:39:57 -05:00
|
|
|
if table.errorMessage == "" {
|
|
|
|
assert.NilError(t, err, table.workflowPath)
|
|
|
|
} else {
|
|
|
|
assert.ErrorContains(t, err, table.errorMessage)
|
|
|
|
}
|
|
|
|
})
|
2019-01-31 01:53:39 -06:00
|
|
|
}
|
|
|
|
}
|
2020-03-06 14:30:24 -06:00
|
|
|
|
|
|
|
func TestRunEventSecrets(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping integration test")
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
platforms := map[string]string{
|
|
|
|
"ubuntu-latest": "node:12.6-buster-slim",
|
|
|
|
}
|
|
|
|
|
|
|
|
workflowPath := "secrets"
|
|
|
|
eventName := "push"
|
|
|
|
|
|
|
|
workdir, err := filepath.Abs("testdata")
|
|
|
|
assert.NilError(t, err, workflowPath)
|
|
|
|
|
|
|
|
_ = godotenv.Load(filepath.Join(workdir, workflowPath, ".env"))
|
|
|
|
|
|
|
|
secrets := make(map[string]string)
|
|
|
|
for _, secret := range []string{
|
|
|
|
"MY_SECRET",
|
|
|
|
"MULTILINE_SECRET",
|
|
|
|
"JSON_SECRET",
|
|
|
|
} {
|
|
|
|
if env, ok := os.LookupEnv(secret); ok && env != "" {
|
|
|
|
secrets[secret] = env
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runnerConfig := &Config{
|
|
|
|
Workdir: workdir,
|
|
|
|
EventName: eventName,
|
|
|
|
Platforms: platforms,
|
|
|
|
ReuseContainers: false,
|
|
|
|
Secrets: secrets,
|
|
|
|
}
|
|
|
|
runner, err := New(runnerConfig)
|
|
|
|
assert.NilError(t, err, workflowPath)
|
|
|
|
|
|
|
|
planner, err := model.NewWorkflowPlanner(fmt.Sprintf("testdata/%s", workflowPath))
|
|
|
|
assert.NilError(t, err, workflowPath)
|
|
|
|
|
|
|
|
plan := planner.PlanEvent(eventName)
|
|
|
|
|
|
|
|
err = runner.NewPlanExecutor(plan)(ctx)
|
|
|
|
assert.NilError(t, err, workflowPath)
|
|
|
|
}
|