Skip to content

Commit a85b078

Browse files
committed
add conda-package-cf workflow
tests against conda-forge packages
1 parent e6b98b3 commit a85b078

1 file changed

Lines changed: 337 additions & 0 deletions

File tree

Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
name: Conda package with conda-forge channel only
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
permissions: read-all
10+
11+
env:
12+
PACKAGE_NAME: mkl_umath
13+
VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); d = j['mkl_umath'][0];"
14+
VER_SCRIPT2: "print('='.join((d[s] for s in ('version', 'build'))))"
15+
16+
jobs:
17+
build_linux:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
22+
steps:
23+
- name: Cancel Previous Runs
24+
uses: styfle/cancel-workflow-action@3155a141048f8f89c06b4cdae32e7853e97536bc # 0.13.0
25+
with:
26+
access_token: ${{ github.token }}
27+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Set pkgs_dirs
32+
run: |
33+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
34+
35+
- name: Cache conda packages
36+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
37+
env:
38+
CACHE_NUMBER: 0 # Increase to reset cache
39+
with:
40+
path: ~/.conda/pkgs
41+
key:
42+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }}
43+
restore-keys: |
44+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
45+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
46+
47+
- name: Add conda to system path
48+
run: echo $CONDA/bin >> $GITHUB_PATH
49+
50+
- name: Install conda-build
51+
run: conda install conda-build
52+
53+
- name: Build conda package
54+
run: |
55+
CHANNELS="-c conda-forge --override-channels"
56+
VERSIONS="--python ${{ matrix.python }}"
57+
TEST="--no-test"
58+
echo "CONDA_BLD=${CONDA}/conda-bld/linux-64" >> $GITHUB_ENV
59+
60+
conda build \
61+
$TEST \
62+
$VERSIONS \
63+
$CHANNELS \
64+
conda-recipe-cf
65+
66+
- name: Upload artifact
67+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
68+
with:
69+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
70+
path: ${{ env.CONDA_BLD }}/${{ env.PACKAGE_NAME }}-*.conda
71+
72+
test_linux:
73+
needs: build_linux
74+
runs-on: ${{ matrix.runner }}
75+
76+
strategy:
77+
matrix:
78+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
79+
experimental: [false]
80+
runner: [ubuntu-latest]
81+
continue-on-error: ${{ matrix.experimental }}
82+
env:
83+
CHANNELS: -c conda-forge --override-channels
84+
85+
steps:
86+
- name: Download artifact
87+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
88+
with:
89+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
90+
- name: Add conda to system path
91+
run: echo $CONDA/bin >> $GITHUB_PATH
92+
- name: Install conda-build
93+
run: conda install conda-build
94+
- name: Create conda channel
95+
run: |
96+
mkdir -p $GITHUB_WORKSPACE/channel/linux-64
97+
mv ${PACKAGE_NAME}-*.conda $GITHUB_WORKSPACE/channel/linux-64
98+
conda index $GITHUB_WORKSPACE/channel
99+
# Test channel
100+
conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels
101+
102+
- name: Collect dependencies
103+
run: |
104+
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
105+
conda create -n test_mkl_umath $PACKAGE_NAME python=${{ matrix.python }} $CHANNELS --only-deps --dry-run > lockfile
106+
- name: Display lockfile
107+
run: cat lockfile
108+
109+
- name: Set pkgs_dirs
110+
run: |
111+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
112+
113+
- name: Cache conda packages
114+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
115+
env:
116+
CACHE_NUMBER: 0 # Increase to reset cache
117+
with:
118+
path: ~/.conda/pkgs
119+
key:
120+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
121+
restore-keys: |
122+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
123+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
124+
125+
- name: Install mkl_umath
126+
run: |
127+
CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}"
128+
conda create -n test_mkl_umath python=${{ matrix.python }} $PACKAGE_NAME pytest $CHANNELS
129+
# Test installed packages
130+
conda list -n test_mkl_umath
131+
132+
- name: Smoke test
133+
run: |
134+
source $CONDA/etc/profile.d/conda.sh
135+
conda activate test_mkl_umath
136+
python -c "import mkl_umath, numpy as np; mkl_umath.use_in_numpy(); np.sin(np.linspace(0, 1, num=10**6));"
137+
138+
- name: Run tests
139+
run: |
140+
source $CONDA/etc/profile.d/conda.sh
141+
conda activate test_mkl_umath
142+
pytest -v --pyargs ${{ env.PACKAGE_NAME }}
143+
144+
build_windows:
145+
runs-on: windows-latest
146+
147+
strategy:
148+
matrix:
149+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
150+
env:
151+
conda-bld: C:\Miniconda\conda-bld\win-64\
152+
steps:
153+
- name: Cancel Previous Runs
154+
uses: styfle/cancel-workflow-action@3155a141048f8f89c06b4cdae32e7853e97536bc # 0.13.0
155+
with:
156+
access_token: ${{ github.token }}
157+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
158+
with:
159+
fetch-depth: 0
160+
161+
- uses: conda-incubator/setup-miniconda@fc2d68f6413eb2d87b895e92f8584b5b94a10167 # v3.3.0
162+
with:
163+
miniforge-variant: Miniforge3
164+
miniforge-version: latest
165+
activate-environment: build
166+
channels: conda-forge
167+
conda-remove-defaults: "true"
168+
python-version: ${{ matrix.python }}
169+
170+
- name: Cache conda packages
171+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
172+
env:
173+
CACHE_NUMBER: 3 # Increase to reset cache
174+
with:
175+
path: /home/runner/conda_pkgs_dir
176+
key:
177+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }}
178+
restore-keys: |
179+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
180+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
181+
182+
- name: Store conda paths as envs
183+
shell: bash -l {0}
184+
run: |
185+
echo "CONDA_BLD=$CONDA/conda-bld/win-64/" | tr "\\\\" '/' >> $GITHUB_ENV
186+
187+
- name: Install conda build
188+
run: |
189+
conda activate
190+
conda install -y conda-build
191+
conda list -n base
192+
193+
- name: Build conda package
194+
run: |
195+
conda activate
196+
conda build --no-test --python ${{ matrix.python }} -c conda-forge --override-channels conda-recipe-cf
197+
198+
- name: Upload artifact
199+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
200+
with:
201+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
202+
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.conda
203+
204+
test_windows:
205+
needs: build_windows
206+
runs-on: ${{ matrix.runner }}
207+
defaults:
208+
run:
209+
shell: cmd /C CALL {0}
210+
strategy:
211+
matrix:
212+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
213+
experimental: [false]
214+
runner: [windows-latest]
215+
continue-on-error: ${{ matrix.experimental }}
216+
env:
217+
workdir: '${{ github.workspace }}'
218+
CHANNELS: -c conda-forge --override-channels
219+
220+
steps:
221+
- name: Download artifact
222+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
223+
with:
224+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
225+
226+
- uses: conda-incubator/setup-miniconda@fc2d68f6413eb2d87b895e92f8584b5b94a10167 # v3.3.0
227+
with:
228+
miniforge-variant: Miniforge3
229+
miniforge-version: latest
230+
activate-environment: mkl_umath_test
231+
channels: conda-forge
232+
conda-remove-defaults: "true"
233+
python-version: ${{ matrix.python }}
234+
235+
- name: Install conda-index
236+
run: |
237+
conda install -n base conda-index
238+
239+
- name: Create conda channel with the artifact bit
240+
shell: cmd /C CALL {0}
241+
run: |
242+
echo ${{ env.workdir }}
243+
mkdir ${{ env.workdir }}\channel
244+
mkdir ${{ env.workdir }}\channel\win-64
245+
move ${{ env.PACKAGE_NAME }}-*.conda ${{ env.workdir }}\channel\win-64
246+
dir ${{ env.workdir }}\channel\win-64
247+
248+
- name: Index the channel
249+
shell: cmd /C CALL {0}
250+
run: |
251+
conda index ${{ env.workdir }}\channel
252+
253+
- name: Dump mkl_umath version info from created channel to STDOUT
254+
shell: cmd /C CALL {0}
255+
run: |
256+
conda search ${{ env.PACKAGE_NAME }} -c ${{ env.workdir }}/channel --override-channels --info --json
257+
258+
- name: Dump mkl_umath version info from created channel into ver.json
259+
shell: cmd /C CALL {0}
260+
run: |
261+
conda search ${{ env.PACKAGE_NAME }} -c ${{ env.workdir }}/channel --override-channels --info --json > ${{ env.workdir }}\ver.json
262+
263+
- name: Output content of workdir
264+
shell: pwsh
265+
run: Get-ChildItem -Path ${{ env.workdir }}
266+
267+
- name: Output content of produced ver.json
268+
shell: pwsh
269+
run: Get-Content -Path ${{ env.workdir }}\ver.json
270+
271+
- name: Collect dependencies
272+
shell: cmd /C CALL {0}
273+
run: |
274+
@ECHO ON
275+
IF NOT EXIST ver.json (
276+
copy /Y ${{ env.workdir }}\ver.json .
277+
)
278+
SET "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%"
279+
FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO (
280+
SET PACKAGE_VERSION=%%F
281+
)
282+
conda install -n mkl_umath_test ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }} --only-deps --dry-run > lockfile
283+
284+
- name: Display lockfile content
285+
shell: pwsh
286+
run: Get-Content -Path .\lockfile
287+
288+
- name: Cache conda packages
289+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
290+
env:
291+
CACHE_NUMBER: 0 # Increase to reset cache
292+
with:
293+
path: /home/runner/conda_pkgs_dir
294+
key:
295+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
296+
restore-keys: |
297+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
298+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
299+
300+
# add intel-openmp as an explicit dependency
301+
# to avoid it being missed when package version is specified exactly
302+
- name: Install mkl_umath
303+
shell: cmd /C CALL {0}
304+
run: |
305+
@ECHO ON
306+
IF NOT EXIST ver.json (
307+
copy /Y ${{ env.workdir }}\ver.json .
308+
)
309+
set "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%"
310+
FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO (
311+
SET PACKAGE_VERSION=%%F
312+
)
313+
SET "TEST_DEPENDENCIES=pytest pytest-cov"
314+
SET "WORKAROUND_DEPENDENCIES=intel-openmp"
315+
SET "DEPENDENCIES=%TEST_DEPENDENCIES% %WORKAROUND_DEPENDENCIES%"
316+
conda install -n mkl_umath_test ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% %DEPENDENCIES% python=${{ matrix.python }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }}
317+
318+
- name: Report content of test environment
319+
shell: cmd /C CALL {0}
320+
run: |
321+
conda activate
322+
echo "Value of CONDA environment variable was: " %CONDA%
323+
echo "Value of CONDA_PREFIX environment variable was: " %CONDA_PREFIX%
324+
conda info && conda list -n mkl_umath_test
325+
326+
- name: Smoke test
327+
shell: cmd /C CALL {0}
328+
run: |
329+
@ECHO ON
330+
conda activate mkl_umath_test
331+
python -c "import mkl_umath, numpy as np; mkl_umath.use_in_numpy(); np.sin(np.linspace(0, 1, num=10**6));"
332+
333+
- name: Run tests
334+
shell: cmd /C CALL {0}
335+
run: |
336+
conda activate mkl_umath_test
337+
python -m pytest -v -s --pyargs ${{ env.PACKAGE_NAME }}

0 commit comments

Comments
 (0)