Skip to content

Commit e57ca92

Browse files
authored
Migrate unit test to be reusable (#3884)
* Migrate unit test to be reusable * Set working directory once * Add jobs * Do not use relative path for inputs * Copy over steps * Use system * Use relative path * Use modal_token_secret * Move container dependencies into tests * Use upper case * Update naming * Remove system * Move env as well
1 parent 02f6a4b commit e57ca92

2 files changed

Lines changed: 153 additions & 105 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 6 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -81,111 +81,12 @@ jobs:
8181
run: python -m modal_global_objects.mounts.modal_client_package
8282

8383
client-test:
84-
name: Unit tests on ${{ matrix.python-version }} and ${{ matrix.os }} (protobuf=${{ matrix.proto-version }})
85-
timeout-minutes: 30
86-
87-
strategy:
88-
fail-fast: false # run all variants across python versions/os to completion
89-
matrix:
90-
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
91-
os: ["ubuntu-24.04"]
92-
proto-version: ["latest"]
93-
include:
94-
- os: "macos-15-intel" # x86-64
95-
python-version: "3.10"
96-
proto-version: "latest"
97-
- os: "macos-15" # ARM64 (M1)
98-
python-version: "3.10"
99-
proto-version: "latest"
100-
- os: "windows-latest"
101-
python-version: "3.10"
102-
proto-version: "latest"
103-
- os: "ubuntu-24.04"
104-
python-version: "3.10"
105-
proto-version: "3.20"
106-
107-
runs-on: ${{ matrix.os }}
108-
steps:
109-
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
110-
111-
- uses: ./.github/actions/setup-cached-python
112-
with:
113-
version: ${{ matrix.python-version }}
114-
115-
- if: matrix.proto-version != 'latest'
116-
name: Install protobuf
117-
run: pip install protobuf==${{ matrix.proto-version }}
118-
119-
- name: Build protobuf
120-
run: inv protoc
121-
122-
- name: Build client package (installs all dependencies)
123-
run: pip install -e .
124-
125-
- name: Run client tests
126-
run: inv test
127-
128-
- name: Run docstring tests
129-
if: github.event.pull_request.head.repo.fork == false
130-
env:
131-
MODAL_ENVIRONMENT: client-doc-tests
132-
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
133-
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
134-
run: pytest -v --markdown-docs -m markdown-docs modal
135-
136-
container-dependencies:
137-
name: Check minimal container dependencies for ${{ matrix.python-version }} / ${{ matrix.image-builder-version }}
138-
runs-on: ubuntu-24.04
139-
timeout-minutes: 4
140-
strategy:
141-
matrix:
142-
include:
143-
- image-builder-version: "2024.04"
144-
python-version: "3.10"
145-
- image-builder-version: "2024.04"
146-
python-version: "3.12"
147-
- image-builder-version: "2024.10"
148-
python-version: "3.10"
149-
- image-builder-version: "2024.10"
150-
python-version: "3.13"
151-
- image-builder-version: "2025.06"
152-
python-version: "3.10"
153-
- image-builder-version: "2025.06"
154-
python-version: "3.14"
155-
156-
steps:
157-
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
158-
159-
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
160-
with:
161-
python-version: ${{ matrix.python-version }}
162-
163-
- name: Install dependencies
164-
run: |
165-
pip install -r modal/builder/${{ matrix.image-builder-version }}.txt
166-
pip install synchronicity
167-
168-
- name: Compile protos
169-
run: |
170-
python -m venv venv
171-
source venv/bin/activate
172-
if [ "${{ matrix.python-version }}" == "3.10" ]; then
173-
pip install grpcio-tools==1.48.2 grpclib==0.4.7;
174-
elif [ "${{ matrix.python-version }}" == "3.12" ]; then
175-
pip install grpcio-tools==1.59.2 grpclib==0.4.7;
176-
elif [ "${{ matrix.python-version }}" == "3.13" ]; then
177-
pip install grpcio-tools==1.66.2 grpclib==0.4.7;
178-
elif [ "${{ matrix.python-version }}" == "3.14" ]; then
179-
pip install grpcio-tools==1.76.0 grpclib==0.4.9;
180-
fi
181-
python -m grpc_tools.protoc --python_out=. --grpclib_python_out=. --grpc_python_out=. -I . modal_proto/api.proto modal_proto/task_command_router.proto
182-
python -m grpc_tools.protoc --plugin=protoc-gen-modal-grpclib-python=protoc_plugin/plugin.py --modal-grpclib-python_out=. -I . modal_proto/api.proto
183-
deactivate
184-
185-
- name: Check entrypoint import
186-
run: |
187-
python -c 'import modal._container_entrypoint; import modal._runtime.asgi'
188-
if [ "${{ matrix.image-builder-version }}" == "2024.04" ]; then python -c 'import fastapi'; fi
84+
uses: ./.github/workflows/tests.yml
85+
with:
86+
working_directory: "."
87+
secrets:
88+
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
89+
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
18990

19091
publish-client:
19192
name: Publish client package

.github/workflows/tests.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Unit tests
2+
on:
3+
workflow_call:
4+
inputs:
5+
working_directory:
6+
required: true
7+
type: string
8+
secrets:
9+
MODAL_TOKEN_ID:
10+
required: true
11+
MODAL_TOKEN_SECRET:
12+
required: true
13+
14+
env:
15+
TERM: linux
16+
TERMINFO: /etc/terminfo
17+
PYTHONIOENCODING: utf-8
18+
19+
jobs:
20+
client-test:
21+
name: Unit tests on ${{ matrix.python-version }} and ${{ matrix.os }} (protobuf=${{ matrix.proto-version }})
22+
timeout-minutes: 30
23+
24+
strategy:
25+
fail-fast: false # run all variants across python versions/os to completion
26+
matrix:
27+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
28+
os: ["ubuntu-24.04"]
29+
proto-version: ["latest"]
30+
include:
31+
- os: "macos-15-intel" # x86-64
32+
python-version: "3.10"
33+
proto-version: "latest"
34+
- os: "macos-15" # ARM64 (M1)
35+
python-version: "3.10"
36+
proto-version: "latest"
37+
- os: "windows-latest"
38+
python-version: "3.10"
39+
proto-version: "latest"
40+
- os: "ubuntu-24.04"
41+
python-version: "3.10"
42+
proto-version: "3.20"
43+
44+
runs-on: ${{ matrix.os }}
45+
defaults:
46+
run:
47+
working-directory: ${{ inputs.working_directory }}
48+
steps:
49+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
50+
51+
- name: Install Python
52+
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
53+
with:
54+
python-version: ${{ matrix.python-version }}
55+
56+
- name: Setup uv with caching
57+
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2
58+
with:
59+
enable-cache: true
60+
version: "0.9.24"
61+
cache-dependency-glob: |
62+
${{ inputs.working_directory }}/requirements.dev.txt
63+
${{ inputs.working_directory }}/pyproject.toml
64+
65+
- name: Install Python packages
66+
shell: bash
67+
run: |
68+
uv pip install --system -r requirements.dev.txt
69+
70+
- if: matrix.proto-version != 'latest'
71+
name: Install protobuf
72+
run: pip install protobuf==${{ matrix.proto-version }}
73+
74+
- name: Build protobuf
75+
run: inv protoc
76+
77+
- name: Build client package (installs all dependencies)
78+
run: pip install -e .
79+
80+
- name: Run client tests
81+
run: inv test
82+
83+
- name: Run docstring tests
84+
if: github.event.pull_request.head.repo.fork == false
85+
env:
86+
MODAL_ENVIRONMENT: client-doc-tests
87+
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
88+
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
89+
run: pytest -v --markdown-docs -m markdown-docs modal
90+
91+
container-dependencies:
92+
name: Check minimal container dependencies for ${{ matrix.python-version }} - ${{ matrix.image-builder-version }}
93+
runs-on: ubuntu-24.04
94+
timeout-minutes: 4
95+
strategy:
96+
matrix:
97+
include:
98+
- image-builder-version: "2024.04"
99+
python-version: "3.10"
100+
- image-builder-version: "2024.04"
101+
python-version: "3.12"
102+
- image-builder-version: "2024.10"
103+
python-version: "3.10"
104+
- image-builder-version: "2024.10"
105+
python-version: "3.13"
106+
- image-builder-version: "2025.06"
107+
python-version: "3.10"
108+
- image-builder-version: "2025.06"
109+
python-version: "3.14"
110+
111+
defaults:
112+
run:
113+
working-directory: ${{ inputs.working_directory }}
114+
115+
steps:
116+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
117+
118+
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
119+
with:
120+
python-version: ${{ matrix.python-version }}
121+
122+
- name: Install dependencies
123+
run: |
124+
pip install -r modal/builder/${{ matrix.image-builder-version }}.txt
125+
pip install synchronicity
126+
127+
- name: Compile protos
128+
run: |
129+
python -m venv venv
130+
source venv/bin/activate
131+
if [ "${{ matrix.python-version }}" == "3.10" ]; then
132+
pip install grpcio-tools==1.48.2 grpclib==0.4.7;
133+
elif [ "${{ matrix.python-version }}" == "3.12" ]; then
134+
pip install grpcio-tools==1.59.2 grpclib==0.4.7;
135+
elif [ "${{ matrix.python-version }}" == "3.13" ]; then
136+
pip install grpcio-tools==1.66.2 grpclib==0.4.7;
137+
elif [ "${{ matrix.python-version }}" == "3.14" ]; then
138+
pip install grpcio-tools==1.76.0 grpclib==0.4.9;
139+
fi
140+
python -m grpc_tools.protoc --python_out=. --grpclib_python_out=. --grpc_python_out=. -I . modal_proto/api.proto modal_proto/task_command_router.proto
141+
python -m grpc_tools.protoc --plugin=protoc-gen-modal-grpclib-python=protoc_plugin/plugin.py --modal-grpclib-python_out=. -I . modal_proto/api.proto
142+
deactivate
143+
144+
- name: Check entrypoint import
145+
run: |
146+
python -c 'import modal._container_entrypoint; import modal._runtime.asgi'
147+
if [ "${{ matrix.image-builder-version }}" == "2024.04" ]; then python -c 'import fastapi'; fi

0 commit comments

Comments
 (0)