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-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"
|
2019-01-31 01:53:39 -06:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-08-30 00:55:22 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2021-03-28 23:08:40 -05:00
|
|
|
|
|
|
|
"github.com/nektos/act/pkg/model"
|
2019-01-31 01:53:39 -06:00
|
|
|
)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-29 23:45:11 -06:00
|
|
|
type TestJobFileInfo struct {
|
2021-03-28 23:08:40 -05:00
|
|
|
workdir string
|
|
|
|
workflowPath string
|
|
|
|
eventName string
|
|
|
|
errorMessage string
|
|
|
|
platforms map[string]string
|
|
|
|
containerArchitecture string
|
2020-11-29 23:45:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func runTestJobFile(ctx context.Context, t *testing.T, tjfi TestJobFileInfo) {
|
|
|
|
t.Run(tjfi.workflowPath, func(t *testing.T) {
|
|
|
|
workdir, err := filepath.Abs(tjfi.workdir)
|
|
|
|
assert.NilError(t, err, workdir)
|
|
|
|
fullWorkflowPath := filepath.Join(workdir, tjfi.workflowPath)
|
|
|
|
runnerConfig := &Config{
|
2021-03-28 23:08:40 -05:00
|
|
|
Workdir: workdir,
|
|
|
|
BindWorkdir: true,
|
|
|
|
EventName: tjfi.eventName,
|
|
|
|
Platforms: tjfi.platforms,
|
|
|
|
ReuseContainers: false,
|
|
|
|
ContainerArchitecture: tjfi.containerArchitecture,
|
2020-11-29 23:45:11 -06:00
|
|
|
}
|
|
|
|
runner, err := New(runnerConfig)
|
|
|
|
assert.NilError(t, err, tjfi.workflowPath)
|
|
|
|
|
|
|
|
planner, err := model.NewWorkflowPlanner(fullWorkflowPath)
|
|
|
|
assert.NilError(t, err, fullWorkflowPath)
|
|
|
|
|
|
|
|
plan := planner.PlanEvent(tjfi.eventName)
|
|
|
|
|
|
|
|
err = runner.NewPlanExecutor(plan)(ctx)
|
|
|
|
if tjfi.errorMessage == "" {
|
|
|
|
assert.NilError(t, err, fullWorkflowPath)
|
|
|
|
} else {
|
|
|
|
assert.ErrorContains(t, err, tjfi.errorMessage)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2020-11-29 23:45:11 -06:00
|
|
|
platforms := map[string]string{
|
2021-02-23 11:49:24 -06:00
|
|
|
"ubuntu-latest": "node:12.20.1-buster-slim",
|
2020-11-29 23:45:11 -06:00
|
|
|
}
|
|
|
|
tables := []TestJobFileInfo{
|
2021-03-28 23:08:40 -05:00
|
|
|
{"testdata", "basic", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "fail", "push", "exit with `FAILURE`: 1", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "runs-on", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "job-container", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "job-container-non-root", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "uses-docker-url", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "remote-action-docker", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "remote-action-js", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "local-action-docker-url", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "local-action-dockerfile", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "local-action-js", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "matrix", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "matrix-include-exclude", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "commands", "push", "", platforms, "linux/amd64"},
|
|
|
|
{"testdata", "workdir", "push", "", platforms, "linux/amd64"},
|
|
|
|
// {"testdata", "issue-228", "push", "", platforms, "linux/amd64"}, // TODO [igni]: Remove this once everything passes
|
|
|
|
{"testdata", "defaults-run", "push", "", platforms, "linux/amd64"},
|
|
|
|
|
|
|
|
// linux/arm64
|
|
|
|
{"testdata", "basic", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "fail", "push", "exit with `FAILURE`: 1", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "runs-on", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "job-container", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "job-container-non-root", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "uses-docker-url", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "remote-action-docker", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "remote-action-js", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "local-action-docker-url", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "local-action-dockerfile", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "local-action-js", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "matrix", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "matrix-include-exclude", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "commands", "push", "", platforms, "linux/arm64"},
|
|
|
|
{"testdata", "workdir", "push", "", platforms, "linux/arm64"},
|
|
|
|
// {"testdata", "issue-228", "push", "", platforms, "linux/arm64"}, // TODO [igni]: Remove this once everything passes
|
|
|
|
{"testdata", "defaults-run", "push", "", platforms, "linux/arm64"},
|
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 {
|
2020-11-29 23:45:11 -06:00
|
|
|
runTestJobFile(ctx, t, table)
|
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{
|
2021-02-23 11:49:24 -06:00
|
|
|
"ubuntu-latest": "node:12.20.1-buster-slim",
|
2020-03-06 14:30:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
workflowPath := "secrets"
|
|
|
|
eventName := "push"
|
|
|
|
|
|
|
|
workdir, err := filepath.Abs("testdata")
|
|
|
|
assert.NilError(t, err, workflowPath)
|
|
|
|
|
2020-04-17 12:04:40 -05:00
|
|
|
env, _ := godotenv.Read(filepath.Join(workdir, workflowPath, ".env"))
|
|
|
|
secrets, _ := godotenv.Read(filepath.Join(workdir, workflowPath, ".secrets"))
|
2020-03-06 14:30:24 -06:00
|
|
|
|
|
|
|
runnerConfig := &Config{
|
|
|
|
Workdir: workdir,
|
|
|
|
EventName: eventName,
|
|
|
|
Platforms: platforms,
|
|
|
|
ReuseContainers: false,
|
|
|
|
Secrets: secrets,
|
2020-04-17 12:04:40 -05:00
|
|
|
Env: env,
|
2020-03-06 14:30:24 -06:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
2020-03-06 16:17:57 -06:00
|
|
|
|
|
|
|
func TestRunEventPullRequest(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping integration test")
|
|
|
|
}
|
|
|
|
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
platforms := map[string]string{
|
2021-02-23 11:49:24 -06:00
|
|
|
"ubuntu-latest": "node:12.20.1-buster-slim",
|
2020-03-06 16:17:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
workflowPath := "pull-request"
|
|
|
|
eventName := "pull_request"
|
|
|
|
|
|
|
|
workdir, err := filepath.Abs("testdata")
|
|
|
|
assert.NilError(t, err, workflowPath)
|
|
|
|
|
|
|
|
runnerConfig := &Config{
|
|
|
|
Workdir: workdir,
|
|
|
|
EventName: eventName,
|
|
|
|
EventPath: filepath.Join(workdir, workflowPath, "event.json"),
|
|
|
|
Platforms: platforms,
|
|
|
|
ReuseContainers: false,
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|