pre-commit check #1
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: Validate Source Rules | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
concurrency: | |
group: check-${{github.ref}} | |
cancel-in-progress: true | |
jobs: | |
pre-commit: | |
name: Check pre-commit hooks | |
runs-on: ubuntu-latest | |
steps: | |
- name: ๐ฅ Check out source code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: ๐ฆ Install pre-commit | |
run: pipx install pre-commit | |
- name: ๐ช Install pre-commit hooks | |
run: pre-commit install-hooks | |
# switch git branches so we don't trip the branch pre-commit check | |
- name: Switch branches | |
run: git checkout -b check-source HEAD | |
- name: โ Check that pre-commit is clean | |
run: | | |
if pre-commit run --all-files; then | |
echo "::debug title=pre-commit::pre-commit checks passed" | |
else | |
git diff | |
git status -s |sed -Ee 's/^...(.*)/::error file=\1,title=pre-commit::pre-commit would modify this file/' | |
exit 1 | |
fi | |
lint: | |
name: Check Source Code | |
runs-on: ubuntu-latest | |
steps: | |
- name: ๐ฅ Check out source code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: ๐ Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
cache: "pip" | |
- name: ๐ ๏ธ Install development tools and dependencies | |
run: | | |
pip install -e .[dev] | |
- name: ๐ชฎ Check source code formatting | |
id: format | |
run: | | |
if ruff format --diff $PKG_DIR; then | |
echo passed=yes >>"$GITHUB_OUTPUT" | |
else | |
echo passed=no >>"$GITHUB_OUTPUT" | |
echo "::error::source code not formatted" | |
fi | |
env: | |
PKG_DIR: xshaper | |
- name: ๐ Check source code lint rules | |
id: lint | |
run: | | |
if ruff check --output-format=github $PKG_DIR; then | |
echo passed=yes >>"$GITHUB_OUTPUT" | |
else | |
echo passed=no >>"$GITHUB_OUTPUT" | |
echo "::error::source code lint check failed" | |
fi | |
env: | |
PKG_DIR: xshaper | |
- name: ๐งพ Checking lint and format results | |
run: | | |
if [ "$FMT_PASSED" = no ]; then | |
echo "::error::format failed, failing build" | |
exit 1 | |
fi | |
if [ "$LINT_PASSED" = no ]; then | |
if [ "$LINT_REQUIRED" = true ]; then | |
echo "::error::lint failed, failing build" | |
exit 2 | |
else | |
echo "::error::lint failed but non-mandatory" | |
fi | |
fi | |
env: | |
FMT_PASSED: ${{ steps.format.outputs.passed }} | |
LINT_PASSED: ${{ steps.lint.outputs.passed }} | |
LINT_REQUIRED: True | |
- name: ๐ Check types | |
id: typecheck | |
uses: jakebailey/pyright-action@v1 | |
with: | |
extra-args: xshaper |