release-artifacts.yml 6.3 KB

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