Skip to content

Commit d8c08e3

Browse files
committed
ci: modularize workflows
1 parent c64ab94 commit d8c08e3

File tree

4 files changed

+123
-127
lines changed

4 files changed

+123
-127
lines changed

.github/workflows/CI.yml

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ permissions:
1919

2020
jobs:
2121
test:
22-
runs-on: ${{ matrix.os }}
23-
timeout-minutes: 60
24-
env:
25-
COVERAGE_PROCESS_START: "${{ github.workspace }}/.coveragerc"
26-
defaults:
27-
run:
28-
shell: bash
2922
strategy:
3023
matrix:
3124
julia-version: ['1']
@@ -45,48 +38,20 @@ jobs:
4538
python-version: '3.8'
4639
os: ubuntu-latest
4740
test-id: include
48-
49-
steps:
50-
- uses: actions/checkout@v4
51-
- name: "Set up Julia"
52-
uses: julia-actions/setup-julia@v2
53-
with:
54-
version: ${{ matrix.julia-version }}
55-
- name: "Cache Julia"
56-
uses: julia-actions/cache@v2
57-
with:
58-
cache-name: ${{ matrix.os }}-test-${{ matrix.julia-version }}-${{ matrix.python-version }}
59-
cache-packages: false
60-
- name: "Set up Python"
61-
uses: actions/setup-python@v5
62-
with:
63-
python-version: ${{ matrix.python-version }}
64-
cache: pip
65-
- name: "Install PySR"
66-
run: |
67-
python -m pip install --upgrade pip
68-
pip install '.[dev]'
69-
python -c 'import pysr'
70-
- name: "Assert Julia version"
71-
if: ${{ matrix.julia-version != '1'}}
72-
run: python3 -c "from pysr import jl; assert jl.VERSION.major == jl.seval('v\"${{ matrix.julia-version }}\"').major; assert jl.VERSION.minor == jl.seval('v\"${{ matrix.julia-version }}\"').minor"
73-
- name: "Set up coverage for subprocesses"
74-
run: echo 'import coverage; coverage.process_startup()' > "${{ github.workspace }}/sitecustomize.py"
75-
- name: "Run tests"
76-
run: coverage run -m pysr test main,cli,startup
77-
- name: "Run JAX tests"
78-
run: coverage run --append -m pysr test jax
79-
if: ${{ matrix.test-id == 'main' }}
80-
- name: "Run Torch tests"
81-
run: coverage run --append -m pysr test torch
82-
if: ${{ matrix.test-id == 'main' }}
83-
- name: "Build coverage report"
84-
run: coverage xml
85-
- name: "Upload results to Codecov"
86-
uses: codecov/codecov-action@v5
87-
with:
88-
token: ${{ secrets.CODECOV_TOKEN }}
89-
slug: MilesCranmer/PySR
41+
uses: ./.github/workflows/reusable.yml
42+
with:
43+
os: ${{ matrix.os }}
44+
python-version: ${{ matrix.python-version }}
45+
julia-version: ${{ matrix.julia-version }}
46+
run-coverage: true
47+
extra-tests: |
48+
echo 'import coverage; coverage.process_startup()' > "${{ github.workspace }}/sitecustomize.py"
49+
if [[ "${{ matrix.test-id }}" == "main" ]]; then
50+
coverage run --append -m pysr test jax
51+
coverage run --append -m pysr test torch
52+
fi
53+
coverage xml
54+
secrets: inherit
9055

9156
dev_install:
9257
runs-on: ${{ matrix.os }}

.github/workflows/CI_Windows.yml

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,11 @@ on:
1616

1717
jobs:
1818
test:
19-
runs-on: ${{ matrix.os }}
20-
timeout-minutes: 60
21-
defaults:
22-
run:
23-
shell: bash
24-
strategy:
25-
matrix:
26-
julia-version: ['1']
27-
python-version: ['3.13']
28-
os: [windows-latest]
29-
30-
steps:
31-
- uses: actions/checkout@v4
32-
- name: "Set up Julia"
33-
uses: julia-actions/setup-julia@v2
34-
with:
35-
version: ${{ matrix.julia-version }}
36-
- name: "Cache Julia"
37-
uses: julia-actions/cache@v2
38-
with:
39-
cache-name: ${{ matrix.os }}-test-${{ matrix.julia-version }}-${{ matrix.python-version }}
40-
cache-packages: false
41-
- name: "Set up Python"
42-
uses: actions/setup-python@v5
43-
with:
44-
python-version: ${{ matrix.python-version }}
45-
cache: pip
46-
- name: "Install PySR"
47-
run: |
48-
python -m pip install --upgrade pip
49-
pip install '.[dev]'
50-
python -c 'import pysr'
51-
- name: "Run tests"
52-
run: |
53-
python -m pysr test main,cli,startup
54-
- name: "Install Torch"
55-
run: pip install torch # (optional import)
56-
- name: "Run Torch tests"
57-
run: python -m pysr test torch
19+
uses: ./.github/workflows/reusable.yml
20+
with:
21+
os: windows-latest
22+
python-version: '3.13'
23+
julia-version: '1'
24+
extra-tests: |
25+
pip install torch
26+
python -m pysr test torch

.github/workflows/CI_mac.yml

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,11 @@ on:
1616

1717
jobs:
1818
test:
19-
runs-on: ${{ matrix.os }}
20-
timeout-minutes: 60
21-
defaults:
22-
run:
23-
shell: bash
24-
strategy:
25-
matrix:
26-
julia-version: ['1']
27-
python-version: ['3.13']
28-
os: [macos-latest]
29-
30-
steps:
31-
- uses: actions/checkout@v4
32-
- name: "Set up Julia"
33-
uses: julia-actions/setup-julia@v2
34-
with:
35-
version: ${{ matrix.julia-version }}
36-
- name: "Cache Julia"
37-
uses: julia-actions/cache@v2
38-
with:
39-
cache-name: ${{ matrix.os }}-test-${{ matrix.julia-version }}-${{ matrix.python-version }}
40-
cache-packages: false
41-
- name: "Set up Python"
42-
uses: actions/setup-python@v5
43-
with:
44-
python-version: ${{ matrix.python-version }}
45-
cache: pip
46-
- name: "Install PySR"
47-
run: |
48-
python -m pip install --upgrade pip
49-
pip install '.[dev]'
50-
python -c 'import pysr'
51-
- name: "Run tests"
52-
run: |
53-
python -m pysr test main,cli,startup
54-
- name: "Run JAX tests"
55-
run: python -m pysr test jax
56-
- name: "Run Torch tests"
57-
run: python -m pysr test torch
19+
uses: ./.github/workflows/reusable.yml
20+
with:
21+
os: macos-latest
22+
python-version: '3.13'
23+
julia-version: '1'
24+
extra-tests: |
25+
python -m pysr test jax
26+
python -m pysr test torch

.github/workflows/reusable.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Reusable PySR Test Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
os:
7+
required: true
8+
type: string
9+
python-version:
10+
required: false
11+
type: string
12+
default: '3.13'
13+
julia-version:
14+
required: false
15+
type: string
16+
default: '1'
17+
run-coverage:
18+
required: false
19+
type: boolean
20+
default: false
21+
extra-tests:
22+
required: false
23+
type: string
24+
default: ''
25+
26+
jobs:
27+
test:
28+
runs-on: ${{ inputs.os }}
29+
timeout-minutes: 60
30+
defaults:
31+
run:
32+
shell: bash
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: "Set up Python"
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: ${{ inputs.python-version }}
41+
cache: pip
42+
43+
44+
- name: "Set up Julia"
45+
uses: julia-actions/setup-julia@v2
46+
with:
47+
version: ${{ inputs.julia-version }}
48+
49+
- name: "Cache Julia"
50+
uses: julia-actions/cache@v2
51+
52+
- name: "Install PySR"
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install '.[dev]'
56+
python -c 'import pysr'
57+
58+
- name: "Assert Julia version"
59+
if: ${{ inputs.julia-version != '1' }}
60+
run: python -c "from pysr import _get_julia_project; print(_get_julia_project().julia_version); assert _get_julia_project().julia_version.startswith('${{ inputs.julia-version }}')"
61+
62+
- name: "Set environment variables"
63+
run: |
64+
echo "PYSR_TEST_JULIA_VERSION=${{ inputs.julia-version }}" >> $GITHUB_ENV
65+
echo "PYSR_TEST_PYTHON_VERSION=${{ inputs.python-version }}" >> $GITHUB_ENV
66+
if [[ "${{ inputs.run-coverage }}" == "true" ]]; then
67+
echo "COVERAGE_PROCESS_START=${{ github.workspace }}/.coveragerc" >> $GITHUB_ENV
68+
fi
69+
70+
- name: "Run tests"
71+
run: |
72+
if [[ "${{ inputs.run-coverage }}" == "true" ]]; then
73+
coverage run -m pysr test main,cli,startup
74+
else
75+
python -m pysr test main,cli,startup
76+
fi
77+
78+
- name: "Run extra tests"
79+
if: ${{ inputs.extra-tests != '' }}
80+
run: ${{ inputs.extra-tests }}
81+
82+
- name: "Generate coverage report"
83+
if: ${{ inputs.run-coverage }}
84+
run: |
85+
coverage combine
86+
coverage report -m
87+
88+
- name: "Upload results to Codecov"
89+
if: ${{ inputs.run-coverage }}
90+
uses: codecov/codecov-action@v5
91+
with:
92+
token: ${{ secrets.CODECOV_TOKEN }}
93+
slug: MilesCranmer/PySR

0 commit comments

Comments
 (0)