Skip to content

Commit 2feef16

Browse files
authored
Merge pull request #356 from python-jsonschema/expression-in-gha-timeout
Support expressions in GHA require-timeout schema
2 parents d655126 + 2d71566 commit 2feef16

File tree

6 files changed

+57
-4
lines changed

6 files changed

+57
-4
lines changed

src/check_jsonschema/builtin_schemas/custom/github-workflows-require-timeout.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"$comment": "A schema which requires that github workflow jobs define job timeouts",
4+
"definitions": {
5+
"expressionSyntax": {
6+
"type": "string",
7+
"$comment": "pattern definition taken from schemastore 'github-workflow.json'",
8+
"pattern": "^\\$\\{\\{(.|[\r\n])*\\}\\}$"
9+
}
10+
},
411
"properties": {
512
"jobs": {
613
"$comment": "https://help.github.com/en/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobs",
@@ -15,8 +22,15 @@
1522
"timeout-minutes": {
1623
"$comment": "https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idtimeout-minutes",
1724
"description": "The maximum number of minutes to let a workflow run before GitHub automatically cancels it. Default: 360",
18-
"type": "number",
19-
"default": 360
25+
"default": 360,
26+
"oneOf": [
27+
{
28+
"type": "number"
29+
},
30+
{
31+
"$ref": "#/definitions/expressionSyntax"
32+
}
33+
]
2034
}
2135
},
2236
"required": [

tests/acceptance/test_example_files.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_hook_positive_examples(case_name, run_line):
6464

6565
hook_id = POSITIVE_HOOK_CASES[case_name]
6666
ret = run_line(HOOK_CONFIG[hook_id] + [rcase.path] + rcase.add_args)
67-
assert ret.exit_code == 0
67+
assert ret.exit_code == 0, _format_cli_result(rcase, ret)
6868

6969

7070
@pytest.mark.parametrize("case_name", NEGATIVE_HOOK_CASES.keys())
@@ -73,7 +73,7 @@ def test_hook_negative_examples(case_name, run_line):
7373

7474
hook_id = NEGATIVE_HOOK_CASES[case_name]
7575
ret = run_line(HOOK_CONFIG[hook_id] + [rcase.path] + rcase.add_args)
76-
assert ret.exit_code == 1
76+
assert ret.exit_code == 1, _format_cli_result(rcase, ret)
7777

7878

7979
@pytest.mark.parametrize("case_name", _get_explicit_cases("positive"))
@@ -167,3 +167,13 @@ def _package_is_installed(pkg: str) -> bool:
167167
if spec is None:
168168
return False
169169
return True
170+
171+
172+
def _format_cli_result(rcase: ResolvedCase, result) -> str:
173+
return (
174+
"\n"
175+
f"config.add_args={rcase.add_args}\n"
176+
f"{result.exit_code=}\n"
177+
f"result.stdout={result.output}\n"
178+
f"{result.stderr=}"
179+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
files:
2+
github-workflow-timeout-minutes-expression.yaml:
3+
add_args: ["--builtin-schema", "custom.github-workflows-require-timeout"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
on:
2+
workflow-call:
3+
inputs:
4+
qemu:
5+
default: ''
6+
required: false
7+
8+
jobs:
9+
job-id:
10+
runs-on: ubuntu-latest
11+
# missing trailing '}'
12+
timeout-minutes: ${{ inputs.qemu && '60' || '20' }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
files:
2+
github-workflow-timeout-minutes-expression.yaml:
3+
add_args: ["--builtin-schema", "custom.github-workflows-require-timeout"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
on:
2+
workflow-call:
3+
inputs:
4+
qemu:
5+
default: ''
6+
required: false
7+
8+
jobs:
9+
job-id:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: ${{ inputs.qemu && '60' || '20' }}

0 commit comments

Comments
 (0)