Merge branch 'feature-improve-python-template' into 'main' #44
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
| name: CI | |
| on: | |
| push: | |
| branches: ["**"] | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Build and import | |
| shell: bash | |
| run: | | |
| set -e | |
| ./scripts/pyproject_ssh_to_https.sh | |
| python -m venv --upgrade-deps .venv | |
| source .venv/bin/activate | |
| pip install . | |
| python -c "import chathpc.app; print(chathpc.app.__doc__)" | |
| check_format: | |
| name: Check format | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Run formatter | |
| shell: bash | |
| run: | | |
| set -Eeuo pipefail | |
| ./scripts/pyproject_ssh_to_https.sh | |
| python -m venv --upgrade-deps .venv | |
| source .venv/bin/activate | |
| pip install --upgrade hatch hatch-mkdocs | |
| # Always create outputs | |
| : > fmt.out | |
| : > metrics.txt | |
| # Run hatch fmt, capture exit code, keep full output | |
| set +e | |
| hatch fmt 2>&1 | tee fmt.out | |
| fmt_rc=${PIPESTATUS[0]} | |
| set -e | |
| # Derive lint error count as best-effort (defaults to 0 if unknown) | |
| # Adjust the regex to match your formatter's actual output. | |
| lint_errors="$(grep -Eo 'Found[[:space:]]+[0-9]+[[:space:]]+errors' fmt.out \ | |
| | tail -n 1 | grep -Eo '[0-9]+' || true)" | |
| lint_errors="${lint_errors:-0}" | |
| echo "lint_errors ${lint_errors}" > metrics.txt | |
| cat metrics.txt | |
| # Fail if hatch fmt failed OR lint_errors > 0 | |
| if [[ "${fmt_rc}" -ne 0 || "${lint_errors}" -ne 0 ]]; then | |
| echo "Formatting/lint issues detected." | |
| exit 1 | |
| fi | |
| - name: Upload format summary | |
| if: always() | |
| shell: bash | |
| run: | | |
| set -Eeuo pipefail | |
| { | |
| echo "## Format results" | |
| echo | |
| if [[ -f metrics.txt ]]; then | |
| echo "Format lint errors:" | |
| echo | |
| echo '```' | |
| cat metrics.txt | |
| echo '```' | |
| else | |
| echo "metrics.txt not found" | |
| fi | |
| echo | |
| if [[ -f fmt.out ]]; then | |
| echo "Formatter output (last 200 lines):" | |
| echo | |
| echo '```' | |
| tail -n 200 fmt.out | |
| echo '```' | |
| else | |
| echo "fmt.out not found" | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - name: Upload format artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: format-results | |
| path: | | |
| fmt.out | |
| metrics.txt | |
| - name: Build format comment body | |
| if: always() && github.event_name == 'pull_request' | |
| shell: bash | |
| run: | | |
| set -Eeuo pipefail | |
| { | |
| echo "## Format results" | |
| echo | |
| echo "**Metrics**" | |
| echo '```' | |
| cat metrics.txt 2>/dev/null || echo "metrics.txt missing" | |
| echo '```' | |
| echo | |
| echo "**Formatter output (last 200 lines)**" | |
| echo '```' | |
| tail -n 200 fmt.out 2>/dev/null || echo "fmt.out missing" | |
| echo '```' | |
| } > pr_comment.md | |
| - name: Post format comment | |
| if: always() && github.event_name == 'pull_request' | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| with: | |
| header: format-results | |
| path: pr_comment.md | |
| docs: | |
| name: Docs | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Build docs | |
| shell: bash | |
| run: | | |
| set -e | |
| ./scripts/pyproject_ssh_to_https.sh | |
| python -m venv --upgrade-deps .venv | |
| source .venv/bin/activate | |
| pip install --upgrade hatch | |
| hatch run docs:build | |
| - name: Upload docs site | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: site | |
| path: site | |
| test: | |
| name: Tests | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Run tests | |
| shell: bash | |
| run: | | |
| set -e | |
| ./scripts/pyproject_ssh_to_https.sh | |
| python -m venv --upgrade-deps .venv | |
| source .venv/bin/activate | |
| pip install --upgrade hatch | |
| hatch run test -- --junit-xml=test-results.xml | |
| - name: Publish test results | |
| if: always() | |
| uses: EnricoMi/publish-unit-test-result-action@v2 | |
| with: | |
| files: test-results.xml | |
| test_scripts: | |
| name: Test scripts | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Run script tests | |
| shell: bash | |
| run: | | |
| set -e | |
| ./scripts/pyproject_ssh_to_https.sh | |
| python -m venv --upgrade-deps .venv | |
| source .venv/bin/activate | |
| pip install . | |
| ./scripts/test_commands.sh | |
| coverage: | |
| name: Coverage | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Run coverage | |
| shell: bash | |
| run: | | |
| set -e | |
| ./scripts/pyproject_ssh_to_https.sh | |
| python -m venv --upgrade-deps .venv | |
| source .venv/bin/activate | |
| pip install --upgrade hatch | |
| hatch run cov-html | |
| - name: Upload coverage artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage | |
| path: | | |
| coverage_html_report | |
| coverage.xml | |
| - name: Report coverage | |
| if: github.event_name == 'pull_request' | |
| uses: orgoro/coverage@v3.2 | |
| with: | |
| coverageFile: coverage.xml | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Coverage summary | |
| if: always() | |
| shell: bash | |
| run: | | |
| set -Eeuo pipefail | |
| if [[ ! -f coverage.xml ]]; then | |
| echo "## Coverage results" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "coverage.xml not found" >> "$GITHUB_STEP_SUMMARY" | |
| exit 0 | |
| fi | |
| # Extract overall line-rate (Cobertura format) | |
| line_rate="$(grep -oP 'line-rate="\K[0-9.]+' coverage.xml | head -n 1)" | |
| percent="$(awk "BEGIN { printf \"%.1f\", ${line_rate} * 100 }")" | |
| { | |
| echo "## Coverage results" | |
| echo | |
| echo "| Metric | Value |" | |
| echo "|--------|-------|" | |
| echo "| Line coverage | ${percent}% |" | |
| echo | |
| echo "**Artifacts:**" | |
| echo "- coverage.xml" | |
| echo "- coverage_html_report/" | |
| } >> "$GITHUB_STEP_SUMMARY" |