Skip to content

Commit e957904

Browse files
committed
add osx workflow
1 parent 22dd3d9 commit e957904

1 file changed

Lines changed: 162 additions & 0 deletions

File tree

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
name: Conda package for osx using conda-forge
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
permissions: read-all
10+
11+
env:
12+
PACKAGE_NAME: mkl-service
13+
MODULE_NAME: mkl
14+
TEST_ENV_NAME: test_mkl_service
15+
VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); "
16+
VER_SCRIPT2: "d = j['mkl-service'][0]; print('='.join((d[s] for s in ('version', 'build'))))"
17+
18+
jobs:
19+
build_osx:
20+
runs-on: macos-latest
21+
22+
strategy:
23+
matrix:
24+
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
25+
26+
steps:
27+
- name: Cancel Previous Runs
28+
uses: styfle/cancel-workflow-action@d07a454dad7609a92316b57b23c9ccfd4f59af66 # 0.13.1
29+
with:
30+
access_token: ${{ github.token }}
31+
32+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
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/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
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: Store conda paths as envs
59+
shell: bash -el {0}
60+
run: |
61+
echo "CONDA_BLD=$CONDA/conda-bld/osx-arm64/" >> "$GITHUB_ENV"
62+
echo "WHEELS_OUTPUT_FOLDER=$GITHUB_WORKSPACE/" >> "$GITHUB_ENV"
63+
64+
- name: Build conda package
65+
run: |
66+
CHANNELS=(-c conda-forge -c conda-forge/label/python_rc --override-channels)
67+
VERSIONS=(--python "${{ matrix.python }}")
68+
TEST=(--no-test)
69+
70+
conda build \
71+
"${TEST[@]}" \
72+
"${VERSIONS[@]}" \
73+
"${CHANNELS[@]}" \
74+
conda-recipe-cf
75+
76+
- name: Upload artifact
77+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
78+
with:
79+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
80+
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.conda
81+
82+
- name: Upload wheels artifact
83+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
84+
with:
85+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Wheels Python ${{ matrix.python }}
86+
path: ${{ env.WHEELS_OUTPUT_FOLDER }}mkl_service-*.whl
87+
88+
test_osx:
89+
needs: build_osx
90+
runs-on: ${{ matrix.runner }}
91+
92+
strategy:
93+
matrix:
94+
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
95+
experimental: [false]
96+
runner: [macos-latest]
97+
continue-on-error: ${{ matrix.experimental }}
98+
env:
99+
CHANNELS: -c conda-forge -c conda-forge/label/python_rc --override-channels
100+
101+
steps:
102+
- name: Download artifact
103+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
104+
with:
105+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
106+
107+
- name: Add conda to system path
108+
run: echo "$CONDA/bin" >> "$GITHUB_PATH"
109+
110+
- name: Install conda-build
111+
run: conda install conda-build
112+
113+
- name: Create conda channel
114+
run: |
115+
mkdir -p "$GITHUB_WORKSPACE/channel/osx-arm64"
116+
conda index "$GITHUB_WORKSPACE/channel" || exit 1
117+
mv "${PACKAGE_NAME}"-*.conda "$GITHUB_WORKSPACE/channel/osx-arm64" || exit 1
118+
conda index "$GITHUB_WORKSPACE/channel" || exit 1
119+
# Test channel
120+
conda search "$PACKAGE_NAME" -c "$GITHUB_WORKSPACE/channel" --override-channels --info --json > "$GITHUB_WORKSPACE/ver.json"
121+
cat ver.json
122+
123+
- name: Collect dependencies
124+
run: |
125+
. "$CONDA/etc/profile.d/conda.sh"
126+
CHANNELS=(-c "$GITHUB_WORKSPACE/channel" -c conda-forge -c conda-forge/label/python_rc --override-channels)
127+
PACKAGE_VERSION="$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}")"
128+
export PACKAGE_VERSION
129+
conda create -n "${{ env.TEST_ENV_NAME }}" "$PACKAGE_NAME=$PACKAGE_VERSION" "python=${{ matrix.python }}" "${CHANNELS[@]}" --only-deps --dry-run > lockfile
130+
cat lockfile
131+
132+
- name: Set pkgs_dirs
133+
run: |
134+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
135+
136+
- name: Cache conda packages
137+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
138+
env:
139+
CACHE_NUMBER: 0 # Increase to reset cache
140+
with:
141+
path: ~/.conda/pkgs
142+
key:
143+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
144+
restore-keys: |
145+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
146+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
147+
148+
- name: Install mkl-service
149+
run: |
150+
. "$CONDA/etc/profile.d/conda.sh"
151+
CHANNELS=(-c "$GITHUB_WORKSPACE/channel" -c conda-forge -c conda-forge/label/python_rc --override-channels)
152+
PACKAGE_VERSION="$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}")"
153+
export PACKAGE_VERSION
154+
conda create -n "${{ env.TEST_ENV_NAME }}" "$PACKAGE_NAME=$PACKAGE_VERSION" pytest "python=${{ matrix.python }}" "${CHANNELS[@]}"
155+
# Test installed packages
156+
conda list
157+
158+
- name: Run tests
159+
run: |
160+
. "$CONDA/etc/profile.d/conda.sh"
161+
conda activate ${{ env.TEST_ENV_NAME }}
162+
pytest -vv --pyargs ${{ env.MODULE_NAME }}

0 commit comments

Comments
 (0)