|
| 1 | +name: PyPI Publish |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + push: |
| 7 | + pull_request: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-n-publish: |
| 12 | + # pull requests are a duplicate of a branch push if within the same repo. |
| 13 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository |
| 14 | + |
| 15 | + name: ${{ matrix.host-os }} / Python ${{ matrix.python-version }} / OpenMP ${{ matrix.openmp }} |
| 16 | + runs-on: ${{ matrix.host-os }} |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + host-os: ["ubuntu-latest", "macos-latest", "windows-latest"] |
| 20 | + python-version: ["3.8", "3.9", "3.10", "3.11"] |
| 21 | + openmp: ["off"] |
| 22 | + fail-fast: false |
| 23 | + |
| 24 | + defaults: |
| 25 | + run: |
| 26 | + shell: bash -l {0} |
| 27 | + |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v3 |
| 30 | + |
| 31 | + - name: Set OpenMP mode |
| 32 | + if: matrix.openmp == 'on' |
| 33 | + run: | |
| 34 | + export MODE="omp" |
| 35 | + echo "MODE=${MODE}" >> $GITHUB_ENV |
| 36 | +
|
| 37 | + - name: Set MacOS Deployment Target |
| 38 | + if: runner.os == 'macOS' |
| 39 | + run: | |
| 40 | + export MACOSX_DEPLOYMENT_TARGET="10.15" |
| 41 | + echo "MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}" >> $GITHUB_ENV |
| 42 | +
|
| 43 | + - uses: conda-incubator/setup-miniconda@v2 |
| 44 | + with: |
| 45 | + activate-environment: testenv |
| 46 | + allow-softlinks: true |
| 47 | + auto-activate-base: false |
| 48 | + auto-update-conda: true |
| 49 | + channel-priority: flexible |
| 50 | + channels: conda-forge |
| 51 | + miniconda-version: "latest" |
| 52 | + python-version: ${{ matrix.python-version }} |
| 53 | + show-channel-urls: true |
| 54 | + use-only-tar-bz2: false |
| 55 | + |
| 56 | + - name: Set up Visual Studio shell |
| 57 | + if: runner.os == 'Windows' |
| 58 | + uses: egor-tensin/vs-shell@v2 |
| 59 | + with: |
| 60 | + arch: x64 |
| 61 | + |
| 62 | + - name: Install build requirements with conda |
| 63 | + if: runner.os != 'Linux' |
| 64 | + run: | |
| 65 | + set -vxeuo pipefail |
| 66 | + conda install -y cmake |
| 67 | +
|
| 68 | + - name: Install OpenMP for macOS with conda |
| 69 | + if: runner.os == 'macOS' && matrix.openmp == 'on' |
| 70 | + run: | |
| 71 | + set -vxeuo pipefail |
| 72 | + conda install -y -c conda-forge llvm-openmp |
| 73 | +
|
| 74 | + # NOTE: This step is not needed for fast tests. |
| 75 | + # - name: Install mpi4py for Unix with conda |
| 76 | + # if: runner.os != 'Windows' |
| 77 | + # run: | |
| 78 | + # set -vxeuo pipefail |
| 79 | + # conda install -y -c conda-forge mpi4py openmpi |
| 80 | + |
| 81 | + - name: Copy over README.md |
| 82 | + run: | |
| 83 | + set -vxeuo pipefail |
| 84 | + cp README.md env/python |
| 85 | +
|
| 86 | + - name: Install cibuildwheel on Linux |
| 87 | + if: runner.os == 'Linux' |
| 88 | + run: | |
| 89 | + set -vxeuo pipefail |
| 90 | + python -m pip install --upgrade pip |
| 91 | + python -m pip install cibuildwheel |
| 92 | + echo "CIBW_BEFORE_ALL=pip install cmake" >> $GITHUB_ENV |
| 93 | + PYTH_VER=${{ matrix.python-version }} |
| 94 | + PYTH_VER=${PYTH_VER//.} |
| 95 | + echo "CIBW_BUILD="cp$PYTH_VER-manylinux*"" >> $GITHUB_ENV |
| 96 | +
|
| 97 | + - name: Build wheel on Linux |
| 98 | + if: runner.os == 'Linux' |
| 99 | + run: | |
| 100 | + set -vxeuo pipefail |
| 101 | + python -VV |
| 102 | + python -m cibuildwheel --output-dir dist env/python |
| 103 | + ls -la dist/* |
| 104 | +
|
| 105 | + - name: Build wheel on Windows/Mac |
| 106 | + if: runner.os != 'Linux' |
| 107 | + run: | |
| 108 | + set -vxeuo pipefail |
| 109 | + cd env/python |
| 110 | + python -VV |
| 111 | + python setup.py bdist_wheel |
| 112 | + ls -la dist/* |
| 113 | + mkdir -p ../../dist |
| 114 | + cp dist/*.whl ../../dist/ |
| 115 | +
|
| 116 | + # - name: Build sdist on Windows (for Python 3.11) |
| 117 | + # if: runner.os == 'Windows' && matrix.python-version == '3.11' |
| 118 | + # run: | |
| 119 | + # set -vxeuo pipefail |
| 120 | + # cd env/python |
| 121 | + # python -VV |
| 122 | + # python setup.py sdist |
| 123 | + # ls -la dist/* |
| 124 | + # mkdir -p ../../dist |
| 125 | + # cp dist/*.tar.gz ../../dist/ |
| 126 | + |
| 127 | + - name: Publish wheels to GitHub artifacts |
| 128 | + uses: actions/upload-artifact@v3 |
| 129 | + with: |
| 130 | + name: wheels |
| 131 | + path: dist/* |
| 132 | + |
| 133 | + - name: Install the package and test requirements |
| 134 | + run: | |
| 135 | + set -vxeuo pipefail |
| 136 | + pip install -v dist/*64.whl |
| 137 | +
|
| 138 | + # Smoke import test: |
| 139 | + python -c "import srwpy; import srwpy.srwlpy" |
| 140 | +
|
| 141 | + python -m pip install -r env/python/requirements-dev.txt |
| 142 | + python -m pip list |
| 143 | +
|
| 144 | + - name: Run fast tests |
| 145 | + run: | |
| 146 | + set -vxeuo pipefail |
| 147 | + cd env/python |
| 148 | + pytest -k fast |
| 149 | +
|
| 150 | + publish-to-pypi: |
| 151 | + # Hints from: |
| 152 | + # - https://github.com/pypa/gh-action-pypi-publish/discussions/28 |
| 153 | + # - https://github.com/Lightning-AI/lightning/blob/master/.github/workflows/release-pypi.yml |
| 154 | + if: github.event_name == 'release' |
| 155 | + name: Publish to PyPI |
| 156 | + needs: build-n-publish |
| 157 | + runs-on: ubuntu-latest |
| 158 | + permissions: |
| 159 | + id-token: write |
| 160 | + |
| 161 | + steps: |
| 162 | + - uses: actions/checkout@v3 |
| 163 | + |
| 164 | + - name: Download wheels from GitHub artifacts |
| 165 | + uses: actions/download-artifact@v3 |
| 166 | + with: |
| 167 | + name: wheels |
| 168 | + path: dist/ |
| 169 | + |
| 170 | + - name: Publish wheels to PyPI |
| 171 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 172 | + with: |
| 173 | + packages-dir: ./dist/ |
0 commit comments