diff --git a/WORKFLOW_SUPPORT.md b/WORKFLOW_SUPPORT.md index 30a8555..a8eb50f 100644 --- a/WORKFLOW_SUPPORT.md +++ b/WORKFLOW_SUPPORT.md @@ -12,7 +12,7 @@ syntax](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for - [ ] env - [ ] defaults - [x] jobs - - [ ] jobs..name + - [x] jobs..name - [ ] jobs..permissions - [x] jobs..needs (ordering, not success) - [ ] jobs..if diff --git a/internal/workflow/create.go b/internal/workflow/create.go index 04de2ee..4075411 100644 --- a/internal/workflow/create.go +++ b/internal/workflow/create.go @@ -16,6 +16,16 @@ func FromYamlBytes(raw []byte) (*Workflow, error) { return nil, yamlError } + // If not "name" prop is provided, it defaults to the + // key that is used in the jobs object. + for jobLabel, job := range workflow.Jobs { + if job.Name == "" { + job.Name = jobLabel + } + + workflow.Jobs[jobLabel] = job + } + return &workflow, nil } diff --git a/internal/workflow/create_test.go b/internal/workflow/create_test.go index 147a8ed..9e7f4de 100644 --- a/internal/workflow/create_test.go +++ b/internal/workflow/create_test.go @@ -26,6 +26,22 @@ jobs: } } +func TestFromYamlBytesDefaultsJobNameToObjectKey(t *testing.T) { + sample := ` +jobs: + jobA: + runs-on: default + steps: + - run: echo "test" + ` + + workflow, _ := FromYamlBytes([]byte(sample)) + + if workflow.Jobs["jobA"].Name != "jobA" { + t.Errorf("Expected job name to be \"jobA\", got %s instead.", workflow.Jobs["jobA"].Name) + } +} + func TestFromYamlBytesReturnsErrorIfErrorParsing(t *testing.T) { sample := `not-yaml!` diff --git a/internal/workflow/models.go b/internal/workflow/models.go index 481dd13..04d0db4 100644 --- a/internal/workflow/models.go +++ b/internal/workflow/models.go @@ -8,6 +8,8 @@ type Job struct { RunsOn string `yaml:"runs-on"` Steps []Step `yaml:"steps"` Needs []string `yaml:"needs"` + // Job name; this isn't guaranteed to be unique. + Name string `yaml:"name"` } func (j Job) Validate() []error {