feat: add job name and job name default support

This commit is contained in:
Marc 2024-08-09 00:31:06 -04:00
parent 56295fe89e
commit c352b05d6c
Signed by: marc
GPG key ID: 048E042F22B5DC79
4 changed files with 29 additions and 1 deletions

View file

@ -12,7 +12,7 @@ syntax](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for
- [ ] env - [ ] env
- [ ] defaults - [ ] defaults
- [x] jobs - [x] jobs
- [ ] jobs.<job_id>.name - [x] jobs.<job_id>.name
- [ ] jobs.<job_id>.permissions - [ ] jobs.<job_id>.permissions
- [x] jobs.<job_id>.needs (ordering, not success) - [x] jobs.<job_id>.needs (ordering, not success)
- [ ] jobs.<job_id>.if - [ ] jobs.<job_id>.if

View file

@ -16,6 +16,16 @@ func FromYamlBytes(raw []byte) (*Workflow, error) {
return nil, yamlError 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 return &workflow, nil
} }

View file

@ -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) { func TestFromYamlBytesReturnsErrorIfErrorParsing(t *testing.T) {
sample := `not-yaml!` sample := `not-yaml!`

View file

@ -8,6 +8,8 @@ type Job struct {
RunsOn string `yaml:"runs-on"` RunsOn string `yaml:"runs-on"`
Steps []Step `yaml:"steps"` Steps []Step `yaml:"steps"`
Needs []string `yaml:"needs"` Needs []string `yaml:"needs"`
// Job name; this isn't guaranteed to be unique.
Name string `yaml:"name"`
} }
func (j Job) Validate() []error { func (j Job) Validate() []error {