Skip to content

Commit 600b1aa

Browse files
authored
Unit tests + coverage reports, type checking, pre-commit, and requested fixes (#81)
* integrate mypy type checking into CI * resolve #75 * resolve #73 * run pylint workflow on changes to workflow file - fix a few long line warnings - add rich to the py dev reqs - add types-PyYAML to dev reqs * resolve #76 normalize submodule path separators per runner's OS * add unit tests for ignored paths also make sure the current working directory is appended to the .gitmodules path * run pytest in CI - add pytest to dev reqs - rename run-pylint.yml to run-dev-tests.yml - install cpp-linter pkg in run-dev-tests.yml workflow - upgrade actions/setup-python to v2 in run-dev-tests.yml workflow - rename step in run-dev-tests.yml workflow * resolve #74 and add unit tests for it This allows the `lines-changed-only` option to accept the following values: - false: All lines in a file are analyzed - true: All lines in the diff are analyzed (including unchanged lines) - strict: Only lines in the diff that contain additions are analyzed gitignore some test resources as they are fetched running the tests. Retain original repo structure when fetching files. This is only used when the user doesn't checkout the repo being analyzed. * improve and test CLI arg parsing * add unit test for database also fix a typo in demo.hpp variable name * switch to pre-commit; run pytest in a matrix * parametrize unit tests * fix changes to dev-test yaml * make database path absolute * use pathlib to resolve() relative paths in test * let db path be independent of repo-root w/o docker * this fails locally * show me value for RUNNER_WORKSPACE * use gh workspace if not in docker env * simplify the paths' concatenation * fix assignment of `Globals.FILES` * treat unsupport events like a push * explicitly set a env var when using docker * ammend some logic * show me some contents of folders on docker * hardcode the correct worspace dir * remove unused import * try detecting the docker env better * set the docker env var w/ a str * assume that RUNNER_WORKSPACE is abs * use only relativer path to db on docker * Revert "use only relativer path to db on docker" This reverts commit 37e3083. * better test coverage * mkdocstring doesn't support `Tuple[x, x]` type see mkdocstrings/griffe/#95 * fix workflow * revert changes to `get_line_cnt_from_cols()` * upload without codecov token?? * ensure LF used on demo src * update workflow * re-implement newer `get_line_cnt_from_cols()` * switch to pyproject.toml (setup.py is a dummy now) * resolve version exe path better * ammend make_annotations() (& its tests) * adjust for pypi releases * allow running locally & fix duplicate log cmds * use pathlib.Path to open files * rely on pathlib, update pkg name & CI workflows * `is_relative_to()` introduced in python v3.9 * `lstrip(".")` from file's extension * tidy v13 use abs path to std libs in output error * build/install wheel in test CI * oops, use correct artifact name * remove identifying info from test's event payload * make files list simpler for any event * ammend walking the repo files/folders This could probably get changed to using pathlib's glob mechanism. * replace os.walk() with pathlib's rglob() * only upload coverage report once from test CI * use OS dependent path separators for DB path * resolve #82 * ensure tidy fixit_lines end w/ a LF * workflow continue only if `latest` tag was added * include v7-9 for CI tests * fix docs about `parse_ignore_option()` Also, docs show type annotations in the function signatures * fix `TidyNotification.__repr__()` * tell CI to download clang-tools v7-9 * support older versions of clang-tidy YML output * don't try to traverse a `None` obj * add common hooks to pre-commit config * add more configs to toml This removes the need for a separate .coveragerc file pytest can be executed without args based on the config in the toml * update event triggers on dev-test CI workflow * sort requirements.txt contents * split pre-commit step into its own CI workflow update version of used (external) actions * pleasing pre-commit hooks * fix run-test.yml (trailing whitespaces) * revise README & remove .ci-ignore file * add code coverage badge to README
1 parent 8695d1f commit 600b1aa

38 files changed

+2906
-876
lines changed

.ci-ignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
*.py text eol=lf
77
*.rst text eol=lf
88
*.sh text eol=lf
9+
*.cpp text eol=lf
10+
*.hpp text eol=lf

.github/workflows/mkdocs-deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
12-
- uses: actions/setup-python@v2
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-python@v4
1313
with:
1414
python-version: 3.x
1515
- name: Install python action for doc extraction
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Pre-commit
2+
3+
on:
4+
push:
5+
pull_request:
6+
types: opened
7+
8+
jobs:
9+
check-source-files:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v4
14+
with:
15+
python-version: '3.x'
16+
- run: python3 -m pip install pre-commit
17+
- run: pre-commit run --all-files

.github/workflows/publish-pypi.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
branches: [master]
14+
types: [published]
15+
workflow_dispatch:
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
deploy:
22+
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v3
27+
# use fetch --all for setuptools_scm to work
28+
with:
29+
fetch-depth: 0
30+
- name: Set up Python
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: '3.x'
34+
- name: Install dependencies
35+
run: python -m pip install --upgrade pip twine
36+
- name: Build wheel
37+
run: python -m pip wheel -w dist --no-deps .
38+
- name: Check distribution
39+
run: twine check dist/*
40+
- name: Publish package (to TestPyPI)
41+
if: github.event_name == 'workflow_dispatch' && github.repository == 'cpp-linter/cpp-linter-action'
42+
env:
43+
TWINE_USERNAME: __token__
44+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
45+
run: twine upload --repository testpypi dist/*
46+
- name: Publish package (to PyPI)
47+
if: github.event_name != 'workflow_dispatch' && github.repository == 'cpp-linter/cpp-linter-action'
48+
env:
49+
TWINE_USERNAME: __token__
50+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
51+
run: twine upload dist/*

.github/workflows/run-dev-tests.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: "Check python code"
2+
3+
on:
4+
push:
5+
paths:
6+
- "**.py"
7+
- pyproject.toml
8+
- pre-commit-config.yaml
9+
- ".github/workflows/run-dev-tests.yml"
10+
pull_request:
11+
types: opened
12+
paths:
13+
- "**.py"
14+
- "**requirements*.txt"
15+
- pyproject.toml
16+
- pre-commit-config.yaml
17+
- ".github/workflows/run-dev-tests.yml"
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.x'
27+
- name: Build wheel
28+
run: python3 -m pip wheel --no-deps -w dist .
29+
- name: Upload wheel as artifact
30+
uses: actions/upload-artifact@v3
31+
with:
32+
name: cpp-linter-action_wheel
33+
path: ${{ github.workspace }}/dist/*.whl
34+
35+
test:
36+
needs: [build]
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
py: ['3.7', '3.8', '3.9', '3.10']
41+
os: ['windows-latest', ubuntu-latest]
42+
version: ['13', '12', '11', '10', '9', '8', '7']
43+
include:
44+
- tools_dir: 'N/A'
45+
- os: 'windows-latest'
46+
version: '10'
47+
tools_dir: temp
48+
- os: 'windows-latest'
49+
version: '10'
50+
tools_dir: temp
51+
- os: 'windows-latest'
52+
version: '11'
53+
tools_dir: temp
54+
- os: 'windows-latest'
55+
version: '12'
56+
tools_dir: temp
57+
- os: 'ubuntu-latest'
58+
version: '13'
59+
tools_dir: temp
60+
# - version: '14'
61+
# tools_dir: temp
62+
- version: '7'
63+
tools_dir: temp
64+
- version: '8'
65+
tools_dir: temp
66+
- version: '9'
67+
tools_dir: temp
68+
69+
runs-on: ${{ matrix.os }}
70+
steps:
71+
- uses: actions/checkout@v3
72+
73+
- uses: actions/setup-python@v4
74+
with:
75+
python-version: ${{ matrix.py }}
76+
77+
- name: download wheel artifact
78+
uses: actions/download-artifact@v3
79+
with:
80+
name: cpp-linter-action_wheel
81+
path: dist
82+
83+
- name: Install workflow deps
84+
# using a wildcard as filename on Windows requires a bash shell
85+
shell: bash
86+
run: python3 -m pip install pytest coverage[toml] dist/*.whl
87+
88+
- name: Install clang-tools
89+
if: matrix.tools_dir == 'temp'
90+
run: |
91+
python -m pip install clang-tools
92+
clang-tools --install ${{ matrix.version }} --directory ${{ runner.temp }}/clang-tools
93+
94+
- name: Collect Coverage (native clang install)
95+
if: matrix.tools_dir == 'N/A'
96+
env:
97+
CLANG_VERSION: ${{ matrix.version }}
98+
run: coverage run -m pytest
99+
100+
- name: Collect Coverage (non-native clang install)
101+
if: matrix.tools_dir == 'temp'
102+
env:
103+
CLANG_VERSION: ${{ runner.temp }}/clang-tools
104+
run: coverage run -m pytest
105+
106+
- run: coverage report && coverage xml
107+
108+
- uses: codecov/codecov-action@v3
109+
if: matrix.os == 'ubuntu-latest' && matrix.version == '12' && matrix.py == '3.10'
110+
with:
111+
files: ./coverage.xml
112+
fail_ci_if_error: true # optional (default = false)
113+
verbose: true # optional (default = false)

.github/workflows/run-pylint.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/run-test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ jobs:
2323
git push origin latest
2424
2525
test-action:
26+
needs: [add-tag]
2627
runs-on: ubuntu-latest
2728
steps:
2829
- uses: convictional/[email protected]
2930
with:
3031
owner: cpp-linter
31-
repo: test-cpp-linter-action
32+
repo: test-cpp-linter-action
3233
github_token: ${{ secrets.PAT_TOKEN }}
3334
workflow_file_name: cpp-lint-action.yml
3435
ref: master
@@ -38,12 +39,13 @@ jobs:
3839
trigger_workflow: true
3940
wait_workflow: true
4041
test-package:
42+
needs: [add-tag]
4143
runs-on: ubuntu-latest
4244
steps:
4345
- uses: convictional/[email protected]
4446
with:
4547
owner: cpp-linter
46-
repo: test-cpp-linter-action
48+
repo: test-cpp-linter-action
4749
github_token: ${{ secrets.PAT_TOKEN }}
4850
workflow_file_name: cpp-lint-package.yml
4951
ref: master

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ coverage.xml
5858
*.py,cover
5959
.hypothesis/
6060
.pytest_cache/
61+
tests/*/test*.json
62+
tests/**/*.c
6163

6264
# Translations
6365
*.mo

.gitpod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
tasks:
2-
- init: pip install -r requirements.txt
2+
- init: pip install -r requirements.txt

.pre-commit-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-docstring-first
8+
- id: check-added-large-files
9+
- id: check-yaml
10+
- id: check-toml
11+
- id: requirements-txt-fixer
12+
- repo: https://github.com/python/black
13+
rev: '22.6.0'
14+
hooks:
15+
- id: black
16+
args: ["--diff"]
17+
- repo: https://github.com/pycqa/pylint
18+
rev: v2.14.5
19+
hooks:
20+
- id: pylint
21+
name: pylint (action code)
22+
types: [python]
23+
exclude: "^(docs/|tests/|setup.py$)"
24+
additional_dependencies: [pyyaml, requests]
25+
- repo: local
26+
# this is a "local" hook to run mypy (see https://pre-commit.com/#repository-local-hooks)
27+
# because the mypy project doesn't seem to be compatible with pre-commit hooks
28+
hooks:
29+
- id: mypy
30+
name: mypy
31+
description: type checking with mypy tool
32+
language: python
33+
types: [python]
34+
entry: mypy
35+
exclude: "^(docs/|setup.py$)"
36+
additional_dependencies: [mypy, types-pyyaml, types-requests, rich, requests, pytest, pyyaml, '.']

0 commit comments

Comments
 (0)