Skip to content

Commit 658f656

Browse files
committed
add osx workflow
1 parent 22dd3d9 commit 658f656

1 file changed

Lines changed: 177 additions & 0 deletions

File tree

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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+
- uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1
37+
with:
38+
miniforge-version: latest
39+
activate-environment: build
40+
channels: conda-forge
41+
python-version: ${{ matrix.python }}
42+
43+
- name: Set pkgs_dirs
44+
run: |
45+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
46+
47+
- name: Cache conda packages
48+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
49+
env:
50+
CACHE_NUMBER: 0 # Increase to reset cache
51+
with:
52+
path: ~/.conda/pkgs
53+
key:
54+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }}
55+
restore-keys: |
56+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
57+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
58+
59+
- name: Install conda-build
60+
shell: bash -el {0}
61+
run: |
62+
conda install -n base -y conda-build
63+
conda list -n base
64+
65+
- name: Store conda paths as envs
66+
shell: bash -el {0}
67+
run: |
68+
CONDA_SUBDIR=$(conda info --json | python -c "import json,sys; print(json.load(sys.stdin)['subdir'])")
69+
echo "CONDA_BLD=$CONDA/conda-bld/$CONDA_SUBDIR/" >> "$GITHUB_ENV"
70+
echo "WHEELS_OUTPUT_FOLDER=$GITHUB_WORKSPACE/" >> "$GITHUB_ENV"
71+
72+
- name: Build conda package
73+
shell: bash -el {0}
74+
run: |
75+
CHANNELS=(-c conda-forge -c conda-forge/label/python_rc --override-channels)
76+
VERSIONS=(--python "${{ matrix.python }}")
77+
TEST=(--no-test)
78+
79+
conda build \
80+
"${TEST[@]}" \
81+
"${VERSIONS[@]}" \
82+
"${CHANNELS[@]}" \
83+
conda-recipe-cf
84+
85+
- name: Upload artifact
86+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
87+
with:
88+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
89+
path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.conda
90+
91+
- name: Upload wheels artifact
92+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
93+
with:
94+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Wheels Python ${{ matrix.python }}
95+
path: ${{ env.WHEELS_OUTPUT_FOLDER }}mkl_service-*.whl
96+
97+
test_osx:
98+
needs: build_osx
99+
runs-on: ${{ matrix.runner }}
100+
101+
strategy:
102+
matrix:
103+
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
104+
experimental: [false]
105+
runner: [macos-latest]
106+
continue-on-error: ${{ matrix.experimental }}
107+
env:
108+
CHANNELS: -c conda-forge -c conda-forge/label/python_rc --override-channels
109+
110+
steps:
111+
- name: Download artifact
112+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
113+
with:
114+
name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }}
115+
116+
- uses: conda-incubator/setup-miniconda@8ee1f361103df19b6f8c8655fd3967a8ecb162d5 # v4.0.1
117+
with:
118+
miniforge-version: latest
119+
channels: conda-forge
120+
activate-environment: base
121+
122+
- name: Install conda-index
123+
shell: bash -el {0}
124+
run: conda install -n base -y conda-index
125+
126+
- name: Create conda channel
127+
shell: bash -el {0}
128+
run: |
129+
CONDA_SUBDIR=$(conda info --json | python -c "import json,sys; print(json.load(sys.stdin)['subdir'])")
130+
mkdir -p "$GITHUB_WORKSPACE/channel/$CONDA_SUBDIR"
131+
conda index "$GITHUB_WORKSPACE/channel" || exit 1
132+
mv "${PACKAGE_NAME}"-*.conda "$GITHUB_WORKSPACE/channel/$CONDA_SUBDIR" || exit 1
133+
conda index "$GITHUB_WORKSPACE/channel" || exit 1
134+
# Test channel
135+
conda search "$PACKAGE_NAME" -c "$GITHUB_WORKSPACE/channel" --override-channels --info --json > "$GITHUB_WORKSPACE/ver.json"
136+
cat ver.json
137+
138+
- name: Collect dependencies
139+
run: |
140+
. "$CONDA/etc/profile.d/conda.sh"
141+
CHANNELS=(-c "$GITHUB_WORKSPACE/channel" -c conda-forge -c conda-forge/label/python_rc --override-channels)
142+
PACKAGE_VERSION="$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}")"
143+
export PACKAGE_VERSION
144+
conda create -n "${{ env.TEST_ENV_NAME }}" "$PACKAGE_NAME=$PACKAGE_VERSION" "python=${{ matrix.python }}" "${CHANNELS[@]}" --only-deps --dry-run > lockfile
145+
cat lockfile
146+
147+
- name: Set pkgs_dirs
148+
run: |
149+
echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc
150+
151+
- name: Cache conda packages
152+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
153+
env:
154+
CACHE_NUMBER: 0 # Increase to reset cache
155+
with:
156+
path: ~/.conda/pkgs
157+
key:
158+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }}
159+
restore-keys: |
160+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-
161+
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-
162+
163+
- name: Install mkl-service
164+
run: |
165+
. "$CONDA/etc/profile.d/conda.sh"
166+
CHANNELS=(-c "$GITHUB_WORKSPACE/channel" -c conda-forge -c conda-forge/label/python_rc --override-channels)
167+
PACKAGE_VERSION="$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}")"
168+
export PACKAGE_VERSION
169+
conda create -n "${{ env.TEST_ENV_NAME }}" "$PACKAGE_NAME=$PACKAGE_VERSION" pytest "python=${{ matrix.python }}" "${CHANNELS[@]}"
170+
# Test installed packages
171+
conda list
172+
173+
- name: Run tests
174+
run: |
175+
. "$CONDA/etc/profile.d/conda.sh"
176+
conda activate ${{ env.TEST_ENV_NAME }}
177+
pytest -vv --pyargs ${{ env.MODULE_NAME }}

0 commit comments

Comments
 (0)