11name : Check analyzers
2+ description : >
3+ This workflow checks the code quality of a Python package using various
4+ analyzers like linters and type checkers, including ni-python-styleguide,
5+ mypy, bandit, and pyright. It is designed to be reusable across different
6+ projects and can be easily integrated into existing CI/CD pipelines.
27
38on :
49 workflow_call :
510 inputs :
6- package-name :
7- description : ' The name of the package to check.'
11+ project-directory :
12+ description : Path to the directory containing pyproject.toml.
13+ default : ${{ github.workspace }}
14+ install-extras :
15+ description : ' List of Poetry extras to install (comma separated)'
816 default : ' '
9- required : true
10- type : string
11- package-base-path :
12- description : ' The parent directory of the package to check. Defaults to packages.'
13- default : ' packages'
1417 required : false
1518 type : string
16- install-drivers :
17- description : ' Whether to install drivers extras'
18- default : false
19- required : false
20- type : boolean
2119
2220jobs :
2321 check_analyzers :
@@ -26,50 +24,58 @@ jobs:
2624 defaults :
2725 run :
2826 # Set the working-directory for all steps in this job.
29- working-directory : ${{ inputs.package-base-path != '' && format('./{0}/{1}', inputs.package-base-path, inputs.package-name) || format('.', '') }}
27+ working-directory : ${{ inputs.project-directory }}
3028 steps :
29+ - name : Get package name and version
30+ id : get_package_info
31+ run : |
32+ result=$(poetry version -C "${{ inputs.project-directory }}")
33+ name=$(echo "$result" | awk '{print $1}')
34+ version=$(echo "$result" | awk '{print $2}')
35+ echo "name=$name" >> $GITHUB_OUTPUT
36+ echo "version=$version" >> $GITHUB_OUTPUT
3137 - name : Check out repo
3238 uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3339 with :
3440 submodules : true
3541 - name : Set up Python
36- uses : ni/python-actions/ setup-python@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0
42+ uses : ./ setup-python
3743 id : setup-python
3844 - name : Set up Poetry
39- uses : ni/python-actions/ setup-poetry@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0
45+ uses : ./ setup-poetry
4046 - name : Check for lock changes
4147 run : poetry check --lock
4248 - name : Cache virtualenv
4349 uses : actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
4450 with :
45- path : ${{ inputs.package-base-path }}/${{ inputs.package-name }}/.venv
46- key : ${{ inputs.package-name }}-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles(format('{0}/{1}/ poetry.lock', inputs.package-base-path, inputs.package-name )) }}
47- - name : Install ${{ inputs.package- name }}
51+ path : ${{ inputs.project-directory }}/.venv
52+ key : ${{ inputs.package-name }}-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles(format('{0}/poetry.lock', inputs.project-directory )) }}
53+ - name : Install ${{ steps.get_package_info.outputs. name }}
4854 run : |
49- if [ "${{ inputs.install-drivers }}" = "true " ]; then
50- poetry install -v --extras drivers
55+ if [ "${{ inputs.install-extras }}" ! = "" ]; then
56+ poetry install -v --extras "${{ inputs.install-extras }}"
5157 else
5258 poetry install -v
5359 fi
5460 - name : Lint
5561 run : poetry run ni-python-styleguide lint
5662 - name : Mypy static analysis (Linux)
57- run : poetry run mypy
63+ run : poetry run mypy
5864 - name : Mypy static analysis (Windows)
59- run : poetry run mypy --platform win32
65+ run : poetry run mypy --platform win32
6066 - name : Bandit security checks
61- run : poetry run bandit -c pyproject.toml -r src/
67+ run : poetry run bandit -c pyproject.toml -r src/
6268 - name : Add virtualenv to the path for pyright-action
6369 run : echo "$(poetry env info --path)/bin" >> $GITHUB_PATH
6470 - name : Pyright static analysis (Linux)
6571 uses : jakebailey/pyright-action@b5d50e5cde6547546a5c4ac92e416a8c2c1a1dfe # v2.3.2
6672 with :
6773 python-platform : Linux
6874 version : PATH
69- working-directory : ${{ inputs.package-base-path != '' && format('./{0}/{1}', inputs.package-base-path, inputs.package-name) || format('.', '') }}
75+ working-directory : ${{ inputs.project-directory }}
7076 - name : Pyright static analysis (Windows)
7177 uses : jakebailey/pyright-action@b5d50e5cde6547546a5c4ac92e416a8c2c1a1dfe # v2.3.2
7278 with :
7379 python-platform : Windows
7480 version : PATH
75- working-directory : ${{ inputs.package-base-path != '' && format('./{0}/{1}', inputs.package-base-path, inputs.package-name) || format('.', '') }}
81+ working-directory : ${{ inputs.project-directory }}
0 commit comments