2020-02-10 18:35:00 -06:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2020-02-12 01:55:20 -06:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-02-10 18:35:00 -06:00
|
|
|
)
|
|
|
|
|
2022-12-09 19:14:14 -06:00
|
|
|
func TestReadWorkflow_ScheduleEvent(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on:
|
|
|
|
schedule:
|
|
|
|
- cron: '30 5 * * 1,3'
|
|
|
|
- cron: '30 5 * * 2,4'
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
|
|
|
|
schedules := workflow.OnEvent("schedule")
|
|
|
|
assert.Len(t, schedules, 2)
|
|
|
|
|
|
|
|
newSchedules := workflow.OnSchedule()
|
|
|
|
assert.Len(t, newSchedules, 2)
|
|
|
|
|
|
|
|
assert.Equal(t, "30 5 * * 1,3", newSchedules[0])
|
|
|
|
assert.Equal(t, "30 5 * * 2,4", newSchedules[1])
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on:
|
|
|
|
schedule:
|
|
|
|
test: '30 5 * * 1,3'
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
|
|
|
|
newSchedules = workflow.OnSchedule()
|
|
|
|
assert.Len(t, newSchedules, 0)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on:
|
|
|
|
schedule:
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
|
|
|
|
newSchedules = workflow.OnSchedule()
|
|
|
|
assert.Len(t, newSchedules, 0)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on: [push, tag]
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
|
|
|
|
newSchedules = workflow.OnSchedule()
|
|
|
|
assert.Len(t, newSchedules, 0)
|
|
|
|
}
|
|
|
|
|
2020-02-10 18:35:00 -06:00
|
|
|
func TestReadWorkflow_StringEvent(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on: push
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
2020-02-12 01:55:20 -06:00
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
2020-02-10 18:35:00 -06:00
|
|
|
|
2020-02-12 01:55:20 -06:00
|
|
|
assert.Len(t, workflow.On(), 1)
|
|
|
|
assert.Contains(t, workflow.On(), "push")
|
2020-02-10 18:35:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadWorkflow_ListEvent(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on: [push, pull_request]
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
2020-02-12 01:55:20 -06:00
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
2020-02-10 18:35:00 -06:00
|
|
|
|
2020-02-12 01:55:20 -06:00
|
|
|
assert.Len(t, workflow.On(), 2)
|
|
|
|
assert.Contains(t, workflow.On(), "push")
|
|
|
|
assert.Contains(t, workflow.On(), "pull_request")
|
2020-02-10 18:35:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadWorkflow_MapEvent(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
2021-04-01 13:36:41 -05:00
|
|
|
on:
|
2020-02-10 18:35:00 -06:00
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
2020-02-12 01:55:20 -06:00
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
assert.Len(t, workflow.On(), 2)
|
|
|
|
assert.Contains(t, workflow.On(), "push")
|
|
|
|
assert.Contains(t, workflow.On(), "pull_request")
|
2020-02-10 18:35:00 -06:00
|
|
|
}
|
2020-02-25 00:35:08 -06:00
|
|
|
|
2023-11-12 13:46:38 -06:00
|
|
|
func TestReadWorkflow_RunsOnLabels(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
container: nginx:latest
|
|
|
|
runs-on:
|
|
|
|
labels: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
assert.Equal(t, workflow.Jobs["test"].RunsOn(), []string{"ubuntu-latest"})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadWorkflow_RunsOnLabelsWithGroup(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
container: nginx:latest
|
|
|
|
runs-on:
|
|
|
|
labels: [ubuntu-latest]
|
|
|
|
group: linux
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
assert.Equal(t, workflow.Jobs["test"].RunsOn(), []string{"ubuntu-latest", "linux"})
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:35:08 -06:00
|
|
|
func TestReadWorkflow_StringContainer(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
container: nginx:latest
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
test2:
|
2021-04-01 13:36:41 -05:00
|
|
|
container:
|
2020-02-25 00:35:08 -06:00
|
|
|
image: nginx:latest
|
|
|
|
env:
|
|
|
|
foo: bar
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
assert.Len(t, workflow.Jobs, 2)
|
|
|
|
assert.Contains(t, workflow.Jobs["test"].Container().Image, "nginx:latest")
|
|
|
|
assert.Contains(t, workflow.Jobs["test2"].Container().Image, "nginx:latest")
|
|
|
|
assert.Contains(t, workflow.Jobs["test2"].Container().Env["foo"], "bar")
|
|
|
|
}
|
2021-04-01 13:36:41 -05:00
|
|
|
|
2021-11-27 12:05:56 -06:00
|
|
|
func TestReadWorkflow_ObjectContainer(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
container:
|
|
|
|
image: r.example.org/something:latest
|
|
|
|
credentials:
|
|
|
|
username: registry-username
|
|
|
|
password: registry-password
|
|
|
|
env:
|
|
|
|
HOME: /home/user
|
2022-04-04 13:01:13 -05:00
|
|
|
volumes:
|
|
|
|
- my_docker_volume:/volume_mount
|
|
|
|
- /data/my_data
|
|
|
|
- /source/directory:/destination/directory
|
2021-11-27 12:05:56 -06:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: ./actions/docker-url
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
assert.Len(t, workflow.Jobs, 1)
|
|
|
|
|
|
|
|
container := workflow.GetJob("test").Container()
|
|
|
|
|
|
|
|
assert.Contains(t, container.Image, "r.example.org/something:latest")
|
|
|
|
assert.Contains(t, container.Env["HOME"], "/home/user")
|
|
|
|
assert.Contains(t, container.Credentials["username"], "registry-username")
|
|
|
|
assert.Contains(t, container.Credentials["password"], "registry-password")
|
2022-04-04 13:01:13 -05:00
|
|
|
assert.ElementsMatch(t, container.Volumes, []string{
|
|
|
|
"my_docker_volume:/volume_mount",
|
|
|
|
"/data/my_data",
|
|
|
|
"/source/directory:/destination/directory",
|
|
|
|
})
|
2021-11-27 12:05:56 -06:00
|
|
|
}
|
|
|
|
|
2022-11-01 10:58:07 -05:00
|
|
|
func TestReadWorkflow_JobTypes(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: invalid job definition
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
default-job:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- run: echo
|
2023-07-10 23:27:43 -05:00
|
|
|
remote-reusable-workflow-yml:
|
|
|
|
uses: remote/repo/some/path/to/workflow.yml@main
|
|
|
|
remote-reusable-workflow-yaml:
|
|
|
|
uses: remote/repo/some/path/to/workflow.yaml@main
|
|
|
|
remote-reusable-workflow-custom-path:
|
|
|
|
uses: remote/repo/path/to/workflow.yml@main
|
|
|
|
local-reusable-workflow-yml:
|
|
|
|
uses: ./some/path/to/workflow.yml
|
|
|
|
local-reusable-workflow-yaml:
|
|
|
|
uses: ./some/path/to/workflow.yaml
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
assert.Len(t, workflow.Jobs, 6)
|
|
|
|
|
|
|
|
jobType, err := workflow.Jobs["default-job"].Type()
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
assert.Equal(t, JobTypeDefault, jobType)
|
|
|
|
|
|
|
|
jobType, err = workflow.Jobs["remote-reusable-workflow-yml"].Type()
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
assert.Equal(t, JobTypeReusableWorkflowRemote, jobType)
|
|
|
|
|
|
|
|
jobType, err = workflow.Jobs["remote-reusable-workflow-yaml"].Type()
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
assert.Equal(t, JobTypeReusableWorkflowRemote, jobType)
|
|
|
|
|
|
|
|
jobType, err = workflow.Jobs["remote-reusable-workflow-custom-path"].Type()
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
assert.Equal(t, JobTypeReusableWorkflowRemote, jobType)
|
|
|
|
|
|
|
|
jobType, err = workflow.Jobs["local-reusable-workflow-yml"].Type()
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
assert.Equal(t, JobTypeReusableWorkflowLocal, jobType)
|
|
|
|
|
|
|
|
jobType, err = workflow.Jobs["local-reusable-workflow-yaml"].Type()
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
assert.Equal(t, JobTypeReusableWorkflowLocal, jobType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadWorkflow_JobTypes_InvalidPath(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: invalid job definition
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
remote-reusable-workflow-missing-version:
|
|
|
|
uses: remote/repo/some/path/to/workflow.yml
|
|
|
|
remote-reusable-workflow-bad-extension:
|
|
|
|
uses: remote/repo/some/path/to/workflow.json
|
|
|
|
local-reusable-workflow-bad-extension:
|
|
|
|
uses: ./some/path/to/workflow.json
|
|
|
|
local-reusable-workflow-bad-path:
|
|
|
|
uses: some/path/to/workflow.yaml
|
2022-11-01 10:58:07 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
2023-07-10 23:27:43 -05:00
|
|
|
assert.Len(t, workflow.Jobs, 4)
|
|
|
|
|
|
|
|
jobType, err := workflow.Jobs["remote-reusable-workflow-missing-version"].Type()
|
|
|
|
assert.Equal(t, JobTypeInvalid, jobType)
|
|
|
|
assert.NotEqual(t, nil, err)
|
|
|
|
|
|
|
|
jobType, err = workflow.Jobs["remote-reusable-workflow-bad-extension"].Type()
|
|
|
|
assert.Equal(t, JobTypeInvalid, jobType)
|
|
|
|
assert.NotEqual(t, nil, err)
|
|
|
|
|
|
|
|
jobType, err = workflow.Jobs["local-reusable-workflow-bad-extension"].Type()
|
|
|
|
assert.Equal(t, JobTypeInvalid, jobType)
|
|
|
|
assert.NotEqual(t, nil, err)
|
|
|
|
|
|
|
|
jobType, err = workflow.Jobs["local-reusable-workflow-bad-path"].Type()
|
|
|
|
assert.Equal(t, JobTypeInvalid, jobType)
|
|
|
|
assert.NotEqual(t, nil, err)
|
2022-11-01 10:58:07 -05:00
|
|
|
}
|
|
|
|
|
2021-04-01 13:36:41 -05:00
|
|
|
func TestReadWorkflow_StepsTypes(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: invalid step definition
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: test1
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
run: echo
|
|
|
|
- name: test2
|
|
|
|
run: echo
|
|
|
|
- name: test3
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
- name: test4
|
|
|
|
uses: docker://nginx:latest
|
|
|
|
- name: test5
|
|
|
|
uses: ./local-action
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
assert.Len(t, workflow.Jobs, 1)
|
|
|
|
assert.Len(t, workflow.Jobs["test"].Steps, 5)
|
|
|
|
assert.Equal(t, workflow.Jobs["test"].Steps[0].Type(), StepTypeInvalid)
|
|
|
|
assert.Equal(t, workflow.Jobs["test"].Steps[1].Type(), StepTypeRun)
|
|
|
|
assert.Equal(t, workflow.Jobs["test"].Steps[2].Type(), StepTypeUsesActionRemote)
|
|
|
|
assert.Equal(t, workflow.Jobs["test"].Steps[3].Type(), StepTypeUsesDockerURL)
|
|
|
|
assert.Equal(t, workflow.Jobs["test"].Steps[4].Type(), StepTypeUsesActionLocal)
|
|
|
|
}
|
2021-05-05 00:57:33 -05:00
|
|
|
|
2021-07-01 10:20:20 -05:00
|
|
|
// See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs
|
|
|
|
func TestReadWorkflow_JobOutputs(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: job outputs definition
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
test1:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- id: test1_1
|
|
|
|
run: |
|
|
|
|
echo "::set-output name=a_key::some-a_value"
|
|
|
|
echo "::set-output name=b-key::some-b-value"
|
|
|
|
outputs:
|
|
|
|
some_a_key: ${{ steps.test1_1.outputs.a_key }}
|
|
|
|
some-b-key: ${{ steps.test1_1.outputs.b-key }}
|
|
|
|
|
|
|
|
test2:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs:
|
|
|
|
- test1
|
|
|
|
steps:
|
|
|
|
- name: test2_1
|
|
|
|
run: |
|
|
|
|
echo "${{ needs.test1.outputs.some_a_key }}"
|
|
|
|
echo "${{ needs.test1.outputs.some-b-key }}"
|
|
|
|
`
|
|
|
|
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
assert.Len(t, workflow.Jobs, 2)
|
|
|
|
|
|
|
|
assert.Len(t, workflow.Jobs["test1"].Steps, 1)
|
|
|
|
assert.Equal(t, StepTypeRun, workflow.Jobs["test1"].Steps[0].Type())
|
|
|
|
assert.Equal(t, "test1_1", workflow.Jobs["test1"].Steps[0].ID)
|
|
|
|
assert.Len(t, workflow.Jobs["test1"].Outputs, 2)
|
|
|
|
assert.Contains(t, workflow.Jobs["test1"].Outputs, "some_a_key")
|
|
|
|
assert.Contains(t, workflow.Jobs["test1"].Outputs, "some-b-key")
|
|
|
|
assert.Equal(t, "${{ steps.test1_1.outputs.a_key }}", workflow.Jobs["test1"].Outputs["some_a_key"])
|
|
|
|
assert.Equal(t, "${{ steps.test1_1.outputs.b-key }}", workflow.Jobs["test1"].Outputs["some-b-key"])
|
|
|
|
}
|
|
|
|
|
2021-08-09 10:35:05 -05:00
|
|
|
func TestReadWorkflow_Strategy(t *testing.T) {
|
|
|
|
w, err := NewWorkflowPlanner("testdata/strategy/push.yml", true)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2023-02-16 10:41:59 -06:00
|
|
|
p, err := w.PlanJob("strategy-only-max-parallel")
|
|
|
|
assert.NoError(t, err)
|
2021-08-09 10:35:05 -05:00
|
|
|
|
|
|
|
assert.Equal(t, len(p.Stages), 1)
|
|
|
|
assert.Equal(t, len(p.Stages[0].Runs), 1)
|
|
|
|
|
|
|
|
wf := p.Stages[0].Runs[0].Workflow
|
|
|
|
|
|
|
|
job := wf.Jobs["strategy-only-max-parallel"]
|
2023-04-07 03:31:03 -05:00
|
|
|
matrixes, err := job.GetMatrixes()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, matrixes, []map[string]interface{}{{}})
|
2021-08-09 10:35:05 -05:00
|
|
|
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
|
|
|
assert.Equal(t, job.Strategy.MaxParallel, 2)
|
|
|
|
assert.Equal(t, job.Strategy.FailFast, true)
|
|
|
|
|
|
|
|
job = wf.Jobs["strategy-only-fail-fast"]
|
2023-04-07 03:31:03 -05:00
|
|
|
matrixes, err = job.GetMatrixes()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, matrixes, []map[string]interface{}{{}})
|
2021-08-09 10:35:05 -05:00
|
|
|
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
|
|
|
assert.Equal(t, job.Strategy.MaxParallel, 4)
|
|
|
|
assert.Equal(t, job.Strategy.FailFast, false)
|
|
|
|
|
|
|
|
job = wf.Jobs["strategy-no-matrix"]
|
2023-04-07 03:31:03 -05:00
|
|
|
matrixes, err = job.GetMatrixes()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, matrixes, []map[string]interface{}{{}})
|
2021-08-09 10:35:05 -05:00
|
|
|
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
|
|
|
|
assert.Equal(t, job.Strategy.MaxParallel, 2)
|
|
|
|
assert.Equal(t, job.Strategy.FailFast, false)
|
|
|
|
|
|
|
|
job = wf.Jobs["strategy-all"]
|
2023-04-07 03:31:03 -05:00
|
|
|
matrixes, err = job.GetMatrixes()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, matrixes,
|
2021-08-09 10:35:05 -05:00
|
|
|
[]map[string]interface{}{
|
|
|
|
{"datacenter": "site-c", "node-version": "14.x", "site": "staging"},
|
|
|
|
{"datacenter": "site-c", "node-version": "16.x", "site": "staging"},
|
|
|
|
{"datacenter": "site-d", "node-version": "16.x", "site": "staging"},
|
2022-06-20 17:33:07 -05:00
|
|
|
{"php-version": 5.4},
|
2021-08-09 10:35:05 -05:00
|
|
|
{"datacenter": "site-a", "node-version": "10.x", "site": "prod"},
|
|
|
|
{"datacenter": "site-b", "node-version": "12.x", "site": "dev"},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert.Equal(t, job.Matrix(),
|
|
|
|
map[string][]interface{}{
|
|
|
|
"datacenter": {"site-c", "site-d"},
|
|
|
|
"exclude": {
|
|
|
|
map[string]interface{}{"datacenter": "site-d", "node-version": "14.x", "site": "staging"},
|
|
|
|
},
|
|
|
|
"include": {
|
|
|
|
map[string]interface{}{"php-version": 5.4},
|
|
|
|
map[string]interface{}{"datacenter": "site-a", "node-version": "10.x", "site": "prod"},
|
|
|
|
map[string]interface{}{"datacenter": "site-b", "node-version": "12.x", "site": "dev"},
|
|
|
|
},
|
|
|
|
"node-version": {"14.x", "16.x"},
|
|
|
|
"site": {"staging"},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
assert.Equal(t, job.Strategy.MaxParallel, 2)
|
|
|
|
assert.Equal(t, job.Strategy.FailFast, false)
|
|
|
|
}
|
|
|
|
|
2021-05-05 00:57:33 -05:00
|
|
|
func TestStep_ShellCommand(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
shell string
|
|
|
|
want string
|
|
|
|
}{
|
2021-12-22 00:37:16 -06:00
|
|
|
{"pwsh -v '. {0}'", "pwsh -v '. {0}'"},
|
2021-05-05 00:57:33 -05:00
|
|
|
{"pwsh", "pwsh -command . '{0}'"},
|
|
|
|
{"powershell", "powershell -command . '{0}'"},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.shell, func(t *testing.T) {
|
|
|
|
got := (&Step{Shell: tt.shell}).ShellCommand()
|
|
|
|
assert.Equal(t, got, tt.want)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-01-20 08:07:36 -06:00
|
|
|
|
|
|
|
func TestReadWorkflow_WorkflowDispatchConfig(t *testing.T) {
|
|
|
|
yaml := `
|
|
|
|
name: local-action-docker-url
|
|
|
|
`
|
|
|
|
workflow, err := ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
workflowDispatch := workflow.WorkflowDispatchConfig()
|
|
|
|
assert.Nil(t, workflowDispatch)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on: push
|
|
|
|
`
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
workflowDispatch = workflow.WorkflowDispatchConfig()
|
|
|
|
assert.Nil(t, workflowDispatch)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on: workflow_dispatch
|
|
|
|
`
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
workflowDispatch = workflow.WorkflowDispatchConfig()
|
|
|
|
assert.NotNil(t, workflowDispatch)
|
|
|
|
assert.Nil(t, workflowDispatch.Inputs)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on: [push, pull_request]
|
|
|
|
`
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
workflowDispatch = workflow.WorkflowDispatchConfig()
|
|
|
|
assert.Nil(t, workflowDispatch)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on: [push, workflow_dispatch]
|
|
|
|
`
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
workflowDispatch = workflow.WorkflowDispatchConfig()
|
|
|
|
assert.NotNil(t, workflowDispatch)
|
|
|
|
assert.Nil(t, workflowDispatch.Inputs)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on:
|
|
|
|
- push
|
|
|
|
- workflow_dispatch
|
|
|
|
`
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
workflowDispatch = workflow.WorkflowDispatchConfig()
|
|
|
|
assert.NotNil(t, workflowDispatch)
|
|
|
|
assert.Nil(t, workflowDispatch.Inputs)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
pull_request:
|
|
|
|
`
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
workflowDispatch = workflow.WorkflowDispatchConfig()
|
|
|
|
assert.Nil(t, workflowDispatch)
|
|
|
|
|
|
|
|
yaml = `
|
|
|
|
name: local-action-docker-url
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
pull_request:
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
logLevel:
|
|
|
|
description: 'Log level'
|
|
|
|
required: true
|
|
|
|
default: 'warning'
|
|
|
|
type: choice
|
|
|
|
options:
|
|
|
|
- info
|
|
|
|
- warning
|
|
|
|
- debug
|
|
|
|
`
|
|
|
|
workflow, err = ReadWorkflow(strings.NewReader(yaml))
|
|
|
|
assert.NoError(t, err, "read workflow should succeed")
|
|
|
|
workflowDispatch = workflow.WorkflowDispatchConfig()
|
|
|
|
assert.NotNil(t, workflowDispatch)
|
|
|
|
assert.Equal(t, WorkflowDispatchInput{
|
|
|
|
Default: "warning",
|
|
|
|
Description: "Log level",
|
|
|
|
Options: []string{
|
|
|
|
"info",
|
|
|
|
"warning",
|
|
|
|
"debug",
|
|
|
|
},
|
|
|
|
Required: true,
|
|
|
|
Type: "choice",
|
|
|
|
}, workflowDispatch.Inputs["logLevel"])
|
|
|
|
}
|