Skip to content

Commit 9c136cd

Browse files
authored
Merge pull request #425 from lincc-frameworks/issue/382/pre-commit-workflow-validation
Add validation of Github workflows to pre-commit
2 parents 6f69d3d + cb49ce4 commit 9c136cd

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

python-project-template/.pre-commit-config.yaml.jinja

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ repos:
3737
- id: validate-pyproject
3838
name: Validate pyproject.toml
3939
description: Verify that pyproject.toml adheres to the established schema.
40+
# Verify that GitHub workflows are well formed
41+
- repo: https://github.com/python-jsonschema/check-jsonschema
42+
rev: 0.28.0
43+
hooks:
44+
- id: check-github-workflows
45+
args: ["--verbose"]
4046
{%- if 'isort' in enforce_style %}
4147
# Automatically sort the imports used in .py files
4248
- repo: https://github.com/pycqa/isort

tests/test_package_creation.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import pytest_copie
32
import subprocess
43

54

@@ -19,7 +18,8 @@ def black_runs_successfully(result):
1918
"""Test to ensure that the black linter runs successfully on the project"""
2019
# run black with `--check` to look for lint errors, but don't fix them.
2120
black_results = subprocess.run(
22-
["python", "-m", "black", "--check", (result.project_dir / "src")], cwd=result.project_dir
21+
["python", "-m", "black", "--check", (result.project_dir / "src")],
22+
cwd=result.project_dir,
2323
)
2424

2525
return black_results.returncode == 0
@@ -29,7 +29,14 @@ def pylint_runs_successfully(result):
2929
"""Test to ensure that the pylint linter runs successfully on the project"""
3030
# run pylint to ensure that the hydrated files are linted correctly
3131
pylint_results = subprocess.run(
32-
["python", "-m", "pylint", "--recursive=y", "--rcfile=./src/.pylintrc", (result.project_dir / "src")],
32+
[
33+
"python",
34+
"-m",
35+
"pylint",
36+
"--recursive=y",
37+
"--rcfile=./src/.pylintrc",
38+
(result.project_dir / "src"),
39+
],
3340
cwd=result.project_dir,
3441
)
3542

@@ -48,6 +55,19 @@ def unit_tests_in_project_run_successfully(result, package_name="example_package
4855
return pytest_results.returncode == 0
4956

5057

58+
def github_workflows_are_valid(result):
59+
"""Test to ensure that the GitHub workflows are valid"""
60+
workflows_results = subprocess.run(
61+
["pre-commit", "run", "check-github-workflows"], cwd=result.project_dir
62+
)
63+
return workflows_results.returncode == 0
64+
65+
66+
def initialize_git_project(result):
67+
"""Initializes local git repository (required to run pre-commit)"""
68+
subprocess.call(["git", "init", "."], cwd=result.project_dir)
69+
70+
5171
def test_all_defaults(copie):
5272
"""Test that the default values are used when no arguments are given.
5373
Ensure that the project is created and that the basic files exist.
@@ -155,3 +175,14 @@ def test_smoke_test_notification(copie):
155175
assert successfully_created_project(result)
156176
assert directory_structure_is_correct(result)
157177
assert black_runs_successfully(result)
178+
179+
180+
def test_github_workflows_schema(copie):
181+
"""Confirm the current GitHub workflows have valid schemas."""
182+
extra_answers = {
183+
"include_benchmarks": True,
184+
"include_docs": True,
185+
}
186+
result = copie.copy(extra_answers=extra_answers)
187+
initialize_git_project(result)
188+
assert github_workflows_are_valid(result)

0 commit comments

Comments
 (0)