soup/.github/workflows/ci.yml

67 lines
2.6 KiB
YAML

name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install ruff
- run: ruff check soup_cli/ tests/
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
env:
# Force UTF-8 mode on all platforms. Without this, Windows defaults to
# cp1252 ('charmap'), which fails when importing upstream packages that
# read their own source / data files without an explicit encoding
# (seen with trl.trainer.grpo_trainer on windows-latest / py3.11).
PYTHONUTF8: "1"
PYTHONIOENCODING: "utf-8"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run unit tests with coverage
run: pytest tests/ -v --tb=short --junitxml=report.xml --cov=soup_cli --cov-report=xml:coverage.xml --cov-report=term-missing:skip-covered
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
uses: codecov/codecov-action@v4
with:
files: coverage.xml
fail_ci_if_error: false
- name: Update test count badge
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' && github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
TESTS=$(python -c "
import xml.etree.ElementTree as ET
root = ET.parse('report.xml').getroot()
ts = root.find('testsuite')
print(ts.attrib.get('tests', '0') if ts is not None else root.attrib.get('tests', '0'))
")
echo "Test count: $TESTS"
# --fail-with-body: surface non-2xx (e.g. 401 expired token) as a
# CI failure with the response body printed, instead of silently
# discarding to /dev/null and leaving the badge stale.
curl --fail-with-body -sS \
-X PATCH \
-H "Authorization: token ${{ secrets.GIST_TOKEN }}" \
-d "{\"files\":{\"soup_tests.json\":{\"content\":\"{\\\"schemaVersion\\\":1,\\\"label\\\":\\\"tests\\\",\\\"message\\\":\\\"$TESTS passed\\\",\\\"color\\\":\\\"brightgreen\\\"}\"}}}" \
"https://api.github.com/gists/65fdc943f85f3b2c46ecddb415c2b779"