1
0

release-artifacts.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # GitHub actions workflow which builds the release artifacts.
  2. name: Build release artifacts
  3. on:
  4. # we build on PRs and develop to (hopefully) get early warning
  5. # of things breaking (but only build one set of debs). PRs skip
  6. # building wheels on macOS & ARM.
  7. pull_request:
  8. push:
  9. branches: ["develop", "release-*"]
  10. # we do the full build on tags.
  11. tags: ["v*"]
  12. merge_group:
  13. workflow_dispatch:
  14. concurrency:
  15. group: ${{ github.workflow }}-${{ github.ref }}
  16. cancel-in-progress: true
  17. permissions:
  18. contents: write
  19. jobs:
  20. get-distros:
  21. name: "Calculate list of debian distros"
  22. runs-on: ubuntu-latest
  23. steps:
  24. - uses: actions/checkout@v3
  25. - uses: actions/setup-python@v4
  26. with:
  27. python-version: '3.x'
  28. - id: set-distros
  29. run: |
  30. # if we're running from a tag, get the full list of distros; otherwise just use debian:sid
  31. dists='["debian:sid"]'
  32. if [[ $GITHUB_REF == refs/tags/* ]]; then
  33. dists=$(scripts-dev/build_debian_packages.py --show-dists-json)
  34. fi
  35. echo "distros=$dists" >> "$GITHUB_OUTPUT"
  36. # map the step outputs to job outputs
  37. outputs:
  38. distros: ${{ steps.set-distros.outputs.distros }}
  39. # now build the packages with a matrix build.
  40. build-debs:
  41. needs: get-distros
  42. name: "Build .deb packages"
  43. runs-on: ubuntu-latest
  44. strategy:
  45. matrix:
  46. distro: ${{ fromJson(needs.get-distros.outputs.distros) }}
  47. steps:
  48. - name: Checkout
  49. uses: actions/checkout@v3
  50. with:
  51. path: src
  52. - name: Set up Docker Buildx
  53. id: buildx
  54. uses: docker/setup-buildx-action@v2
  55. with:
  56. install: true
  57. - name: Set up docker layer caching
  58. uses: actions/cache@v3
  59. with:
  60. path: /tmp/.buildx-cache
  61. key: ${{ runner.os }}-buildx-${{ github.sha }}
  62. restore-keys: |
  63. ${{ runner.os }}-buildx-
  64. - name: Set up python
  65. uses: actions/setup-python@v4
  66. with:
  67. python-version: '3.x'
  68. - name: Build the packages
  69. # see https://github.com/docker/build-push-action/issues/252
  70. # for the cache magic here
  71. run: |
  72. ./src/scripts-dev/build_debian_packages.py \
  73. --docker-build-arg=--cache-from=type=local,src=/tmp/.buildx-cache \
  74. --docker-build-arg=--cache-to=type=local,mode=max,dest=/tmp/.buildx-cache-new \
  75. --docker-build-arg=--progress=plain \
  76. --docker-build-arg=--load \
  77. "${{ matrix.distro }}"
  78. rm -rf /tmp/.buildx-cache
  79. mv /tmp/.buildx-cache-new /tmp/.buildx-cache
  80. - name: Upload debs as artifacts
  81. uses: actions/upload-artifact@v3
  82. with:
  83. name: debs
  84. path: debs/*
  85. build-wheels:
  86. name: Build wheels on ${{ matrix.os }} for ${{ matrix.arch }}
  87. runs-on: ${{ matrix.os }}
  88. strategy:
  89. matrix:
  90. os: [ubuntu-20.04, macos-11]
  91. arch: [x86_64, aarch64]
  92. # is_pr is a flag used to exclude certain jobs from the matrix on PRs.
  93. # It is not read by the rest of the workflow.
  94. is_pr:
  95. - ${{ startsWith(github.ref, 'refs/pull/') }}
  96. exclude:
  97. # Don't build macos wheels on PR CI.
  98. - is_pr: true
  99. os: "macos-11"
  100. # Don't build aarch64 wheels on mac.
  101. - os: "macos-11"
  102. arch: aarch64
  103. # Don't build aarch64 wheels on PR CI.
  104. - is_pr: true
  105. arch: aarch64
  106. steps:
  107. - uses: actions/checkout@v3
  108. - uses: actions/setup-python@v4
  109. with:
  110. # setup-python@v4 doesn't impose a default python version. Need to use 3.x
  111. # here, because `python` on osx points to Python 2.7.
  112. python-version: "3.x"
  113. - name: Install cibuildwheel
  114. run: python -m pip install cibuildwheel==2.9.0
  115. - name: Set up QEMU to emulate aarch64
  116. if: matrix.arch == 'aarch64'
  117. uses: docker/setup-qemu-action@v2
  118. with:
  119. platforms: arm64
  120. - name: Build aarch64 wheels
  121. if: matrix.arch == 'aarch64'
  122. run: echo 'CIBW_ARCHS_LINUX=aarch64' >> $GITHUB_ENV
  123. - name: Only build a single wheel on PR
  124. if: startsWith(github.ref, 'refs/pull/')
  125. run: echo "CIBW_BUILD="cp37-manylinux_${{ matrix.arch }}"" >> $GITHUB_ENV
  126. - name: Build wheels
  127. run: python -m cibuildwheel --output-dir wheelhouse
  128. env:
  129. # Skip testing for platforms which various libraries don't have wheels
  130. # for, and so need extra build deps.
  131. CIBW_TEST_SKIP: pp3*-* *i686* *musl*
  132. # Fix Rust OOM errors on emulated aarch64: https://github.com/rust-lang/cargo/issues/10583
  133. CARGO_NET_GIT_FETCH_WITH_CLI: true
  134. CIBW_ENVIRONMENT_PASS_LINUX: CARGO_NET_GIT_FETCH_WITH_CLI
  135. - uses: actions/upload-artifact@v3
  136. with:
  137. name: Wheel
  138. path: ./wheelhouse/*.whl
  139. build-sdist:
  140. name: Build sdist
  141. runs-on: ubuntu-latest
  142. if: ${{ !startsWith(github.ref, 'refs/pull/') }}
  143. steps:
  144. - uses: actions/checkout@v3
  145. - uses: actions/setup-python@v4
  146. with:
  147. python-version: '3.10'
  148. - run: pip install build
  149. - name: Build sdist
  150. run: python -m build --sdist
  151. - uses: actions/upload-artifact@v3
  152. with:
  153. name: Sdist
  154. path: dist/*.tar.gz
  155. # if it's a tag, create a release and attach the artifacts to it
  156. attach-assets:
  157. name: "Attach assets to release"
  158. if: ${{ !failure() && !cancelled() && startsWith(github.ref, 'refs/tags/') }}
  159. needs:
  160. - build-debs
  161. - build-wheels
  162. - build-sdist
  163. runs-on: ubuntu-latest
  164. steps:
  165. - name: Download all workflow run artifacts
  166. uses: actions/download-artifact@v3
  167. - name: Build a tarball for the debs
  168. run: tar -cvJf debs.tar.xz debs
  169. - name: Attach to release
  170. uses: softprops/action-gh-release@a929a66f232c1b11af63782948aa2210f981808a # PR#109
  171. env:
  172. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  173. with:
  174. files: |
  175. Sdist/*
  176. Wheel/*
  177. debs.tar.xz
  178. # if it's not already published, keep the release as a draft.
  179. draft: true
  180. # mark it as a prerelease if the tag contains 'rc'.
  181. prerelease: ${{ contains(github.ref, 'rc') }}