generated from ni/github-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Add analyze-project composite action to validate a Python project #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 156d9b4
Fix project-directory inputs, change name of .yml file. Update instal…
dixonjoel 2c82d44
Rename to analyze-project.yml and 'extras'
dixonjoel 0469952
Remove bandit checks. Will be covered by ni-python-styleguide soon
dixonjoel 5b8eb04
Switch to a composite action
dixonjoel 4063db7
Add test for analyze-project
dixonjoel 7e94081
Create project to analyze
dixonjoel 02918c9
Add shell specification for actions
dixonjoel dffb6d2
Attempt to fix the project directory for analyze test
dixonjoel 0818b7e
Attempt to fix the project directory for analyze test
dixonjoel 02b50cc
Produce poetry.lock before analyzing
dixonjoel 7746abc
Add dependency on ni-python-styleguide
dixonjoel 0b967dc
Use a compatible Python version
dixonjoel 6afd6b7
Use matrix Python version
dixonjoel f5abcf7
Another attempt at the correct python version
dixonjoel 47f2905
Tenth time is the charm
dixonjoel f9ab523
Eleventh time is the charm
dixonjoel 82c74e6
Twelfth time is the charm
dixonjoel 5311b24
Thirteenth time is the charm
dixonjoel 078cfb7
Try try again
dixonjoel bf0613b
Try try again
dixonjoel bec5db6
Add docstrings to .py files
dixonjoel 6cee457
Try try again
dixonjoel afe9eec
Whee! Let's try Python
dixonjoel 46f076e
Add mypy dependency
dixonjoel f2711b7
Further restrict the Python version for mypy to work
dixonjoel 84271e0
Show pyproject.toml after the addition of deps
dixonjoel b0f22e5
Attempt to use a template project for testing
dixonjoel 7ce8147
Add mypy section
dixonjoel e3a29bb
Add pyright dependencies
dixonjoel 6c724cf
Update poetry .lock
dixonjoel 4b06b0e
Try different working directory
dixonjoel fffe019
Try original working directory
dixonjoel 5671259
Attempt to make it work on Windows
dixonjoel b23c4a2
Test more Python versions
dixonjoel d2db7bd
Make mypy and pyright optional.
dixonjoel c379517
fix yml syntax
dixonjoel 101fbf5
Indent python code
dixonjoel 901871a
Check the outputs
dixonjoel c1db319
Check packages after install
dixonjoel 938f8ba
Use GITHUB_OUTPUT
dixonjoel 9ef16d9
Move minimal test project under .github to hide it
dixonjoel 4faa1d0
Simplify Add virtualenv to the path for pyright-action
dixonjoel 21cdaf6
Merge remote-tracking branch 'origin/main' into users/jdixon/add-comm…
dixonjoel 0020788
Various PR feedback
dixonjoel 07d9779
Merge remote-tracking branch 'origin/main' into users/jdixon/add-comm…
dixonjoel 2648d0c
Use poetry env info --path to get the venv path
dixonjoel 4579668
Add -C parameter to poetry env --info command
dixonjoel 4a8b3fa
Attempt to use {{ github.workspace }} instead of ./
dixonjoel 228461b
Attempt to use working-directory instead of -C <path>
dixonjoel d840da7
Remove stray quote
dixonjoel 8e5f35a
Merge remote-tracking branch 'origin/main' into users/jdixon/add-comm…
dixonjoel c35bbb4
Try quoting
dixonjoel 94c19d6
Remove some bash code to narrow down error
dixonjoel 6d628bc
Add back in path
dixonjoel 867661a
Try another arrangement
dixonjoel d90f284
Try without echoing the path
dixonjoel 34ee66b
Try some quotes, why not?
dixonjoel 8672646
Try without --path, why not
dixonjoel a5a414d
Try without Python 3.9
dixonjoel 10bad85
Echo the poetry env info
dixonjoel bcc1c1a
Add back in path
dixonjoel 9d3f040
Try a different arrangement of quotes
dixonjoel 0899ce9
Change variable name
dixonjoel 3d89b41
Change variable name
dixonjoel 359640c
print some debug info
mshafer-NI 3fa2cfb
don't stop on help
mshafer-NI 17a40c3
don't fail fast
mshafer-NI a3778a6
ok, let's print it out without exiting first
mshafer-NI 640e806
ok, use or
mshafer-NI 3acc52c
ok, try this...
mshafer-NI 96c1e97
analyze-project: Fix venv caching (#28)
bkeryan 082363c
Restore all the matrix of python versions and OSs
dixonjoel 1831603
Merge branch 'users/jdixon/add-common-workflows' of https://github.co…
dixonjoel 4dd9375
Fix copy and paste error in test_actions.yml
dixonjoel 2187533
Minor PR feedback
dixonjoel dd965b2
Remove 3.13t Python from some spots
dixonjoel 87ed507
Use v0 for actions in README
dixonjoel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Docstring required.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Module docstring.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | ||
| ``` |
dixonjoel marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
dixonjoel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 }} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.