|
| 1 | +name: Wheels |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + release: |
| 10 | + types: |
| 11 | + - published |
| 12 | + |
| 13 | +jobs: |
| 14 | + |
| 15 | + build_sdist: |
| 16 | + name: Build SDist |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v2 |
| 20 | + with: |
| 21 | + submodules: true |
| 22 | + |
| 23 | + - name: Build SDist |
| 24 | + run: pipx run build --sdist |
| 25 | + |
| 26 | + - name: Check metadata |
| 27 | + run: pipx run twine check dist/* |
| 28 | + |
| 29 | + - uses: actions/upload-artifact@v2 |
| 30 | + with: |
| 31 | + path: dist/*.tar.gz |
| 32 | + |
| 33 | + |
| 34 | + build_wheels: |
| 35 | + name: Wheels for ${{ matrix.os }}/${{ matrix.python-version }} |
| 36 | + runs-on: ${{ matrix.os }} |
| 37 | + strategy: |
| 38 | + fail-fast: false |
| 39 | + matrix: |
| 40 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 41 | + python-version: ["3.6", "3.7", "3.8", "3.9"] |
| 42 | + |
| 43 | + env: |
| 44 | + GEANT4_GIT_TAG: v10.7.1 |
| 45 | + GEANT4_SOURCE_DIR: geant4_source |
| 46 | + GEANT4_BUILD_DIR: geant4_build |
| 47 | + GEANT4_INSTALL_DIR: geant4_install |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: Cache Geant4 install |
| 51 | + uses: actions/cache@v2 |
| 52 | + id: g4cache |
| 53 | + with: |
| 54 | + path: ${{ github.workspace }}/${{ env.GEANT4_INSTALL_DIR }} |
| 55 | + key: ${{ env.GEANT4_GIT_TAG }}v2 |
| 56 | + |
| 57 | + - uses: actions/checkout@v2 |
| 58 | + if: steps.g4cache.outputs.cache-hit != 'true' |
| 59 | + with: |
| 60 | + repository: Geant4/geant4 |
| 61 | + ref: ${{ env.GEANT4_GIT_TAG }} |
| 62 | + path: ${{ env.GEANT4_SOURCE_DIR }} |
| 63 | + |
| 64 | + - uses: lukka/get-cmake@latest |
| 65 | + if: steps.g4cache.outputs.cache-hit != 'true' |
| 66 | + |
| 67 | + - name: CMake configure Geant4 Unix |
| 68 | + if: steps.g4cache.outputs.cache-hit != 'true' && runner.os != 'Windows' |
| 69 | + run: > |
| 70 | + cmake -E env CXXFLAGS="-fPIC" |
| 71 | + cmake -E env CFLAGS="-fPIC" |
| 72 | + cmake |
| 73 | + -DBUILD_STATIC_LIBS=ON |
| 74 | + -DBUILD_SHARED_LIBS=OFF |
| 75 | + -DGEANT4_INSTALL_EXAMPLES=OFF |
| 76 | + -DGEANT4_USE_SYSTEM_EXPAT=OFF |
| 77 | + -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/${{ env.GEANT4_INSTALL_DIR }}" |
| 78 | + -S "${{ github.workspace }}/${{ env.GEANT4_SOURCE_DIR }}" |
| 79 | + -B "${{ github.workspace }}/${{ env.GEANT4_BUILD_DIR }}" |
| 80 | +
|
| 81 | + - name: CMake configure Geant4 Windows |
| 82 | + if: steps.g4cache.outputs.cache-hit != 'true' && runner.os == 'Windows' |
| 83 | + run: > |
| 84 | + cmake |
| 85 | + -DBUILD_STATIC_LIBS=ON |
| 86 | + -DBUILD_SHARED_LIBS=OFF |
| 87 | + -DGEANT4_INSTALL_EXAMPLES=OFF |
| 88 | + -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/${{ env.GEANT4_INSTALL_DIR }}" |
| 89 | + -S "${{ github.workspace }}/${{ env.GEANT4_SOURCE_DIR }}" |
| 90 | + -B "${{ github.workspace }}/${{ env.GEANT4_BUILD_DIR }}" |
| 91 | +
|
| 92 | + - name: CMake build Geant4 |
| 93 | + if: steps.g4cache.outputs.cache-hit != 'true' |
| 94 | + run: cmake --build "${{ github.workspace }}/${{ env.GEANT4_BUILD_DIR }}" --config Release |
| 95 | + |
| 96 | + - name: CMake install Geant4 |
| 97 | + if: steps.g4cache.outputs.cache-hit != 'true' |
| 98 | + run: > |
| 99 | + cmake |
| 100 | + --build "${{ github.workspace }}/${{ env.GEANT4_BUILD_DIR }}" |
| 101 | + --config Release |
| 102 | + --target install |
| 103 | +
|
| 104 | + - name: Setup environment variables |
| 105 | + shell: bash |
| 106 | + run: | |
| 107 | + echo "${{ github.workspace }}/${{ env.GEANT4_INSTALL_DIR }}/bin" >> $GITHUB_PATH |
| 108 | + echo "HOME=${{ github.workspace }}" >> $GITHUB_ENV |
| 109 | +
|
| 110 | + - uses: actions/checkout@v2 |
| 111 | + with: |
| 112 | + submodules: true |
| 113 | + path: ${{ github.event.repository.name }} |
| 114 | + |
| 115 | + - uses: actions/setup-python@v2 |
| 116 | + with: |
| 117 | + python-version: ${{ matrix.python-version }} |
| 118 | + |
| 119 | + - name: Add Python requirements |
| 120 | + run: python -m pip install --upgrade wheel setuptools build psutil |
| 121 | + |
| 122 | + - name: Build wheel |
| 123 | + run: python -m build ${{ github.event.repository.name }} |
| 124 | + |
| 125 | + - name: Install wheel |
| 126 | + run: > |
| 127 | + python -m pip install --no-index |
| 128 | + --find-links=${{ github.event.repository.name }}/dist |
| 129 | + geant4_pybind |
| 130 | +
|
| 131 | + - name: Cache Geant4 datasets |
| 132 | + uses: actions/cache@v2 |
| 133 | + with: |
| 134 | + key: ${{ env.GEANT4_GIT_TAG }}-datasets |
| 135 | + path: ${{ github.workspace }}/.geant4_pybind |
| 136 | + |
| 137 | + - name: Run B1 (sanity) test |
| 138 | + run: python ${{ github.event.repository.name }}/tests/test_B1.py |
| 139 | + |
| 140 | + - name: Run example tests |
| 141 | + if: runner.os == 'Linux' |
| 142 | + run: python ${{ github.event.repository.name }}/tests/test_examples.py |
| 143 | + |
| 144 | + - uses: actions/upload-artifact@v2 |
| 145 | + with: |
| 146 | + path: ${{ github.event.repository.name }}/dist/*.whl |
| 147 | + |
| 148 | + |
| 149 | + upload_all: |
| 150 | + name: Upload if release |
| 151 | + needs: [build_wheels, build_sdist] |
| 152 | + runs-on: ubuntu-latest |
| 153 | + if: ${{ github.event_name == 'release' && github.event.action == 'published' }} |
| 154 | + |
| 155 | + steps: |
| 156 | + - uses: actions/setup-python@v2 |
| 157 | + |
| 158 | + - uses: actions/download-artifact@v2 |
| 159 | + with: |
| 160 | + name: artifact |
| 161 | + path: dist |
| 162 | + |
| 163 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 164 | + with: |
| 165 | + user: __token__ |
| 166 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments