fix(parser): allow empty trigger glob arrays

This commit is contained in:
sonwr
2026-03-08 02:40:59 +00:00
parent 81d8d7ab6d
commit b90f07f945
2 changed files with 57 additions and 10 deletions

View File

@@ -318,7 +318,7 @@
"type": "string", "type": "string",
"minLength": 1 "minLength": 1
}, },
"minItems": 1 "minItems": 0
}, },
"machine": { "machine": {
"type": "string", "type": "string",
@@ -1591,20 +1591,28 @@
"workflow_dispatch": { "workflow_dispatch": {
"$comment": "https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/", "$comment": "https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/",
"description": "You can now create workflows that are manually triggered with the new workflow_dispatch event. You will then see a 'Run workflow' button on the Actions tab, enabling you to easily trigger a run.", "description": "You can now create workflows that are manually triggered with the new workflow_dispatch event. You will then see a 'Run workflow' button on the Actions tab, enabling you to easily trigger a run.",
"properties": { "oneOf": [
"inputs": { {
"$comment": "https://help.github.com/en/github/automating-your-workflow-with-github-actions/metadata-syntax-for-github-actions#inputs", "type": "null"
"description": "Input parameters allow you to specify data that the action expects to use during runtime. GitHub stores input parameters as environment variables. Input ids with uppercase letters are converted to lowercase during runtime. We recommended using lowercase input ids.", },
{
"type": "object", "type": "object",
"patternProperties": { "properties": {
"^[_a-zA-Z][a-zA-Z0-9_-]*$": { "inputs": {
"$ref": "#/definitions/workflowDispatchInput" "$comment": "https://help.github.com/en/github/automating-your-workflow-with-github-actions/metadata-syntax-for-github-actions#inputs",
"description": "Input parameters allow you to specify data that the action expects to use during runtime. GitHub stores input parameters as environment variables. Input ids with uppercase letters are converted to lowercase during runtime. We recommended using lowercase input ids.",
"type": "object",
"patternProperties": {
"^[_a-zA-Z][a-zA-Z0-9_-]*$": {
"$ref": "#/definitions/workflowDispatchInput"
}
},
"additionalProperties": false
} }
}, },
"additionalProperties": false "additionalProperties": false
} }
}, ]
"additionalProperties": false
}, },
"workflow_run": { "workflow_run": {
"$comment": "https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_run", "$comment": "https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_run",

View File

@@ -190,3 +190,42 @@ fn normalize_triggers(on_value: &serde_yaml::Value) -> Result<Vec<String>, Strin
Ok(triggers) Ok(triggers)
} }
#[cfg(test)]
mod tests {
use super::parse_workflow;
use std::fs;
use tempfile::tempdir;
#[test]
fn parse_workflow_allows_null_workflow_dispatch_with_other_triggers() {
let temp_dir = tempdir().unwrap();
let workflow_path = temp_dir.path().join("workflow.yml");
let content = r#"
name: trigger-test
on:
push:
branches: []
tags-ignore: []
release:
types: [prereleased, published]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo hi
"#;
fs::write(&workflow_path, content).unwrap();
let parsed = parse_workflow(&workflow_path);
assert!(
parsed.is_ok(),
"Expected workflow to parse successfully, got: {:?}",
parsed.err()
);
}
}