11name : Analyze project
22description : >
3- This workflow analyzes the code quality of a Python project using various
3+ This action analyzes the code quality of a Python project using various
44 linters and type checkers including ni-python-styleguide,
55 mypy (if the 'mypy' package is installed), and pyright (if the 'pyright'
66 package is installed).
@@ -11,14 +11,22 @@ inputs:
1111 default : ${{ github.workspace }}
1212 install-args :
1313 # E.g. "--extras 'drivers addons' --with examples,docs"
14- description : ' Extra arguments. Install command will be "poetry install <install-args>".'
14+ description : >
15+ Extra arguments. Install command will be "poetry install -v <install-args>".
16+ Do not pass untrusted user input.
1517 default : ' '
1618 required : false
1719 type : string
1820
1921runs :
2022 using : composite
2123 steps :
24+ - name : Validate event type
25+ if : ${{ github.event_name == 'pull_request_target' || github.event_name == 'workflow_run' }}
26+ run : |
27+ echo "::error title=Analyze Project Error::Unsupported event '$GITHUB_EVENT_NAME'"
28+ exit 1
29+ shell : bash
2230 - name : Get project info
2331 id : get_project_info
2432 run : |
@@ -36,25 +44,30 @@ runs:
3644 shell : bash
3745 working-directory : ${{ inputs.project-directory }}
3846 - name : Check for lock changes
39- run : poetry check --lock -C "${{ inputs.project-directory }}"
47+ run : poetry check --lock
4048 shell : bash
49+ working-directory : ${{ inputs.project-directory }}
4150 - name : Generate install args hash
4251 id : install_args_hash
4352 run : |
44- install_args_hash=$(echo "${{ inputs.install-args }} " | sha256sum | cut -d ' ' -f1)
53+ install_args_hash=$(echo "$INSTALL_ARGS " | sha256sum | cut -d ' ' -f1)
4554 echo "hash=$install_args_hash" >> "$GITHUB_OUTPUT"
4655 shell : bash
56+ env :
57+ INSTALL_ARGS : ${{ inputs.install-args }}
4758 - name : Cache virtualenv
4859 uses : actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
4960 with :
5061 path : ${{ steps.get_project_info.outputs.venv-path }}
5162 key : ${{ steps.get_project_info.outputs.name }}-${{ runner.os }}-py${{ env.pythonVersion }}-${{ hashFiles(format('{0}/poetry.lock', inputs.project-directory)) }}-${{ steps.install_args_hash.outputs.hash }}
5263 - name : Install ${{ steps.get_project_info.outputs.name }}
5364 run : |
54- install_cmd="poetry install -v ${{ inputs.install-args }} "
65+ install_cmd="poetry install -v $INSTALL_ARGS "
5566 eval $install_cmd
5667 working-directory : ${{ inputs.project-directory }}
5768 shell : bash
69+ env :
70+ INSTALL_ARGS : ${{ inputs.install-args }}
5871 - name : Lint
5972 run : poetry run ni-python-styleguide lint
6073 working-directory : ${{ inputs.project-directory }}
7992 shell : poetry run python {0}
8093 - name : Echo check_tools outputs
8194 run : |
82- echo "mypy installed: ${{ steps.check_tools.outputs.mypy }} "
83- echo "pyright installed: ${{ steps.check_tools.outputs.pyright }} "
95+ echo "mypy installed: $MYPY_INSTALLED "
96+ echo "pyright installed: $PYRIGHT_INSTALLED "
8497 shell : bash
98+ env :
99+ MYPY_INSTALLED : ${{ steps.check_tools.outputs.mypy }}
100+ PYRIGHT_INSTALLED : ${{ steps.check_tools.outputs.pyright }}
85101 - name : Mypy static analysis
86102 if : steps.check_tools.outputs.mypy == 'true'
87103 run : poetry run mypy
90106 - name : Add virtualenv to the path for pyright-action
91107 if : steps.check_tools.outputs.pyright == 'true'
92108 shell : bash
93- run : |
109+ run : | # zizmor: ignore[github-env] # intentionally add project venv to the path
94110 echo "$(dirname $(poetry env info --executable))" >> $GITHUB_PATH
95111 working-directory : ${{ inputs.project-directory }}
96112 - name : Pyright static analysis
0 commit comments