From d47ba0bb71680ca6f4eb3d341b762cb29b010848 Mon Sep 17 00:00:00 2001 From: LJ Date: Sun, 27 Apr 2025 09:21:58 -0700 Subject: [PATCH 1/7] build(workflow): add tests to CI workflow --- .github/workflows/CI.yml | 10 +++++++--- .github/workflows/_test.yml | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/_test.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c5397184..87092e22 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -12,14 +12,14 @@ on: - src/** - python/** - "*.toml" - - ".github/workflows/CI.yml" + - ".github/workflows/*.yml" push: branches: [main] paths: - src/** - python/** - "*.toml" - - ".github/workflows/CI.yml" + - ".github/workflows/*.yml" workflow_dispatch: permissions: @@ -38,6 +38,10 @@ jobs: - uses: actions/setup-python@v5 with: python-version: 3.x + - name: Run tests + uses: ./.github/workflows/_test.yml + with: + platform: ${{ matrix.platform.runner }} - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -45,4 +49,4 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' manylinux: auto - container: ${{ matrix.platform.container }} + container: ${{ matrix.platform.container }} \ No newline at end of file diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml new file mode 100644 index 00000000..2d7f4f10 --- /dev/null +++ b/.github/workflows/_test.yml @@ -0,0 +1,40 @@ +name: Run Tests + +on: + workflow_call: + inputs: + platform: + required: true + type: string + +jobs: + rust: + strategy: + matrix: + python-version: [3.11, 3.13] + runs-on: ${{ inputs.platform }} + steps: + - uses: actions/checkout@v4 + + - run: rustup toolchain install stable --profile minimal + - name: Rust Cache + uses: Swatinem/rust-cache@v2.7.3 + - name: Build + run: cargo build --verbose + - name: Run Rust tests + run: cargo test --verbose + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + + - name: Install dependencies + run: | + pip3 install . + pip3 install pytest + + - name: Run Python tests + run: | + cd python + pytest cocoindex/tests \ No newline at end of file From 8d0d210cf557004167a89084e3bcbf428a7ef611 Mon Sep 17 00:00:00 2001 From: LJ Date: Sun, 27 Apr 2025 09:37:12 -0700 Subject: [PATCH 2/7] fix: the way to call sub workflow --- .github/workflows/CI.yml | 9 ++++----- .github/workflows/_test.yml | 7 ++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 87092e22..f321b31b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -38,10 +38,6 @@ jobs: - uses: actions/setup-python@v5 with: python-version: 3.x - - name: Run tests - uses: ./.github/workflows/_test.yml - with: - platform: ${{ matrix.platform.runner }} - name: Build wheels uses: PyO3/maturin-action@v1 with: @@ -49,4 +45,7 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' manylinux: auto - container: ${{ matrix.platform.container }} \ No newline at end of file + container: ${{ matrix.platform.container }} + test: + name: Run test + uses: ./.github/workflows/_test.yml diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 2d7f4f10..ec07bcf3 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -2,17 +2,14 @@ name: Run Tests on: workflow_call: - inputs: - platform: - required: true - type: string jobs: rust: strategy: matrix: python-version: [3.11, 3.13] - runs-on: ${{ inputs.platform }} + platform: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v4 From 81b93d0dff88e9865244a2c37788008f523d44a0 Mon Sep 17 00:00:00 2001 From: LJ Date: Sun, 27 Apr 2025 09:54:24 -0700 Subject: [PATCH 3/7] fix: switch to `maturin develop` --- .github/workflows/_test.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index ec07bcf3..666a1a4e 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -16,8 +16,6 @@ jobs: - run: rustup toolchain install stable --profile minimal - name: Rust Cache uses: Swatinem/rust-cache@v2.7.3 - - name: Build - run: cargo build --verbose - name: Run Rust tests run: cargo test --verbose @@ -25,13 +23,12 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: 'pip' - - - name: Install dependencies + - name: Install Python dependencies run: | - pip3 install . - pip3 install pytest - + pip3 install maturin pytest + - name: Build Python bindings + run: | + maturin develop - name: Run Python tests run: | - cd python - pytest cocoindex/tests \ No newline at end of file + pytest python/cocoindex/tests \ No newline at end of file From ebdca1783a033bea69f9815e390b5e73b3a2a954 Mon Sep 17 00:00:00 2001 From: LJ Date: Sun, 27 Apr 2025 11:18:23 -0700 Subject: [PATCH 4/7] fix: use venv as required by `maturin` --- .github/workflows/_test.yml | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 666a1a4e..51bc3e40 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -3,6 +3,9 @@ name: Run Tests on: workflow_call: +env: + CARGO_TERM_COLOR: always + jobs: rust: strategy: @@ -16,19 +19,27 @@ jobs: - run: rustup toolchain install stable --profile minimal - name: Rust Cache uses: Swatinem/rust-cache@v2.7.3 - - name: Run Rust tests + - name: Rust build + run: cargo build --verbose + - name: Rust tests run: cargo test --verbose - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: 'pip' - - name: Install Python dependencies + - name: Install Python global dependencies run: | - pip3 install maturin pytest - - name: Build Python bindings + pip install maturin pytest + - uses: actions/cache@v4 + with: + path: .venv + key: ${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-python-${{ matrix.python-version }}- + - name: Python build & test run: | + python -m venv .venv + source .venv/bin/activate maturin develop - - name: Run Python tests - run: | pytest python/cocoindex/tests \ No newline at end of file From 1adebba94d533e81a680bb9377aee482aaa060a5 Mon Sep 17 00:00:00 2001 From: LJ Date: Sun, 27 Apr 2025 11:19:53 -0700 Subject: [PATCH 5/7] chore: update cache key for venv --- .github/workflows/_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 51bc3e40..86e6108e 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -34,9 +34,9 @@ jobs: - uses: actions/cache@v4 with: path: .venv - key: ${{ runner.os }}-python-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} + key: ${{ runner.os }}-pythonenv-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }} restore-keys: | - ${{ runner.os }}-python-${{ matrix.python-version }}- + ${{ runner.os }}-pythonenv-${{ matrix.python-version }}- - name: Python build & test run: | python -m venv .venv From 42a15305a9a20698b5cf59a006393f52ac1825c8 Mon Sep 17 00:00:00 2001 From: LJ Date: Sun, 27 Apr 2025 12:10:43 -0700 Subject: [PATCH 6/7] fix: install python dependencies in venv --- .github/workflows/_test.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 86e6108e..24c38eda 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -28,9 +28,6 @@ jobs: with: python-version: ${{ matrix.python-version }} cache: 'pip' - - name: Install Python global dependencies - run: | - pip install maturin pytest - uses: actions/cache@v4 with: path: .venv @@ -41,5 +38,7 @@ jobs: run: | python -m venv .venv source .venv/bin/activate + pip install maturin pytest maturin develop - pytest python/cocoindex/tests \ No newline at end of file + cd python + pytest cocoindex/tests \ No newline at end of file From c4fb41e64f495ccddb2f322798f4b860754b039e Mon Sep 17 00:00:00 2001 From: LJ Date: Sun, 27 Apr 2025 12:15:23 -0700 Subject: [PATCH 7/7] style: simplify command to run pytest --- .github/workflows/_test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml index 24c38eda..c2716b62 100644 --- a/.github/workflows/_test.yml +++ b/.github/workflows/_test.yml @@ -40,5 +40,4 @@ jobs: source .venv/bin/activate pip install maturin pytest maturin develop - cd python - pytest cocoindex/tests \ No newline at end of file + pytest python/cocoindex/tests \ No newline at end of file