Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0a37a03f2e | ||
|
88cce47022 |
@@ -67,6 +67,30 @@ func (w *Workflow) OnEvent(event string) interface{} {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Workflow) OnSchedule() []string {
|
||||||
|
schedules := w.OnEvent("schedule")
|
||||||
|
if schedules == nil {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch val := schedules.(type) {
|
||||||
|
case []interface{}:
|
||||||
|
allSchedules := []string{}
|
||||||
|
for _, v := range val {
|
||||||
|
for k, cron := range v.(map[string]interface{}) {
|
||||||
|
if k != "cron" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
allSchedules = append(allSchedules, cron.(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return allSchedules
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
type WorkflowDispatchInput struct {
|
type WorkflowDispatchInput struct {
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description"`
|
||||||
Required bool `yaml:"required"`
|
Required bool `yaml:"required"`
|
||||||
@@ -487,7 +511,7 @@ func (s *Step) GetEnv() map[string]string {
|
|||||||
func (s *Step) ShellCommand() string {
|
func (s *Step) ShellCommand() string {
|
||||||
shellCommand := ""
|
shellCommand := ""
|
||||||
|
|
||||||
//Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17
|
// Reference: https://github.com/actions/runner/blob/8109c962f09d9acc473d92c595ff43afceddb347/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L9-L17
|
||||||
switch s.Shell {
|
switch s.Shell {
|
||||||
case "", "bash":
|
case "", "bash":
|
||||||
shellCommand = "bash --noprofile --norc -e -o pipefail {0}"
|
shellCommand = "bash --noprofile --norc -e -o pipefail {0}"
|
||||||
|
@@ -7,6 +7,88 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadWorkflow_StringEvent(t *testing.T) {
|
func TestReadWorkflow_StringEvent(t *testing.T) {
|
||||||
yaml := `
|
yaml := `
|
||||||
name: local-action-docker-url
|
name: local-action-docker-url
|
||||||
|
@@ -64,7 +64,13 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
|
|||||||
URL: sar.remoteAction.CloneURL(),
|
URL: sar.remoteAction.CloneURL(),
|
||||||
Ref: sar.remoteAction.Ref,
|
Ref: sar.remoteAction.Ref,
|
||||||
Dir: actionDir,
|
Dir: actionDir,
|
||||||
Token: github.Token,
|
Token: "", /*
|
||||||
|
Shouldn't provide token when cloning actions,
|
||||||
|
the token comes from the instance which triggered the task,
|
||||||
|
however, it might be not the same instance which provides actions.
|
||||||
|
For GitHub, they are the same, always github.com.
|
||||||
|
But for Gitea, tasks triggered by a.com can clone actions from b.com.
|
||||||
|
*/
|
||||||
})
|
})
|
||||||
var ntErr common.Executor
|
var ntErr common.Executor
|
||||||
if err := gitClone(ctx); err != nil {
|
if err := gitClone(ctx); err != nil {
|
||||||
|
Reference in New Issue
Block a user