Update GitHub actions #245
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Conda package | |
| on: | |
| pull_request: | |
| push: | |
| branches: [master] | |
| permissions: read-all | |
| env: | |
| PACKAGE_NAME: mkl_random | |
| MODULE_NAME: mkl_random | |
| TEST_ENV_NAME: test_mkl_random | |
| VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); " | |
| VER_SCRIPT2: "d = j['mkl_random'][0]; print('='.join((d[s] for s in ('version', 'build'))))" | |
| jobs: | |
| build_linux: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python: ["3.10", "3.11", "3.12", "3.13"] # no python 3.14 support by numpy-base is relased | |
| steps: | |
| - name: Cancel Previous Runs | |
| uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1 | |
| with: | |
| access_token: ${{ github.token }} | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set pkgs_dirs | |
| run: | | |
| echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc | |
| - name: Cache conda packages | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| env: | |
| CACHE_NUMBER: 0 # Increase to reset cache | |
| with: | |
| path: ~/.conda/pkgs | |
| key: | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- | |
| - name: Add conda to system path | |
| run: echo $CONDA/bin >> $GITHUB_PATH | |
| - name: Install conda-build | |
| run: conda install conda-build | |
| - name: Store conda paths as envs | |
| shell: bash -el {0} | |
| run: | | |
| echo "CONDA_BLD=/usr/share/miniconda/conda-bld/linux-64/" >> $GITHUB_ENV | |
| - name: Build conda package | |
| run: | | |
| CHANNELS="-c https://software.repos.intel.com/python/conda -c conda-forge --override-channels" | |
| VERSIONS="--python ${{ matrix.python }}" | |
| TEST="--no-test" | |
| conda build \ | |
| $TEST \ | |
| $VERSIONS \ | |
| $CHANNELS \ | |
| conda-recipe | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} | |
| path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.conda | |
| build_windows: | |
| runs-on: windows-latest | |
| strategy: | |
| matrix: | |
| python: ["3.10", "3.11", "3.12", "3.13"] # no python 3.14 support by numpy-base is relased | |
| steps: | |
| - name: Cancel Previous Runs | |
| uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # 0.12.1 | |
| with: | |
| access_token: ${{ github.token }} | |
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 0 | |
| - uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0 | |
| with: | |
| miniforge-version: latest | |
| use-mamba: 'true' | |
| conda-remove-defaults: 'true' | |
| activate-environment: 'build' | |
| python-version: '3.13' # no python 3.14 support by conda-build | |
| - name: Cache conda packages | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| env: | |
| CACHE_NUMBER: 3 # Increase to reset cache | |
| with: | |
| path: /home/runner/conda_pkgs_dir | |
| key: | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('**/meta.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- | |
| - name: Install conda-build | |
| run: conda install conda-build | |
| - name: Store conda paths as envs | |
| shell: bash -el {0} | |
| run: | | |
| echo "CONDA_BLD=$CONDA_PREFIX\\conda-bld\\win-64\\" >> $GITHUB_ENV | |
| - name: Build conda package | |
| run: conda build --no-test --python ${{ matrix.python }} -c https://software.repos.intel.com/python/conda -c conda-forge --override-channels conda-recipe | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 | |
| with: | |
| name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} | |
| path: ${{ env.CONDA_BLD }}${{ env.PACKAGE_NAME }}-*.conda | |
| test_linux: | |
| needs: build_linux | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - python: "3.10" | |
| numpy: "2.2" | |
| - python: "3.11" | |
| numpy: "2.3" | |
| - python: "3.12" | |
| numpy: "2.3" | |
| - python: "3.13" | |
| numpy: "2.3" | |
| env: | |
| CHANNELS: -c https://software.repos.intel.com/python/conda -c conda-forge --override-channels | |
| steps: | |
| - name: Download artifact | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} | |
| - name: Add conda to system path | |
| run: echo $CONDA/bin >> $GITHUB_PATH | |
| - name: Install conda-build | |
| run: conda install conda-build | |
| - name: Create conda channel | |
| run: | | |
| mkdir -p $GITHUB_WORKSPACE/channel/linux-64 | |
| conda index $GITHUB_WORKSPACE/channel || exit 1 | |
| mv ${PACKAGE_NAME}-*.conda $GITHUB_WORKSPACE/channel/linux-64 || exit 1 | |
| conda index $GITHUB_WORKSPACE/channel || exit 1 | |
| # Test channel | |
| conda search $PACKAGE_NAME -c $GITHUB_WORKSPACE/channel --override-channels --info --json > $GITHUB_WORKSPACE/ver.json | |
| cat ver.json | |
| - name: Collect dependencies | |
| run: | | |
| . $CONDA/etc/profile.d/conda.sh | |
| CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}" | |
| export PACKAGE_VERSION=$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}") | |
| conda create -n ${{ env.TEST_ENV_NAME }} $PACKAGE_NAME=${PACKAGE_VERSION} python=${{ matrix.python }} numpy=${{ matrix.numpy }} $CHANNELS --only-deps --dry-run > lockfile | |
| cat lockfile | |
| - name: Set pkgs_dirs | |
| run: | | |
| echo "pkgs_dirs: [~/.conda/pkgs]" >> ~/.condarc | |
| - name: Cache conda packages | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| env: | |
| CACHE_NUMBER: 0 # Increase to reset cache | |
| with: | |
| path: ~/.conda/pkgs | |
| key: | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }} | |
| restore-keys: | | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- | |
| - name: Install mkl_random | |
| run: | | |
| . $CONDA/etc/profile.d/conda.sh | |
| CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}" | |
| export PACKAGE_VERSION=$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}") | |
| conda create -n ${{ env.TEST_ENV_NAME }} $PACKAGE_NAME=${PACKAGE_VERSION} pytest python=${{ matrix.python }} numpy=${{ matrix.numpy }} $CHANNELS | |
| conda activate ${{ env.TEST_ENV_NAME }} | |
| # Test installed packages | |
| conda list | |
| - name: Run tests | |
| run: | | |
| . $CONDA/etc/profile.d/conda.sh | |
| conda activate ${{ env.TEST_ENV_NAME }} | |
| pytest -vv --pyargs ${{ env.MODULE_NAME }} | |
| test_windows: | |
| needs: build_windows | |
| runs-on: windows-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - python: "3.10" | |
| numpy: "2.2" | |
| - python: "3.11" | |
| numpy: "2.3" | |
| - python: "3.12" | |
| numpy: "2.3" | |
| - python: "3.13" | |
| numpy: "2.3" | |
| env: | |
| CHANNELS: -c https://software.repos.intel.com/python/conda -c conda-forge --override-channels | |
| steps: | |
| - name: Download artifact | |
| uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 | |
| with: | |
| name: ${{ env.PACKAGE_NAME }} ${{ runner.os }} Python ${{ matrix.python }} | |
| - uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f # v3.2.0 | |
| with: | |
| miniforge-version: latest | |
| use-mamba: 'true' | |
| conda-remove-defaults: 'true' | |
| activate-environment: 'test' | |
| python-version: '3.13' # no python 3.14 support by conda-index | |
| - name: Install conda-index | |
| run: conda install conda-index | |
| - name: Create conda channel | |
| run: | | |
| mkdir ${{ env.GITHUB_WORKSPACE }}\channel\win-64 | |
| move ${{ env.PACKAGE_NAME }}-*.conda ${{ env.GITHUB_WORKSPACE }}\channel\win-64 | |
| python -m conda_index ${{ env.GITHUB_WORKSPACE }}/channel | |
| # Test channel | |
| conda search ${{ env.PACKAGE_NAME }} -c ${{ env.GITHUB_WORKSPACE }}/channel --override-channels --info --json > ${{ env.GITHUB_WORKSPACE }}\ver.json | |
| more ${{ env.GITHUB_WORKSPACE }}\ver.json | |
| - name: Collect dependencies | |
| shell: cmd | |
| run: | | |
| @ECHO ON | |
| copy /Y ${{ env.GITHUB_WORKSPACE }}\ver.json . | |
| set "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%" | |
| FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO ( | |
| SET PACKAGE_VERSION=%%F | |
| ) | |
| conda create -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python }} numpy=${{ matrix.numpy }} -c ${{ env.GITHUB_WORKSPACE }}/channel ${{ env.CHANNELS }} --only-deps --dry-run > lockfile | |
| more lockfile | |
| - name: Cache conda packages | |
| uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 | |
| env: | |
| CACHE_NUMBER: 3 # Increase to reset cache | |
| with: | |
| path: /home/runner/conda_pkgs_dir | |
| key: | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}-${{hashFiles('lockfile') }} | |
| restore-keys: | | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- | |
| ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- | |
| # add intel-openmp as an explicit dependency | |
| # to avoid it being missed when package version is specified exactly | |
| - name: Install mkl_random | |
| shell: cmd | |
| run: | | |
| @ECHO ON | |
| copy /Y ${{ env.GITHUB_WORKSPACE }}\ver.json . | |
| set "SCRIPT=%VER_SCRIPT1% %VER_SCRIPT2%" | |
| FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO ( | |
| SET PACKAGE_VERSION=%%F | |
| ) | |
| SET "WORKAROUND_DEPENDENCIES=intel-openmp" | |
| conda create -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% %WORKAROUND_DEPENDENCIES% pytest python=${{ matrix.python }} numpy=${{ matrix.numpy }} -c ${{ env.GITHUB_WORKSPACE }}/channel ${{ env.CHANNELS }} | |
| conda activate -n ${{ env.TEST_ENV_NAME }} | |
| # Test installed packages | |
| conda list | |
| - name: Run tests | |
| run: | | |
| conda activate -n ${{ env.TEST_ENV_NAME }} | |
| pytest -v --pyargs ${{ env.MODULE_NAME }} |