Skip to content

Commit aef7fb9

Browse files
authored
Merge pull request #1409 from IntelPython/feature/cache-conda-package-wf
2 parents 53bb704 + d0e21f1 commit aef7fb9

29 files changed

+468
-2582
lines changed

.flake8

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ exclude =
1919
.git,
2020
__pycache__,
2121
_version.py,
22-
versioneer.py,
2322
lowerer.py,
2423
parfor.py
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: "Setup Miniconda"
2+
description: "Wrapper around conda-incubator/setup-miniconda to cache lock files."
3+
inputs:
4+
python-version:
5+
description: "Refer conda-incubator/setup-miniconda."
6+
required: false
7+
default: ""
8+
activate-environment:
9+
description: "Refer conda-incubator/setup-miniconda."
10+
required: false
11+
default: "test"
12+
environment-file:
13+
description: "Refer conda-incubator/setup-miniconda."
14+
required: false
15+
default: ""
16+
channels:
17+
description: "Refer conda-incubator/setup-miniconda."
18+
required: false
19+
default: ""
20+
channel-priority:
21+
description: "Refer conda-incubator/setup-miniconda, default changed to 'disabled'."
22+
required: false
23+
default: "disabled"
24+
run-post:
25+
description: "Refer conda-incubator/setup-miniconda, default changed to 'false'."
26+
required: false
27+
default: "false"
28+
cache-number:
29+
description: "Increase this value to reset cache if env file has not changed."
30+
required: false
31+
default: "-3"
32+
dependencies:
33+
description: "List of packages separated by ; to use in environment file."
34+
required: false
35+
default: ""
36+
runs:
37+
using: "composite"
38+
steps:
39+
- name: Get Date
40+
id: get-date
41+
shell: bash
42+
run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT
43+
44+
- name: Generate channels hash
45+
id: channels-hash
46+
shell: bash
47+
run: echo "hash=$(echo '${{inputs.channels}}' | sha1sum | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
48+
49+
- name: Write dependencies
50+
if: inputs.dependencies != ''
51+
shell: bash
52+
run: |
53+
printf "dependencies:;${{inputs.dependencies}}" | sed 's/;/\n - /g' > \
54+
${{inputs.environment-file}}
55+
56+
- name: Cache Conda env
57+
uses: actions/cache@v4
58+
with:
59+
# TODO: use channels as part of the key
60+
path: ${{inputs.environment-file}}.lock
61+
key: setup-miniconda-${{ runner.os }}-${{ runner.arch }}-${{
62+
inputs.python-version }}-${{
63+
steps.get-date.outputs.today }}-${{
64+
steps.channels-hash.hash }}-${{
65+
hashFiles(inputs.environment-file) }}-${{
66+
inputs.cache-number }}
67+
id: cache
68+
69+
- name: Setup miniconda
70+
if: steps.cache.outputs.cache-hit != 'true'
71+
uses: conda-incubator/setup-miniconda@v3
72+
with:
73+
python-version: ${{ inputs.python-version }}
74+
activate-environment: ${{inputs.activate-environment}}
75+
channels: ${{ inputs.channels }}
76+
channel-priority: ${{ inputs.channel-priority }}
77+
environment-file: ${{ inputs.environment-file }}
78+
run-post: ${{ inputs.run-post }}
79+
80+
- name: Save environment resolution
81+
if: steps.cache.outputs.cache-hit != 'true'
82+
shell: bash -l {0}
83+
run: conda list --explicit > ${{inputs.activate-environment}}.lock
84+
85+
- name: Setup conda
86+
if: steps.cache.outputs.cache-hit == 'true'
87+
uses: conda-incubator/setup-miniconda@v3
88+
with:
89+
activate-environment: ${{inputs.activate-environment}}
90+
channels: ${{ inputs.channels }}
91+
environment-file: ${{inputs.activate-environment}}.lock
92+
run-post: ${{ inputs.run-post }}
93+
94+
- name: Disable defaults
95+
shell: bash -l {0}
96+
run: conda config --remove channels defaults

.github/workflows/conda-package.yml

Lines changed: 50 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,27 @@ jobs:
4949
- name: Checkout ${{ env.PACKAGE_NAME }} repo
5050
uses: actions/checkout@v4
5151
with:
52+
# We need tags to build proper version
5253
fetch-depth: 0
5354

5455
- name: Setup miniconda
55-
uses: conda-incubator/setup-miniconda@v3
56+
uses: ./.github/actions/setup-miniconda
5657
with:
57-
python-version: ${{ inputs.python-version }}
58-
miniforge-variant: Mambaforge
59-
miniforge-version: latest
58+
python-version: ${{ matrix.python }}
6059
activate-environment: "build"
6160
channels: ${{ env.CHANNELS }}
6261
channel-priority: "disabled"
63-
run-post: false
64-
65-
- name: Disable defautls
66-
run: conda config --remove channels defaults
62+
dependencies: "conda-build"
63+
environment-file: environment/conda-package-build.yml
6764

6865
- name: Store conda paths as envs
6966
run: |
7067
echo "CONDA_BLD=$CONDA_PREFIX/conda-bld/${{ runner.os == 'Linux' && 'linux' || 'win' }}-64/" | tr "\\" '/' >> $GITHUB_ENV
7168
echo "WHEELS_OUTPUT_FOLDER=$GITHUB_WORKSPACE${{ runner.os == 'Linux' && '/' || '\\' }}" >> $GITHUB_ENV
7269
echo "WHEELS_NAME=$PACKAGE_NAME" | tr "-" "_" >> $GITHUB_ENV
7370
74-
# boa is an extention to conda so we can use mamba resolver in conda build
75-
- name: Install conda-build
76-
run: mamba install boa
77-
7871
- name: Build conda package
79-
run: conda mambabuild --no-test --python ${{ matrix.python }} conda-recipe
72+
run: conda build --no-test --python ${{ matrix.python }} conda-recipe
8073

8174
- name: Upload artifact
8275
uses: actions/upload-artifact@v4
@@ -107,28 +100,32 @@ jobs:
107100
python: ['3.9', '3.10', '3.11']
108101
os: [ubuntu-20.04, ubuntu-latest, windows-latest]
109102
experimental: [false]
110-
use_mlir: [false]
111103
scope: ['tests', 'examples', 'gdb']
112104
exclude:
113105
- os: windows-latest
114106
scope: 'gdb'
115107

116-
continue-on-error: ${{ matrix.experimental || matrix.use_mlir }}
108+
continue-on-error: ${{ matrix.experimental }}
117109

118110
steps:
111+
- name: Checkout setup config
112+
uses: actions/checkout@v4
113+
with:
114+
sparse-checkout: |
115+
.github/actions
116+
environment
117+
pyproject.toml
118+
sparse-checkout-cone-mode: false
119+
119120
- name: Setup miniconda
120-
uses: conda-incubator/setup-miniconda@v3
121+
uses: ./.github/actions/setup-miniconda
121122
with:
122123
python-version: ${{ matrix.python }}
123-
miniforge-variant: Mambaforge
124-
miniforge-version: latest
125124
activate-environment: "test"
126125
channels: ${{ env.CHANNELS }}
127126
channel-priority: "disabled"
128-
run-post: false
129-
130-
- name: Disable defautls
131-
run: conda config --remove channels defaults
127+
dependencies: "conda-index;pytest-cov;conda-tree"
128+
environment-file: environment/conda-package-test.yml
132129

133130
- name: Store conda paths as envs
134131
shell: bash -l {0}
@@ -153,10 +150,6 @@ jobs:
153150
mkdir -p ${EXTRACTED_PKG_PATH}
154151
tar -xvf ${PKG_PATH_IN_CHANNEL}${PACKAGE_NAME}-*.tar.bz2 -C ${EXTRACTED_PKG_PATH} --force-local
155152
156-
- name: Install conda build
157-
run: |
158-
mamba install conda-build conda-index
159-
160153
- name: Create conda channel
161154
# Note conda index (instead of python -m conda_index) may find legacy
162155
# conda-build index.
@@ -165,7 +158,7 @@ jobs:
165158
166159
- name: Test conda channel
167160
run: |
168-
mamba search ${{ env.PACKAGE_NAME }} -c ${{ env.CHANNEL_PATH }} --override-channels --info --json > ${{ env.VER_JSON_PATH }}
161+
conda search ${{ env.PACKAGE_NAME }} -c ${{ env.CHANNEL_PATH }} --override-channels --info --json > ${{ env.VER_JSON_PATH }}
169162
cat ${{ env.VER_JSON_PATH }}
170163
171164
- name: Collect dependencies
@@ -176,14 +169,8 @@ jobs:
176169
177170
# We want to make sure that all dependecies install automatically.
178171
# intel::intel-opencl-rt is needed for set-intel-ocl-icd-registry.ps1
179-
# TODO: remove pytest dependency directly, once resolved:
180-
# https://github.com/pytest-dev/pytest/issues/12036
181-
- name: Install builded package
182-
run: mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} intel::intel-opencl-rt pytest-cov pytest=8.0.1 conda-tree -c ${{ env.CHANNEL_PATH }}
183-
184-
- name: Install numba-mlir
185-
if: matrix.use_mlir
186-
run: mamba install numba-mlir -c dppy/label/dev -c conda-forge -c intel
172+
- name: Install built package
173+
run: conda install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} intel::intel-opencl-rt -c ${{ env.CHANNEL_PATH }}
187174

188175
- name: Setup OpenCL CPU device
189176
if: runner.os == 'Windows'
@@ -192,13 +179,6 @@ jobs:
192179
$script_path="$env:CONDA_PREFIX\Scripts\set-intel-ocl-icd-registry.ps1"
193180
&$script_path
194181
195-
- name: Checkout setup config
196-
uses: actions/checkout@v4
197-
with:
198-
sparse-checkout: |
199-
pyproject.toml
200-
sparse-checkout-cone-mode: false
201-
202182
- name: List installed packages
203183
run: conda list
204184

@@ -210,9 +190,7 @@ jobs:
210190
run: conda-tree depends -t numba-dpex
211191

212192
- name: Smoke test
213-
env:
214-
NUMBA_DPEX_USE_MLIR: ${{ matrix.use_mlir && '1' || '0' }}
215-
run: python -c "import dpnp, dpctl, numba_dpex; dpctl.lsplatform()"
193+
run: python -c "import dpnp, dpctl, numba_dpex; dpctl.lsplatform(verbosity=2)"
216194

217195
- name: Smoke test - test import with no default device
218196
env:
@@ -221,8 +199,6 @@ jobs:
221199

222200
- name: Run tests
223201
if: ${{ matrix.scope == 'tests' }}
224-
env:
225-
NUMBA_DPEX_USE_MLIR: ${{ matrix.use_mlir && '1' || '0' }}
226202
run: |
227203
pytest -q -ra --disable-warnings --pyargs ${{ env.MODULE_NAME }} -vv -k "not test_1d_strided_dpnp_array_in_kernel[2]"
228204
@@ -232,7 +208,6 @@ jobs:
232208
# and are possibly due to some driver/opencl compiler bug.
233209
if: ${{ matrix.scope == 'tests' }}
234210
env:
235-
NUMBA_DPEX_USE_MLIR: ${{ matrix.use_mlir && '1' || '0' }}
236211
# Disabling device driver optimization to prevent catching bugs
237212
# from driver compiler.
238213
ONEAPI_DEVICE_SELECTOR: "opencl:cpu"
@@ -267,10 +242,10 @@ jobs:
267242
export ONEAPI_ROOT=/tmp/gdb
268243
./${{ env.GDB_INSTALLER }} -a -s --eula accept --install-dir $ONEAPI_ROOT
269244
source $ONEAPI_ROOT/debugger/latest/env/vars.sh
270-
# We match only major and minor version because latest gdb is not
271-
# often available.
272-
gdb_version=$(echo "$GDB_INSTALLER" | grep -oP '\d+\.\d+' | head -n 1)
273-
icpx_version=$(conda list dpcpp-cpp-rt | tail -n 1 | awk '{print $2}' | grep -oP '\d+\.\d+')
245+
# We match only major version because latest gdb is not often
246+
# available.
247+
gdb_version=$(echo "$GDB_INSTALLER" | grep -oP '\d+' | head -n 1)
248+
icpx_version=$(conda list dpcpp-cpp-rt | tail -n 1 | awk '{print $2}' | grep -oP '\d+' | head -n 1)
274249
if [ "$gdb_version" != "$icpx_version" ]; then
275250
echo "Error: GDB version ($gdb_version) does not match icpx version ($icpx_version)"
276251
exit 1
@@ -297,6 +272,13 @@ jobs:
297272
continue-on-error: false
298273

299274
steps:
275+
- name: Checkout setup config
276+
uses: actions/checkout@v4
277+
with:
278+
sparse-checkout: |
279+
.github/actions
280+
environment
281+
300282
- name: Download artifact
301283
uses: actions/download-artifact@v4
302284
with:
@@ -308,18 +290,13 @@ jobs:
308290
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Wheels Python ${{ matrix.python }}
309291

310292
- name: Setup miniconda
311-
uses: conda-incubator/setup-miniconda@v3
293+
uses: ./.github/actions/setup-miniconda
312294
with:
313295
python-version: ${{ matrix.python }}
314-
miniforge-variant: Mambaforge
315-
miniforge-version: latest
316296
activate-environment: "anaconda"
317-
channels: ${{ env.CHANNELS }}
318297
channel-priority: "disabled"
319-
run-post: false
320-
321-
- name: Install anaconda-client
322-
run: mamba install anaconda-client
298+
dependencies: "anaconda-client"
299+
environment-file: environment/conda-package-anaconda.yml
323300

324301
- name: Upload
325302
run: anaconda --token ${{ secrets.ANACONDA_TOKEN }} upload --user dppy --label dev ${{ env.PACKAGE_NAME }}-*.tar.bz2
@@ -342,21 +319,26 @@ jobs:
342319
run:
343320
shell: bash -el {0}
344321
steps:
345-
- uses: conda-incubator/setup-miniconda@v3
322+
- name: Checkout setup config
323+
uses: actions/checkout@v4
346324
with:
347-
run-post: false
348-
channel-priority: "disabled"
349-
channels: conda-forge
350-
python-version: '3.11'
325+
sparse-checkout: |
326+
.github/actions
327+
environment
351328
352-
- name: Install anaconda-client
353-
run: conda install anaconda-client
329+
- name: Setup miniconda
330+
uses: ./.github/actions/setup-miniconda
331+
with:
332+
python-version: '3.11'
333+
activate-environment: "anaconda"
334+
channel-priority: "disabled"
335+
dependencies: "anaconda-client"
336+
environment-file: environment/conda-package-anaconda.yml
354337

355338
- name: Checkout repo
356339
uses: actions/checkout@v4
357340
with:
358341
repository: IntelPython/devops-tools
359-
fetch-depth: 0
360342

361343
- name: Cleanup old packages
362344
run: |

0 commit comments

Comments
 (0)