Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pkg/parser/validate/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ func (val Validate) validateSingleWorkflow(workflow ast.Workflow) error {
continue
}

isApprovalJob := jobRef.Type == "approval"
if isApprovalJob {
// Define valid job types
validJobTypesMap := map[string]bool{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 more job types that were added recently: lock and unlock

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@briceicle do we mention in our docs? Because I reference the job ref for schema store pr (another repo) and we dont list them there https://circleci.com/docs/configuration-reference/#job-type

"approval": true,
"build": true,
"no-op": true,
"release": true,
}

// Direct lookup in the map
if validJobTypesMap[jobRef.Type] {
continue
}

jobTypeIsDefined := jobRef.Type != ""
if jobTypeIsDefined {
val.addDiagnostic(utils.CreateErrorDiagnosticFromRange(jobRef.TypeRange, "Type can only be \"approval\""))
val.addDiagnostic(utils.CreateErrorDiagnosticFromRange(jobRef.TypeRange, fmt.Sprintf("Job Type \"%s\" is not valid", jobRef.Type)))
continue
}

Expand Down
33 changes: 32 additions & 1 deletion pkg/parser/validate/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ workflows:
utils.CreateErrorDiagnosticFromRange(protocol.Range{
Start: protocol.Position{Line: 0x6, Character: 0x10},
End: protocol.Position{Line: 0x6, Character: 0x17},
}, "Type can only be \"approval\""),
}, "Job Type \"invalid\" is not valid"),
},
},
{
Expand Down Expand Up @@ -90,6 +90,37 @@ workflows:
- deploy:
override-with: local/deploy`,
},
{
Name: "No-op job type",
YamlContent: `version: 2.1

workflows:
someworkflow:
jobs:
- hold:
type: no-op`,
},
{
Name: "Release job type",
YamlContent: `version: 2.1

workflows:
someworkflow:
jobs:
- hold:
type: release
plan_name: my-service-release`,
},
{
Name: "Build job type",
YamlContent: `version: 2.1

workflows:
someworkflow:
jobs:
- hold:
type: build`,
},
}

CheckYamlErrors(t, testCases)
Expand Down
5 changes: 3 additions & 2 deletions pkg/services/hover/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ func jobReference(name string) string {
"- `requires`: Jobs are run in parallel by default, so you must explicitly require any dependencies by their job name.\n" +
"- `name`: can be used to invoke reusable jobs across any number of workflows. Using the `name` key ensures numbers are not appended to your job name (i.e. sayhello-1 , sayhello-2, etc.). The name you assign to the name key needs to be unique, otherwise the numbers will still be appended to the job name.\n" +
"- `context`: Jobs may be configured to use global environment variables set for an organization, see the Contexts document for adding a context in the application settings.\n" +
"- `type`: A job may have a type of `approval` indicating it must be manually approved before downstream jobs may proceed.\n" +
"- `type`: Job type, can be build, release, no-op, or approval. If not specified, defaults to build.\n" +
"- `filters`: Job Filters can have the key branches or tags.+\n" +
"- `matrix` : requires config `2.1`. The `matrix` stanza allows you to run a parameterized job multiple times with different arguments.\n" +
"- `pre-steps` and `post-steps`: requires config `2.1`. Steps under `pre-steps` are executed before any of the other steps in the job. The steps under `post-steps` are executed after all of the other steps.\n"
"- `pre-steps` and `post-steps`: requires config `2.1`. Steps under `pre-steps` are executed before any of the other steps in the job. The steps under `post-steps` are executed after all of the other steps.\n" +
"- `plan_name`: requires release job type. Used to link your release to a release plan. https://circleci.com/docs/deploy/deploys-overview/\n"
}

func HoverInWorkflows(doc yamlparser.YamlDocument, path []string) string {
Expand Down
16 changes: 12 additions & 4 deletions publicschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,18 @@
"default": "org-global"
},
"type": {
"description": "A job may have a `type` of `approval` indicating it must be manually approved before downstream jobs may proceed.",
"description": "Job type, can be build, release, no-op, or approval. If not specified, defaults to build.\nhttps://circleci.com/docs/configuration-reference/#job-type",
"enum": [
"approval"
]
"approval",
"build",
"no-op",
"release"
],
"default": "build"
},
"plan_name": {
"description": "Used with release job type.\nhttps://circleci.com/docs/deploy/deploys-overview/",
"type": "string"
},
"filters": {
"description": "A map defining rules for execution on specific branches",
Expand Down Expand Up @@ -1346,4 +1354,4 @@
],
"title": "JSON schema for CircleCI configuration files",
"type": "object"
}
}