From 672d311fdd838138579fe26bd2c7d31e72ead5ff Mon Sep 17 00:00:00 2001 From: mxj711 Date: Thu, 9 Apr 2026 16:49:49 +0800 Subject: [PATCH] chore: align CI workflow with current execution model and contributor guidance --- .github/workflows/ci.yml | 102 ++++++++++++++++++++------------ CONTRIBUTING.md | 12 ++-- docs/ja/CONTRIBUTING.md | 12 ++-- docs/ko/CONTRIBUTING.md | 12 ++-- docs/zh_CN/CONTRIBUTING.md | 12 ++-- src/unilab/algos/mlx/ppo/ppo.py | 4 +- 6 files changed, 94 insertions(+), 60 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33943bad9..9ce65f6c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,63 +15,89 @@ on: - ".github/pull_request_template.md" workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: read + env: UV_FROZEN: "1" jobs: - lint: - runs-on: ubuntu-latest + ruff-lint: + timeout-minutes: 5 + runs-on: ubuntu-slim + steps: + - uses: actions/checkout@v6.0.2 + with: + persist-credentials: false + - name: Install uv + uses: astral-sh/setup-uv@v8.0.0 + - name: Install dependencies(only dev group) + run: uv sync --only-group dev + - name: Check + run: uv run --no-sync ruff check --output-format=github . + + ruff-format: + timeout-minutes: 5 + runs-on: ubuntu-slim steps: - - uses: actions/checkout@v4 - - uses: astral-sh/setup-uv@v6 + - uses: actions/checkout@v6.0.2 with: - enable-cache: true - - name: Lint with ruff - run: | - uv tool run ruff check . - uv tool run ruff format --check . + persist-credentials: false + - name: Install uv + uses: astral-sh/setup-uv@v8.0.0 + - name: Install dependencies(only dev group) + run: uv sync --only-group dev + - name: Check + run: uv run --no-sync ruff format --check . - typecheck: - runs-on: ubuntu-latest + mypy: + timeout-minutes: 10 + runs-on: macos-26 # Mac platform requires fewer dependencies to install steps: - - uses: actions/checkout@v4 - - uses: astral-sh/setup-uv@v6 + - uses: actions/checkout@v6.0.2 with: - enable-cache: true + persist-credentials: false + - name: Install uv + uses: astral-sh/setup-uv@v8.0.0 - name: Install dependencies run: uv sync - - name: mypy + - name: Check run: uv run mypy src/unilab - - name: pyright + + pyright: + timeout-minutes: 10 + runs-on: macos-26 # Mac platform requires fewer dependencies to install + steps: + - uses: actions/checkout@v6.0.2 + with: + persist-credentials: false + - name: Install uv + uses: astral-sh/setup-uv@v8.0.0 + - name: Install dependencies + run: uv sync + - name: Check run: uv run pyright test: - # strategy: - # matrix: - # os: [ubuntu-latest, macos-latest] + strategy: + matrix: + os: [ubuntu-slim] # python-version: ['3.10', '3.11', '3.12', '3.13'] - # runs-on: ${{ matrix.os }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - - uses: astral-sh/setup-uv@v6 + - uses: actions/checkout@v6.0.2 + with: + persist-credentials: false + - name: Install uv + uses: astral-sh/setup-uv@v8.0.0 with: - enable-cache: true # python-version: ${{ matrix.python-version }} python-version: '3.11' - # - name: Install dependencies (Linux) - # if: runner.os == 'Linux' - # run: | - # sudo apt-get update && sudo apt-get install -y cmake - # uv sync - # - name: Install dependencies (macOS) - # if: runner.os == 'macOS' - # run: | - # brew install cmake - # uv sync - name: Install dependencies - run: | - sudo apt-get update && sudo apt-get install -y cmake - uv sync + run: uv sync --extra motrix - name: Test with coverage - run: uv run pytest -m "not slow and not veryslow" --cov=unilab --cov-report=term-missing --cov-fail-under=10 + run: uv run pytest -m "not slow and not veryslow" --cov=unilab --cov-report markdown-append:$GITHUB_STEP_SUMMARY --cov-fail-under=10 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a67b8bbcd..26717c144 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,15 +96,17 @@ uv run pytest -m veryslow -v ## CI Workflow -PRs targeting `main` trigger three jobs automatically. The current workflow does not rerun the same CI set again after the PR is merged into `main`. +PRs targeting `main` trigger five jobs automatically: `ruff-lint`, `ruff-format`, `mypy`, `pyright`, and `test`. The workflow also enables manual runs through `workflow_dispatch`, skips docs-only and collaboration-metadata changes, and cancels older in-progress runs for the same PR branch. | Job | Content | Blocking on failure | |-----|---------|---------------------| -| `lint` | `ruff check` + `ruff format --check` | ✅ | -| `typecheck` | `mypy src/unilab` + `pyright` | ✅ | -| `test` | `pytest -m "not slow and not veryslow" --cov --cov-fail-under=10` | ✅ | +| `ruff-lint` | `uv sync --only-group dev` + `uv run --no-sync ruff check --output-format=github .` on `ubuntu-slim` | ✅ | +| `ruff-format` | `uv sync --only-group dev` + `uv run --no-sync ruff format --check .` on `ubuntu-slim` | ✅ | +| `mypy` | `uv sync` + `uv run mypy src/unilab` on `macos-26` | ✅ | +| `pyright` | `uv sync` + `uv run pyright` on `macos-26` | ✅ | +| `test` | `uv sync --extra motrix` + `uv run pytest -m "not slow and not veryslow" --cov=unilab --cov-report markdown-append:$GITHUB_STEP_SUMMARY --cov-fail-under=10` on `ubuntu-slim` with Python 3.11 | ✅ | -Docs-only and collaboration-metadata changes such as `*.md`, `docs/**`, issue templates, and `CODEOWNERS` do not trigger CI. +Docs-only and collaboration-metadata changes such as `*.md`, `docs/**`, `CONTRIBUTING.md`, `AGENTS.md`, `LICENSE`, issue templates, `CODEOWNERS`, and `.github/pull_request_template.md` do not trigger CI. ## Documentation Expectations diff --git a/docs/ja/CONTRIBUTING.md b/docs/ja/CONTRIBUTING.md index 95dc9f6b5..06f201dab 100644 --- a/docs/ja/CONTRIBUTING.md +++ b/docs/ja/CONTRIBUTING.md @@ -96,15 +96,17 @@ uv run pytest -m veryslow -v ## CI Workflow -`main` 向け PR では 3 つの job が自動実行されます。現在の workflow では、PR が `main` に merge された後に同じ CI 一式を再実行しません。 +`main` 向け PR では `ruff-lint`、`ruff-format`、`mypy`、`pyright`、`test` の 5 つの job が自動実行されます。workflow は `workflow_dispatch` による手動実行にも対応し、docs-only / 協業メタデータ変更は skip し、同じ PR branch の古い進行中 run は自動で cancel します。 | Job | 内容 | 失敗で block するか | |-----|------|---------------------| -| `lint` | `ruff check` + `ruff format --check` | ✅ | -| `typecheck` | `mypy src/unilab` + `pyright` | ✅ | -| `test` | `pytest -m "not slow and not veryslow" --cov --cov-fail-under=10` | ✅ | +| `ruff-lint` | `ubuntu-slim` 上で `uv sync --only-group dev` + `uv run --no-sync ruff check --output-format=github .` | ✅ | +| `ruff-format` | `ubuntu-slim` 上で `uv sync --only-group dev` + `uv run --no-sync ruff format --check .` | ✅ | +| `mypy` | `macos-26` 上で `uv sync` + `uv run mypy src/unilab` | ✅ | +| `pyright` | `macos-26` 上で `uv sync` + `uv run pyright` | ✅ | +| `test` | `ubuntu-slim` 上で Python 3.11 を使い、`uv sync --extra motrix` + `uv run pytest -m "not slow and not veryslow" --cov=unilab --cov-report markdown-append:$GITHUB_STEP_SUMMARY --cov-fail-under=10` | ✅ | -`*.md`、`docs/**`、issue templates、`CODEOWNERS` のような docs-only / 協業メタデータ変更では CI は起動しません。 +`*.md`、`docs/**`、`CONTRIBUTING.md`、`AGENTS.md`、`LICENSE`、issue templates、`CODEOWNERS`、`.github/pull_request_template.md` のような docs-only / 協業メタデータ変更では CI は起動しません。 ## Documentation Expectations diff --git a/docs/ko/CONTRIBUTING.md b/docs/ko/CONTRIBUTING.md index ae3bb6916..73771d9ea 100644 --- a/docs/ko/CONTRIBUTING.md +++ b/docs/ko/CONTRIBUTING.md @@ -96,15 +96,17 @@ uv run pytest -m veryslow -v ## CI Workflow -`main` 대상 PR은 자동으로 세 개의 job을 실행합니다. 현재 workflow는 PR이 `main`에 merge된 뒤 같은 CI 세트를 다시 돌리지 않습니다. +`main` 대상 PR은 `ruff-lint`, `ruff-format`, `mypy`, `pyright`, `test` 다섯 개의 job을 자동으로 실행합니다. workflow는 `workflow_dispatch` 수동 실행도 지원하고, docs-only / 협업 메타데이터 변경은 건너뛰며, 같은 PR 브랜치의 오래된 진행 중 실행은 자동으로 취소합니다. | Job | 내용 | 실패 시 차단 여부 | |-----|------|-------------------| -| `lint` | `ruff check` + `ruff format --check` | ✅ | -| `typecheck` | `mypy src/unilab` + `pyright` | ✅ | -| `test` | `pytest -m "not slow and not veryslow" --cov --cov-fail-under=10` | ✅ | +| `ruff-lint` | `ubuntu-slim`에서 `uv sync --only-group dev` + `uv run --no-sync ruff check --output-format=github .` 실행 | ✅ | +| `ruff-format` | `ubuntu-slim`에서 `uv sync --only-group dev` + `uv run --no-sync ruff format --check .` 실행 | ✅ | +| `mypy` | `macos-26`에서 `uv sync` + `uv run mypy src/unilab` 실행 | ✅ | +| `pyright` | `macos-26`에서 `uv sync` + `uv run pyright` 실행 | ✅ | +| `test` | `ubuntu-slim`에서 Python 3.11로 `uv sync --extra motrix` + `uv run pytest -m "not slow and not veryslow" --cov=unilab --cov-report markdown-append:$GITHUB_STEP_SUMMARY --cov-fail-under=10` 실행 | ✅ | -`*.md`, `docs/**`, issue templates, `CODEOWNERS` 같은 docs-only / 협업 메타데이터 변경은 CI를 트리거하지 않습니다. +`*.md`, `docs/**`, `CONTRIBUTING.md`, `AGENTS.md`, `LICENSE`, issue templates, `CODEOWNERS`, `.github/pull_request_template.md` 같은 docs-only / 협업 메타데이터 변경은 CI를 트리거하지 않습니다. ## Documentation Expectations diff --git a/docs/zh_CN/CONTRIBUTING.md b/docs/zh_CN/CONTRIBUTING.md index c9461d5dc..d63ffd800 100644 --- a/docs/zh_CN/CONTRIBUTING.md +++ b/docs/zh_CN/CONTRIBUTING.md @@ -96,15 +96,17 @@ uv run pytest -m veryslow -v ## CI Workflow -指向 `main` 的 PR 会自动触发三个 job。当前 workflow 不会在 PR 合并到 `main` 后再次重复跑同一套 CI。 +指向 `main` 的 PR 会自动触发五个 job: `ruff-lint`、`ruff-format`、`mypy`、`pyright` 和 `test`。workflow 也支持通过 `workflow_dispatch` 手动触发,会跳过纯文档和协作元信息改动,并且会自动取消同一 PR 分支上较早的进行中运行。 | Job | 内容 | 失败是否阻断 | |-----|------|--------------| -| `lint` | `ruff check` + `ruff format --check` | ✅ | -| `typecheck` | `mypy src/unilab` + `pyright` | ✅ | -| `test` | `pytest -m "not slow and not veryslow" --cov --cov-fail-under=10` | ✅ | +| `ruff-lint` | 在 `ubuntu-slim` 上执行 `uv sync --only-group dev` + `uv run --no-sync ruff check --output-format=github .` | ✅ | +| `ruff-format` | 在 `ubuntu-slim` 上执行 `uv sync --only-group dev` + `uv run --no-sync ruff format --check .` | ✅ | +| `mypy` | 在 `macos-26` 上执行 `uv sync` + `uv run mypy src/unilab` | ✅ | +| `pyright` | 在 `macos-26` 上执行 `uv sync` + `uv run pyright` | ✅ | +| `test` | 在 `ubuntu-slim` 上以 Python 3.11 执行 `uv sync --extra motrix` + `uv run pytest -m "not slow and not veryslow" --cov=unilab --cov-report markdown-append:$GITHUB_STEP_SUMMARY --cov-fail-under=10` | ✅ | -纯文档和协作元信息改动,例如 `*.md`、`docs/**`、issue templates 和 `CODEOWNERS`,不会触发 CI。 +纯文档和协作元信息改动,例如 `*.md`、`docs/**`、`CONTRIBUTING.md`、`AGENTS.md`、`LICENSE`、issue templates、`CODEOWNERS` 和 `.github/pull_request_template.md`,不会触发 CI。 ## Documentation Expectations diff --git a/src/unilab/algos/mlx/ppo/ppo.py b/src/unilab/algos/mlx/ppo/ppo.py index e2fab7620..505198bf9 100644 --- a/src/unilab/algos/mlx/ppo/ppo.py +++ b/src/unilab/algos/mlx/ppo/ppo.py @@ -69,10 +69,10 @@ def __init__(self, model: MLPActorCritic, cfg: PPOConfig) -> None: @staticmethod def _all_finite(tree) -> bool: - leaves = [leaf for _, leaf in tree_flatten(tree)] # type: ignore[misc] + leaves = [leaf for _, leaf in tree_flatten(tree)] # type: ignore[misc,str-unpack] if not leaves: return True - checks = [mx.all(mx.isfinite(leaf)) for leaf in leaves] + checks = [mx.all(mx.isfinite(leaf)) for leaf in leaves] # type: ignore[arg-type] mx.eval(*checks) return all(bool(c.item()) for c in checks)