Skip to content

Commit ad00f58

Browse files
committed
Implement the 'pre-commit' YAML checking tool, and add
it to a new pre-commit Github Actions workflow. Also replace the direct calls to the python framework unit tests with a new 'pytest' implementation, which should keep the Github Actions workflow simple even with future additions of new python unit tests.
1 parent acb48a9 commit ad00f58

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

.github/workflows/ADF_pre-commit.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
push:
7+
# Run the tests one more time, after the PR changes
8+
# have been pushed. The if-statement below prevents
9+
# the push from running on other repos.
10+
branches:
11+
#Trigger workflow on push to any branch or branch heirarchy:
12+
- '**'
13+
14+
jobs:
15+
#This job is designed to run the "pre-commit"
16+
#set of static analysis, linters, and formatters
17+
#for Python and YAML.
18+
pre-commit:
19+
if: github.event_name == 'pull_request' || github.repository == 'NCAR/ADF'
20+
runs-on: ubuntu-latest
21+
steps:
22+
# acquire github action routines
23+
- uses: actions/checkout@v3
24+
# acquire specific version of python
25+
- name: Set up Python 3.10
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.10' # Use python 3.10
29+
# install pre-commit package
30+
- name: Install pre-commit
31+
run: |
32+
python -m pip install --upgrade pip # Install latest version of PIP
33+
pip install pre-commit
34+
# run pre-commit on ADF code
35+
- name: Run pre-commit
36+
run: pre-commit run -a
37+

.github/workflows/ADF_unit_tests.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,19 @@ jobs:
2525
fail-fast: false
2626
steps:
2727
# Acquire github action routines:
28-
- uses: actions/checkout@v2
28+
- uses: actions/checkout@v3
2929
# Acquire specific version of python:
3030
- name: Set up Python ${{ matrix.python-version }}
31-
uses: actions/setup-python@v1
31+
uses: actions/setup-python@v4
3232
with:
3333
python-version: ${{ matrix.python-version }}
3434
# Install needed python packages:
3535
- name: Install dependencies
3636
run: |
3737
python -m pip install --upgrade pip # Install latest version of PIP
3838
pip install pyyaml # Install PyYAML python package
39+
pip install pytest # Install pytest python package
3940
# Run python unit tests related to ADF library:
4041
- name: ADF lib unit tests
41-
run: |
42-
#AdfBase unit tests:
43-
python lib/test/unit_tests/test_adf_base.py
44-
#AdfConfig unit tests:
45-
python lib/test/unit_tests/test_adf_config.py
42+
run: pytest lib/test/unit_tests
4643

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Configuration file for the "pre-commit" linting/formatting tool.
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.3.0
6+
hooks:
7+
- id: check-yaml
8+
9+
#End of file.

lib/test/unit_tests/pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts=-p no:logging

0 commit comments

Comments
 (0)