|
| 1 | +name: UnitTest |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + release: |
| 7 | + types: |
| 8 | + - created |
| 9 | + pull_request: |
| 10 | + types: [ opened, reopened, ready_for_review, synchronize ] # added `ready_for_review` since draft is skipped |
| 11 | + schedule: |
| 12 | + - cron: "0 0 * * *" # every day at midnight UTC |
| 13 | + |
| 14 | +jobs: |
| 15 | + pytester: |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + if: github.event.pull_request.draft == false |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + os: ["ubuntu-latest", "macos-latest", "windows-latest"] |
| 22 | + python-version: ["3.10", "3.11", "3.12", "3.13"] |
| 23 | + dependency: ["lightning"] |
| 24 | + requires: ["latest"] |
| 25 | + include: |
| 26 | + - { os: "ubuntu-latest", python-version: "3.10", dependency: "lightning", requires: "oldest" } |
| 27 | + timeout-minutes: 20 |
| 28 | + env: |
| 29 | + LIGHTNING_CLOUD_URL: https://staging.gridai.dev |
| 30 | + UV_TORCH_BACKEND: cpu |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v5 |
| 34 | + - name: Install uv and setup python |
| 35 | + uses: astral-sh/setup-uv@v6 |
| 36 | + with: |
| 37 | + activate-environment: true |
| 38 | + python-version: ${{ matrix.python-version }} |
| 39 | + enable-cache: true |
| 40 | + |
| 41 | + - name: Set min. dependencies |
| 42 | + if: matrix.requires == 'oldest' |
| 43 | + run: | |
| 44 | + uv pip install 'lightning-utilities[cli]>=0.15.1' |
| 45 | + uv run python -m lightning_utilities.cli requirements set-oldest --req_files=pyproject.toml |
| 46 | +
|
| 47 | + - name: Adjust lightning dependency |
| 48 | + if: matrix.dependency != 'lightning' |
| 49 | + run: | |
| 50 | + uv pip install 'lightning-utilities[cli]>=0.15.2' |
| 51 | + uv run python -m lightning_utilities.cli requirements replace-pkg --req_files=pyproject.toml \ |
| 52 | + --old_package=lightning --new_package=${{ matrix.dependency }} |
| 53 | +
|
| 54 | + - name: Install package & dependencies |
| 55 | + run: | |
| 56 | + uv sync --group tests |
| 57 | + uv pip list |
| 58 | + # validate that the dependency is installed |
| 59 | + uv run python -c "import ${{ matrix.dependency }}" |
| 60 | +
|
| 61 | + - name: simulate missing git folder (posix) |
| 62 | + if: matrix.os != 'windows-latest' |
| 63 | + run: rm -rf .git |
| 64 | + - name: simulate missing git folder (windows) |
| 65 | + if: matrix.os == 'windows-latest' |
| 66 | + run: rm -r -fo .git |
| 67 | + |
| 68 | + - name: Tests |
| 69 | + working-directory: tests/ |
| 70 | + run: | |
| 71 | + # NOTE: do not include coverage report here, see: https://github.com/nedbat/coveragepy/issues/1003 |
| 72 | + uv run coverage run --source litlogger -m pytest unittests/ -vv -s |
| 73 | + env: # the following values are just dummies since the actual http calls are mocked out |
| 74 | + LIGHTNING_USER_ID: ${{ secrets.LIGHTNING_STAGING_USER_ID }} |
| 75 | + LIGHTNING_API_KEY: ${{ secrets.LIGHTNING_STAGING_API_KEY }} |
| 76 | + - name: Statistics |
| 77 | + working-directory: tests/ |
| 78 | + run: | |
| 79 | + coverage report |
| 80 | + coverage xml |
| 81 | +
|
| 82 | + guardian-unittest: |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: pytester |
| 85 | + if: always() |
| 86 | + steps: |
| 87 | + - run: echo "${{ needs.pytester.result }}" |
| 88 | + - name: failing... |
| 89 | + if: needs.pytester.result == 'failure' |
| 90 | + run: exit 1 |
| 91 | + - name: cancelled or skipped... |
| 92 | + if: contains(fromJSON('["cancelled", "skipped"]'), needs.pytester.result) |
| 93 | + timeout-minutes: 1 |
| 94 | + run: sleep 90 |
0 commit comments