Merge pull request #392 from mdekstrand/tweak/cleanup-ci #113
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: | |
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: lenskit | |
- 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: lenskit | |
- 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: False | |