Skip to content

Commit 630f46e

Browse files
author
Vahid Tavanashad
committed
add a new workflow
1 parent 13967b9 commit 630f46e

File tree

2 files changed

+371
-67
lines changed

2 files changed

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

0 commit comments

Comments
 (0)