Skip to content

Commit 5b8eb04

Browse files
committed
Switch to a composite action
1 parent 0469952 commit 5b8eb04

File tree

2 files changed

+65
-84
lines changed

2 files changed

+65
-84
lines changed

analyze-project/action.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Analyze Python Project
2+
description: >
3+
This workflow checks the code quality of a Python project 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.
7+
8+
inputs:
9+
project-directory:
10+
description: Path to the directory containing pyproject.toml.
11+
default: ${{ github.workspace }}
12+
extras:
13+
# E.g. "docs drivers"
14+
description: 'List of Poetry extras to install (separated by spaces)'
15+
default: ''
16+
required: false
17+
type: string
18+
19+
runs:
20+
using: composite
21+
steps:
22+
- name: Get package name and version
23+
id: get_package_info
24+
run: |
25+
result=$(poetry version -C "${{ inputs.project-directory }}")
26+
name=$(echo "$result" | awk '{print $1}')
27+
version=$(echo "$result" | awk '{print $2}')
28+
echo "name=$name" >> $GITHUB_OUTPUT
29+
echo "version=$version" >> $GITHUB_OUTPUT
30+
working-directory: ${{ inputs.project-directory }}
31+
- name: Check for lock changes
32+
run: poetry check --lock
33+
working-directory: ${{ inputs.project-directory }}
34+
- name: Cache virtualenv
35+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
36+
with:
37+
path: ${{ inputs.project-directory }}/.venv
38+
key: ${{ inputs.package-name }}-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles(format('{0}/poetry.lock', inputs.project-directory)) }}
39+
working-directory: ${{ inputs.project-directory }}
40+
- name: Install ${{ steps.get_package_info.outputs.name }}
41+
run: |
42+
if [ "${{ inputs.install-extras }}" != "" ]; then
43+
EXTRAS_ARGS=""
44+
for extra in ${{ inputs.extras }}; do
45+
EXTRAS_ARGS="$EXTRAS_ARGS -E $extra"
46+
done
47+
poetry install -v $EXTRAS_ARGS
48+
else
49+
poetry install -v
50+
fi
51+
working-directory: ${{ inputs.project-directory }}
52+
- name: Lint
53+
run: poetry run ni-python-styleguide lint
54+
working-directory: ${{ inputs.project-directory }}
55+
- name: Mypy static analysis
56+
run: poetry run mypy
57+
working-directory: ${{ inputs.project-directory }}
58+
- name: Add virtualenv to the path for pyright-action
59+
run: echo "$(poetry env info --path)/bin" >> $GITHUB_PATH
60+
working-directory: ${{ inputs.project-directory }}
61+
- name: Pyright static analysis
62+
uses: jakebailey/pyright-action@b5d50e5cde6547546a5c4ac92e416a8c2c1a1dfe # v2.3.2
63+
with:
64+
version: PATH
65+
working-directory: ${{ inputs.project-directory }}

workflows/analyze-project.yml

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

0 commit comments

Comments
 (0)