Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9b0997b
Add check_analyzers as a trial balloon
dixonjoel Sep 11, 2025
156d9b4
Fix project-directory inputs, change name of .yml file. Update instal…
dixonjoel Sep 12, 2025
2c82d44
Rename to analyze-project.yml and 'extras'
dixonjoel Sep 16, 2025
0469952
Remove bandit checks. Will be covered by ni-python-styleguide soon
dixonjoel Sep 16, 2025
5b8eb04
Switch to a composite action
dixonjoel Sep 18, 2025
4063db7
Add test for analyze-project
dixonjoel Sep 18, 2025
7e94081
Create project to analyze
dixonjoel Sep 18, 2025
02918c9
Add shell specification for actions
dixonjoel Sep 18, 2025
dffb6d2
Attempt to fix the project directory for analyze test
dixonjoel Sep 18, 2025
0818b7e
Attempt to fix the project directory for analyze test
dixonjoel Sep 18, 2025
02b50cc
Produce poetry.lock before analyzing
dixonjoel Sep 18, 2025
7746abc
Add dependency on ni-python-styleguide
dixonjoel Sep 18, 2025
0b967dc
Use a compatible Python version
dixonjoel Sep 18, 2025
6afd6b7
Use matrix Python version
dixonjoel Sep 18, 2025
f5abcf7
Another attempt at the correct python version
dixonjoel Sep 18, 2025
47f2905
Tenth time is the charm
dixonjoel Sep 18, 2025
f9ab523
Eleventh time is the charm
dixonjoel Sep 18, 2025
82c74e6
Twelfth time is the charm
dixonjoel Sep 18, 2025
5311b24
Thirteenth time is the charm
dixonjoel Sep 18, 2025
078cfb7
Try try again
dixonjoel Sep 18, 2025
bf0613b
Try try again
dixonjoel Sep 18, 2025
bec5db6
Add docstrings to .py files
dixonjoel Sep 18, 2025
6cee457
Try try again
dixonjoel Sep 18, 2025
afe9eec
Whee! Let's try Python
dixonjoel Sep 18, 2025
46f076e
Add mypy dependency
dixonjoel Sep 18, 2025
f2711b7
Further restrict the Python version for mypy to work
dixonjoel Sep 18, 2025
84271e0
Show pyproject.toml after the addition of deps
dixonjoel Sep 18, 2025
b0f22e5
Attempt to use a template project for testing
dixonjoel Sep 18, 2025
7ce8147
Add mypy section
dixonjoel Sep 18, 2025
e3a29bb
Add pyright dependencies
dixonjoel Sep 18, 2025
6c724cf
Update poetry .lock
dixonjoel Sep 18, 2025
4b06b0e
Try different working directory
dixonjoel Sep 18, 2025
fffe019
Try original working directory
dixonjoel Sep 18, 2025
5671259
Attempt to make it work on Windows
dixonjoel Sep 18, 2025
b23c4a2
Test more Python versions
dixonjoel Sep 18, 2025
d2db7bd
Make mypy and pyright optional.
dixonjoel Sep 18, 2025
c379517
fix yml syntax
dixonjoel Sep 18, 2025
101fbf5
Indent python code
dixonjoel Sep 18, 2025
901871a
Check the outputs
dixonjoel Sep 18, 2025
c1db319
Check packages after install
dixonjoel Sep 18, 2025
938f8ba
Use GITHUB_OUTPUT
dixonjoel Sep 18, 2025
9ef16d9
Move minimal test project under .github to hide it
dixonjoel Sep 22, 2025
4faa1d0
Simplify Add virtualenv to the path for pyright-action
dixonjoel Sep 22, 2025
21cdaf6
Merge remote-tracking branch 'origin/main' into users/jdixon/add-comm…
dixonjoel Sep 22, 2025
0020788
Various PR feedback
dixonjoel Sep 22, 2025
07d9779
Merge remote-tracking branch 'origin/main' into users/jdixon/add-comm…
dixonjoel Sep 22, 2025
2648d0c
Use poetry env info --path to get the venv path
dixonjoel Sep 22, 2025
4579668
Add -C parameter to poetry env --info command
dixonjoel Sep 22, 2025
4a8b3fa
Attempt to use {{ github.workspace }} instead of ./
dixonjoel Sep 22, 2025
228461b
Attempt to use working-directory instead of -C <path>
dixonjoel Sep 22, 2025
d840da7
Remove stray quote
dixonjoel Sep 22, 2025
8e5f35a
Merge remote-tracking branch 'origin/main' into users/jdixon/add-comm…
dixonjoel Sep 22, 2025
c35bbb4
Try quoting
dixonjoel Sep 22, 2025
94c19d6
Remove some bash code to narrow down error
dixonjoel Sep 22, 2025
6d628bc
Add back in path
dixonjoel Sep 22, 2025
867661a
Try another arrangement
dixonjoel Sep 22, 2025
d90f284
Try without echoing the path
dixonjoel Sep 22, 2025
34ee66b
Try some quotes, why not?
dixonjoel Sep 22, 2025
8672646
Try without --path, why not
dixonjoel Sep 23, 2025
a5a414d
Try without Python 3.9
dixonjoel Sep 23, 2025
10bad85
Echo the poetry env info
dixonjoel Sep 23, 2025
bcc1c1a
Add back in path
dixonjoel Sep 23, 2025
9d3f040
Try a different arrangement of quotes
dixonjoel Sep 23, 2025
0899ce9
Change variable name
dixonjoel Sep 23, 2025
3d89b41
Change variable name
dixonjoel Sep 23, 2025
359640c
print some debug info
mshafer-NI Sep 23, 2025
3fa2cfb
don't stop on help
mshafer-NI Sep 23, 2025
17a40c3
don't fail fast
mshafer-NI Sep 23, 2025
a3778a6
ok, let's print it out without exiting first
mshafer-NI Sep 23, 2025
640e806
ok, use or
mshafer-NI Sep 23, 2025
3acc52c
ok, try this...
mshafer-NI Sep 23, 2025
96c1e97
analyze-project: Fix venv caching (#28)
bkeryan Sep 24, 2025
082363c
Restore all the matrix of python versions and OSs
dixonjoel Sep 24, 2025
1831603
Merge branch 'users/jdixon/add-common-workflows' of https://github.co…
dixonjoel Sep 24, 2025
4dd9375
Fix copy and paste error in test_actions.yml
dixonjoel Sep 24, 2025
2187533
Minor PR feedback
dixonjoel Sep 24, 2025
dd965b2
Remove 3.13t Python from some spots
dixonjoel Sep 24, 2025
87ed507
Use v0 for actions in README
dixonjoel Sep 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
597 changes: 597 additions & 0 deletions .github/test_projects/minimal/poetry.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions .github/test_projects/minimal/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[project]
name = "test-project"
version = "0.1.0"
description = ""
authors = [
{name = "Joel Dixon",email = "joel.dixon@ni.com"}
]
readme = "README.md"
requires-python = ">=3.9,<4.0"
dynamic = ["dependencies"]

[tool.poetry]
packages = [{include = "test_project", from = "src"}]

[tool.poetry.group.lint.dependencies]
ni-python-styleguide = ">=0.4.1"
mypy = ">=1.0"
pyright = { version = ">=1.1.400", extras = ["nodejs"] }

[tool.mypy]
mypy_path = "."
files = "."
namespace_packages = true
strict = true
explicit_package_bases = true

[tool.pyright]
include = ["src/", "tests/"]

[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Docstring required."""
1 change: 1 addition & 0 deletions .github/test_projects/minimal/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module docstring."""
24 changes: 23 additions & 1 deletion .github/workflows/test_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ jobs:
project-directory: test-project
expected-version: 1.0.2.dev1

test_analyze_project:
name: Test analyze-project
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: [3.9, '3.10', 3.11, 3.12, 3.13, pypy3.10, pypy3.11]
steps:
- name: Check out repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Set up Python
uses: ./setup-python
with:
python-version: ${{ matrix.python-version }}
- name: Set up Poetry
uses: ./setup-poetry
- name: Analyze Python Project
uses: ./analyze-project
with:
project-directory: ${{ github.workspace }}/.github/test_projects/minimal

# This job is intended to combine the test results so we don't have to list
# each matrix combination in the required status check settings. There are a
# lot of corner cases that make this harder than it should be; see See
Expand All @@ -225,7 +246,8 @@ jobs:
test_setup_poetry_cache_hit,
test_setup_poetry_no_cache,
test_check_project_version,
test_update_project_version
test_update_project_version,
test_analyze_project,
]
if: ${{ !cancelled() }}
steps:
Expand Down
43 changes: 43 additions & 0 deletions analyze-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# `ni/python-actions/analyze-project`

The `ni/python-actions/update-project-version` action analyzes the code quality
of a Python project using various linters and type checkers including
ni-python-styleguide, mypy (if the 'mypy' package is installed), and pyright
(if the 'pyright' package is installed).

This action requires Poetry, so you must call `ni/python-actions/setup-python` and
`ni/python-actions/setup-poetry` first.

## Usage

```yaml
steps:
- uses: ni/python-actions/setup-python@v0
- uses: ni/python-actions/setup-poetry@v0
- uses: ni/python-actions/analyze-project@v0
```

## Inputs

### `project-directory`

You can specify `project-directory` to indicate the location of the pyproject.toml
file associated with the Python project you are analyzing.

```yaml
- uses: ni/python-actions/update-project-version@v0
with:
project-directory: ${{ github.workspace }}/packages/myproject
```

### `extras`

If there are extras you need to install from your pyproject.toml, specify a space-separated list
of extra groups to install. For example,

```yaml
- uses: ni/python-actions/analyze-project@v0
with:
project-directory: ${{ github.workspace }}/packages/myproject
extras: 'docs drivers'
```
97 changes: 97 additions & 0 deletions analyze-project/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Analyze project
description: >
This workflow analyzes the code quality of a Python project using various
linters and type checkers including ni-python-styleguide,
mypy (if the 'mypy' package is installed), and pyright (if the 'pyright'
package is installed).

inputs:
project-directory:
description: Path to the directory containing pyproject.toml.
default: ${{ github.workspace }}
extras:
# E.g. "docs drivers"
description: 'List of Poetry extras to install (separated by spaces)'
default: ''
required: false
type: string

runs:
using: composite
steps:
- name: Get project info
id: get_project_info
run: |
result=$(poetry version)
name=$(echo "$result" | awk '{print $1}')
version=$(echo "$result" | awk '{print $2}')
echo "Name: $name"
echo "Version: $version"
echo "name=$name" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
poetry env activate
venv_path="$(poetry env info --path)"
echo "venv path: $venv_path"
echo "venv-path=$venv_path" >> "$GITHUB_OUTPUT"
shell: bash
working-directory: ${{ inputs.project-directory }}
- name: Check for lock changes
run: poetry check --lock -C "${{ inputs.project-directory }}"
shell: bash
- name: Cache virtualenv
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: ${{ steps.get_project_info.outputs.venv-path }}
key: ${{ steps.get_project_info.outputs.name }}-${{ runner.os }}-py${{ env.pythonVersion }}-${{ hashFiles(format('{0}/poetry.lock', inputs.project-directory)) }}
- name: Install ${{ steps.get_project_info.outputs.name }}
run: |
if [ -n "${{ inputs.extras }}" ]; then
poetry install -v --extras '${{ inputs.extras }}'
else
poetry install -v
fi
working-directory: ${{ inputs.project-directory }}
shell: bash
- name: Lint
run: poetry run ni-python-styleguide lint
working-directory: ${{ inputs.project-directory }}
shell: bash
- name: Check for mypy and pyright installation
id: check_tools
run: |
import os
from importlib.metadata import version, PackageNotFoundError

def is_installed(pkg_name):
try:
version(pkg_name)
return "true"
except PackageNotFoundError:
return "false"

with open(os.environ["GITHUB_OUTPUT"], "a") as output:
print(f"mypy={is_installed('mypy')}", file=output)
print(f"pyright={is_installed('pyright')}", file=output)
shell: python
- name: Echo check_tools outputs
run: |
echo "mypy installed: ${{ steps.check_tools.outputs.mypy }}"
echo "pyright installed: ${{ steps.check_tools.outputs.pyright }}"
shell: bash
- name: Mypy static analysis
if: steps.check_tools.outputs.mypy == 'true'
run: poetry run mypy
working-directory: ${{ inputs.project-directory }}
shell: bash
- name: Add virtualenv to the path for pyright-action
if: steps.check_tools.outputs.pyright == 'true'
shell: bash
run: |
echo "$(dirname $(poetry env info --executable))" >> $GITHUB_PATH
working-directory: ${{ inputs.project-directory }}
- name: Pyright static analysis
if: steps.check_tools.outputs.pyright == 'true'
uses: jakebailey/pyright-action@b5d50e5cde6547546a5c4ac92e416a8c2c1a1dfe # v2.3.2
with:
version: PATH
working-directory: ${{ inputs.project-directory }}
Loading