Lock file maintenance (#23) #62
This file contains 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
name: Python (checks) | |
on: | |
pull_request: # any pull request | |
push: | |
branches: | |
- master | |
workflow_call: | |
inputs: | |
disable-tests: | |
default: false | |
description: Whether to disable running `pytest`. | |
required: false | |
type: boolean | |
node-version: | |
default: '20' | |
description: Version of node to use. | |
required: false | |
type: string | |
poetry-plugins: | |
default: poetry-dynamic-versioning[plugin] | |
description: A whitespace seperated list of poetry plugins to be installed. | |
required: false | |
type: string | |
python-version: | |
description: | | |
Version range or exact version of a Python version to use, using semver version range syntax. | |
Read from `pyproject.toml` if unset. | |
required: false | |
type: string | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
lint: | |
name: Lint | |
env: | |
FORCE_COLOR: '1' | |
runs-on: ubuntu-latest | |
steps: | |
- name: β€΅οΈ Check out code from GitHub | |
uses: actions/checkout@v4 | |
- name: π Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
cache: npm | |
node-version: ${{ inputs.node-version }} | |
- name: π Setup Python | |
uses: finleyfamily/action-setup-python@v1.0.0 | |
with: | |
poetry-plugins: ${{ inputs.poetry-plugins }} | |
python-version: ${{ inputs.python-version }} | |
- name: β€΅οΈ Install Node Dependencies | |
run: | | |
if [[ -f "Makefile" ]]; then | |
MAKEFILE_LIST="$(make -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/ { s/:.*$// ; p ; } ; }')" | |
fi | |
if [[ -f "Makefile" ]] && [[ " ${MAKEFILE_LIST[*]} " =~ setup-npm ]]; then | |
echo "installing node dependencies using Makefile..."; | |
make setup-npm; | |
elif [[ -f "package-lock.json" ]]; then | |
echo "installing node dependencies using pipeline"; | |
npm ci; | |
else | |
red="\e[31m"; | |
end_color="\e[0m"; | |
echo "${red}lockfile missing - can't install dependencies${end_color}"; | |
exit 9; | |
fi | |
- name: π Run Linters | |
run: | | |
if [[ -f "Makefile" ]]; then | |
MAKEFILE_LIST="$(make -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/ { s/:.*$// ; p ; } ; }')" | |
fi | |
if [[ -f "Makefile" ]] && [[ " ${MAKEFILE_LIST[*]} " =~ lint ]]; then | |
echo "running lint using Makefile..."; | |
make lint; | |
else | |
echo "running linters using pipeline..."; | |
echo "to customize what is run, include a 'Makefile' with a 'lint' target"; | |
poetry run black . --check --color --diff | |
poetry run ruff check . --select ALL | |
npx --yes pyright --venv-path ./; | |
fi | |
test: | |
if: inputs.disable-tests != 'true' | |
name: Test | |
env: | |
PYTEST_ADDOPTS: --color=yes | |
runs-on: ubuntu-latest | |
steps: | |
- name: β€΅οΈ Check out code from GitHub | |
uses: actions/checkout@v4 | |
- name: π Setup Python | |
uses: finleyfamily/action-setup-python@v1.0.0 | |
with: | |
poetry-plugins: ${{ inputs.poetry-plugins || 'poetry-dynamic-versioning' }} | |
python-version: ${{ inputs.python-version }} | |
- name: π Run Tests | |
run: | | |
if [[ -f "Makefile" ]]; then | |
MAKEFILE_LIST="$(make -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/ { s/:.*$// ; p ; } ; }')" | |
fi | |
if [[ -f "Makefile" ]] && [[ " ${MAKEFILE_LIST[*]} " =~ test ]]; then | |
echo "running tests using Makefile..."; | |
make test; | |
else | |
echo "no tests configured"; | |
echo "to customize what is run, include a 'Makefile' with a 'test' target"; | |
fi |