Skip to content

Commit c6106e0

Browse files
committed
Refactor ci: use composite actions
1 parent 95a237e commit c6106e0

6 files changed

Lines changed: 110 additions & 56 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Install Dependencies
2+
description: Install package dependencies using uv
3+
4+
inputs:
5+
options:
6+
description: 'Package options to install (space-separated, e.g., "full")'
7+
required: false
8+
default: ''
9+
groups:
10+
description: 'Dependency groups to install (space-separated, e.g., "test doc")'
11+
required: false
12+
default: ''
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Install dependencies (options=[${{ inputs.options }}], groups=[${{ inputs.groups }}])
18+
shell: bash
19+
run: |
20+
# Build the install command
21+
cmd="uv pip install -e"
22+
23+
# Add options if provided
24+
if [ -n "${{ inputs.options }}" ]; then
25+
# Convert space-separated options to comma-separated for brackets
26+
options=$(echo "${{ inputs.options }}" | tr ' ' ',')
27+
cmd="$cmd '.[$options]'"
28+
else
29+
cmd="$cmd ."
30+
fi
31+
32+
# Add groups
33+
for group in ${{ inputs.groups }}; do
34+
cmd="$cmd --group $group"
35+
done
36+
37+
# Execute the command
38+
eval $cmd

.github/actions/setup/action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Setup
2+
description: Checkout repository and set up uv
3+
4+
inputs:
5+
python-version:
6+
description: Python version to use
7+
required: false
8+
default: '3.14'
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
- name: Set up uv
16+
uses: astral-sh/setup-uv@v5
17+
with:
18+
python-version: ${{ inputs.python-version }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Upload to Codecov
2+
description: Upload coverage results to Codecov
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Upload results to Codecov
8+
uses: codecov/codecov-action@v4
9+
with:
10+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/build-deploy-docs.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88

99
env:
1010
UV_NO_SYNC: 1
11-
PYTHON_VERSION: '3.14'
1211

1312
jobs:
1413
build-deploy-doc:
@@ -18,16 +17,12 @@ jobs:
1817
permissions:
1918
contents: write
2019
steps:
21-
- name: Checkout repository
22-
uses: actions/checkout@v4
20+
- uses: ./.github/actions/setup
2321

24-
- name: Set up uv
25-
uses: astral-sh/setup-uv@v5
22+
- uses: ./.github/actions/install-deps
2623
with:
27-
python-version: ${{ env.PYTHON_VERSION }}
28-
29-
- name: Install dependencies (default with full options & doc)
30-
run: uv pip install -e '.[full]' --group doc
24+
options: full
25+
groups: doc
3126

3227
- name: Determine deployment folder
3328
id: deploy_folder

.github/workflows/release.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ on:
44
release:
55
types: [published]
66

7-
env:
8-
PYTHON_VERSION: 3.14
9-
107
jobs:
118
pypi-publish:
129
name: Publish to PyPI
@@ -16,13 +13,7 @@ jobs:
1613
# IMPORTANT: this permission is mandatory for trusted publishing
1714
id-token: write
1815
steps:
19-
- name: Checkout repository
20-
uses: actions/checkout@v4
21-
22-
- name: Set up uv
23-
uses: astral-sh/setup-uv@v5
24-
with:
25-
python-version: ${{ env.PYTHON_VERSION }}
16+
- uses: ./.github/actions/setup
2617

2718
- name: Build
2819
run: uv build

.github/workflows/tests.yml

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88

99
env:
1010
UV_NO_SYNC: 1
11-
PYTHON_VERSION: 3.14
1211

1312
jobs:
1413
tests-full-install:
@@ -19,36 +18,32 @@ jobs:
1918
matrix:
2019
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
2120
os: [ubuntu-latest, macOS-latest, windows-latest]
22-
env:
23-
PYTHON_VERSION: ${{ matrix.python-version }} # Override the PYTHON_VERSION of the global env
2421

2522
steps:
26-
- &checkout
27-
name: Checkout repository
28-
uses: actions/checkout@v4
29-
- &setup-uv
30-
name: Set up uv
31-
uses: astral-sh/setup-uv@v5
23+
- uses: ./.github/actions/setup
3224
with:
33-
python-version: ${{ env.PYTHON_VERSION }}
34-
- name: Install default (with full options) and test dependencies
35-
run: uv pip install -e '.[full]' --group test
25+
python-version: ${{ matrix.python-version }}
26+
27+
- uses: ./.github/actions/install-deps
28+
with:
29+
options: full
30+
groups: test
31+
3632
- name: Run unit and doc tests with coverage report
3733
run: uv run pytest -W error tests/unit tests/doc --cov=src --cov-report=xml
38-
- &upload-codecov
39-
name: Upload results to Codecov
40-
uses: codecov/codecov-action@v4
41-
with:
42-
token: ${{ secrets.CODECOV_TOKEN }}
34+
35+
- uses: ./.github/actions/upload-codecov
4336

4437
tests-default-install:
4538
name: Run (most) tests with default install
4639
runs-on: ubuntu-latest
4740
steps:
48-
- *checkout
49-
- *setup-uv
50-
- name: Install default (without any option) and test dependencies
51-
run: uv pip install -e . --group test
41+
- uses: ./.github/actions/setup
42+
43+
- uses: ./.github/actions/install-deps
44+
with:
45+
groups: test
46+
5247
- name: Run unit and doc tests with coverage report
5348
run: |
5449
uv run pytest -W error tests/unit tests/doc \
@@ -57,30 +52,36 @@ jobs:
5752
--ignore tests/doc/test_aggregation.py \
5853
--cov=src --cov-report=xml
5954
60-
- *upload-codecov
55+
- uses: ./.github/actions/upload-codecov
6156

6257
tests-float64:
6358
name: Run tests on float64 dtype
6459
runs-on: ubuntu-latest
6560
steps:
66-
- *checkout
67-
- *setup-uv
68-
- name: Install default (with full options) and test dependencies
69-
run: uv pip install -e '.[full]' --group test
61+
- uses: ./.github/actions/setup
62+
63+
- uses: ./.github/actions/install-deps
64+
with:
65+
options: full
66+
groups: test
67+
7068
- name: Run unit and doc tests with coverage report
7169
run: uv run pytest -W error tests/unit tests/doc --cov=src --cov-report=xml
7270
env:
7371
PYTEST_TORCH_DTYPE: float64
74-
- *upload-codecov
72+
73+
- uses: ./.github/actions/upload-codecov
7574

7675
build-doc:
7776
name: Build doc
7877
runs-on: ubuntu-latest
7978
steps:
80-
- *checkout
81-
- *setup-uv
82-
- name: Install dependencies (default with full options & doc)
83-
run: uv pip install -e '.[full]' --group doc
79+
- uses: ./.github/actions/setup
80+
81+
- uses: ./.github/actions/install-deps
82+
with:
83+
options: full
84+
groups: doc
8485

8586
- name: Build Documentation
8687
working-directory: docs
@@ -90,11 +91,12 @@ jobs:
9091
name: Run mypy
9192
runs-on: ubuntu-latest
9293
steps:
93-
- *checkout
94-
- *setup-uv
94+
- uses: ./.github/actions/setup
9595

96-
- name: Install dependencies (default with full options & check)
97-
run: uv pip install -e '.[full]' --group check
96+
- uses: ./.github/actions/install-deps
97+
with:
98+
options: full
99+
groups: check
98100

99-
- name: Run mypy
100-
run: uv run mypy src/torchjd
101+
- name: Run mypy
102+
run: uv run mypy src/torchjd

0 commit comments

Comments
 (0)