2
0

python-distributions.yml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. ---
  2. name: Build Python distributions
  3. "on":
  4. push:
  5. branches: [main, master]
  6. tags:
  7. - 'dulwich-*'
  8. pull_request:
  9. schedule:
  10. - cron: "0 6 * * *" # Daily 6AM UTC build
  11. permissions:
  12. contents: read
  13. jobs:
  14. define-matrix:
  15. runs-on: ubuntu-latest
  16. outputs:
  17. matrix: ${{ steps.merged-identifiers.outputs.merged-identifiers }}
  18. steps:
  19. - uses: actions/checkout@v5.0.0
  20. - uses: actions/setup-python@v5.3.0
  21. with:
  22. python-version: 3.x
  23. cache: pip
  24. - name: Install jq
  25. run: sudo apt-get update && sudo apt-get install -y jq
  26. - name: Install cibuildwheel
  27. run: pip install cibuildwheel
  28. - name: Find build identifiers using cibuildwheel --print-build-identifiers
  29. id: all-build-identifiers
  30. run: |
  31. echo "linux=$(cibuildwheel --platform linux --print-build-identifiers | grep -v cp314 | tr '\n' ' ')" >> $GITHUB_OUTPUT
  32. echo "macos=$(cibuildwheel --platform macos --print-build-identifiers | grep -v cp314 | tr '\n' ' ')" >> $GITHUB_OUTPUT
  33. echo "windows=$(cibuildwheel --platform windows --print-build-identifiers | grep -v cp314 | tr '\n' ' ')" >> $GITHUB_OUTPUT
  34. - name: Select build identifiers
  35. id: select-build-identifiers
  36. run: |
  37. if [[ "$GITHUB_REF" = "refs/heads/main" ]] || [[ "$GITHUB_REF" = "refs/heads/master" ]] || [[ "$GITHUB_REF" = "refs/tags/"* ]]; then
  38. echo 'linux=${{ steps.all-build-identifiers.outputs.linux }}' >> $GITHUB_OUTPUT
  39. echo 'windows=${{ steps.all-build-identifiers.outputs.windows }}' >> $GITHUB_OUTPUT
  40. echo 'macos=${{ steps.all-build-identifiers.outputs.macos }}' >> $GITHUB_OUTPUT
  41. else
  42. echo "linux=$(echo -n '${{ steps.all-build-identifiers.outputs.linux }}' | awk '{print $NF}')" >> $GITHUB_OUTPUT
  43. echo "macos=$(echo -n '${{ steps.all-build-identifiers.outputs.macos }}' | awk '{print $NF}')" >> $GITHUB_OUTPUT
  44. echo "windows=$(echo -n '${{ steps.all-build-identifiers.outputs.windows }}' | awk '{print $NF}')" >> $GITHUB_OUTPUT
  45. fi
  46. - name: Output build identifiers
  47. id: json-identifiers
  48. run: |
  49. echo "linux=$(echo -n '${{ steps.select-build-identifiers.outputs.linux }}' | jq -R -s -c 'split(" ") | map(select(length > 0)) | [.[] | {os: "ubuntu-latest", "build-identifier": .}]')" >> $GITHUB_OUTPUT
  50. echo "macos=$(echo -n '${{ steps.select-build-identifiers.outputs.macos }}' | jq -R -s -c 'split(" ") | map(select(length > 0)) | [.[] | {os: "macos-latest", "build-identifier": .}]')" >> $GITHUB_OUTPUT
  51. echo "windows=$(echo -n '${{ steps.select-build-identifiers.outputs.windows }}' | jq -R -s -c 'split(" ") | map(select(length > 0)) | [.[] | {os: "windows-latest", "build-identifier": .}]')" >> $GITHUB_OUTPUT
  52. - name: Merge build identifiers
  53. id: merged-identifiers
  54. run: |
  55. echo merged-identifiers=$(echo -n '${{ steps.json-identifiers.outputs.linux }} ${{ steps.json-identifiers.outputs.macos }} ${{ steps.json-identifiers.outputs.windows }}' | jq -c -s 'add') >> $GITHUB_OUTPUT
  56. build-wheels:
  57. runs-on: ${{ matrix.os }}
  58. needs: define-matrix
  59. strategy:
  60. matrix:
  61. include: ${{ fromJSON(needs.define-matrix.outputs.matrix ) }}
  62. fail-fast: true
  63. steps:
  64. - uses: actions/checkout@v5.0.0
  65. - uses: actions/setup-python@v5.3.0
  66. with:
  67. cache: pip
  68. - name: Install dependencies
  69. run: |
  70. python -m pip install --upgrade pip
  71. pip install setuptools wheel cibuildwheel setuptools-rust
  72. - name: Set up QEMU
  73. uses: docker/setup-qemu-action@v3.2.0
  74. if: "matrix.os == 'ubuntu-latest'"
  75. - name: Build wheels
  76. run: python -m cibuildwheel --output-dir wheelhouse
  77. env:
  78. CIBW_BUILD: "${{ matrix.build-identifier }}*"
  79. - name: Upload wheels
  80. uses: actions/upload-artifact@v4.5.0
  81. with:
  82. name: artifact-${{ matrix.build-identifier }}
  83. path: ./wheelhouse/*.whl
  84. # Android wheels build disabled due to HTTP 403 Forbidden error when downloading
  85. # Python 3.13.7 for Android from Maven repository (python-3.13.7-aarch64-linux-android.tar.gz)
  86. # The download from https://repo.maven.apache.org fails during cibuildwheel setup
  87. # build-android-wheels:
  88. # runs-on: ubuntu-latest
  89. # steps:
  90. # - uses: actions/checkout@v5.0.0
  91. # - uses: actions/setup-python@v5.3.0
  92. # with:
  93. # cache: pip
  94. # - name: Install dependencies
  95. # run: |
  96. # python -m pip install --upgrade pip
  97. # pip install setuptools wheel cibuildwheel setuptools-rust
  98. # - name: Build Android wheels
  99. # run: python -m cibuildwheel --output-dir wheelhouse
  100. # env:
  101. # CIBW_PLATFORM: android
  102. # CIBW_ARCHS_ANDROID: arm64_v8a x86_64
  103. # - name: Upload Android wheels
  104. # uses: actions/upload-artifact@v4.5.0
  105. # with:
  106. # name: artifact-android
  107. # path: ./wheelhouse/*.whl
  108. build-pure-wheels:
  109. runs-on: ubuntu-latest
  110. steps:
  111. - uses: actions/checkout@v5.0.0
  112. - uses: actions/setup-python@v5.3.0
  113. with:
  114. cache: pip
  115. - run: pip install build
  116. - run: PURE=true python -m build --wheel
  117. - name: Upload pure wheels
  118. uses: actions/upload-artifact@v4.5.0
  119. with:
  120. name: artifact-pure
  121. path: ./dist/*.whl
  122. build-sdist:
  123. runs-on: ubuntu-latest
  124. steps:
  125. - uses: actions/checkout@v5.0.0
  126. - uses: actions/setup-python@v5.3.0
  127. with:
  128. cache: pip
  129. - name: Install dependencies
  130. run: |
  131. python -m pip install --upgrade pip
  132. pip install build
  133. - name: Build sdist
  134. run: python -m build --sdist
  135. - name: Upload sdist
  136. uses: actions/upload-artifact@v4.5.0
  137. with:
  138. name: artifact-source
  139. path: ./dist/*.tar.gz
  140. test-sdist:
  141. needs:
  142. - build-sdist
  143. runs-on: ubuntu-latest
  144. steps:
  145. - uses: actions/setup-python@v5.3.0
  146. with:
  147. cache: pip
  148. - name: Install dependencies
  149. run: |
  150. python -m pip install --upgrade pip
  151. # Upgrade packging to avoid a bug in twine.
  152. # See https://github.com/pypa/twine/issues/1216
  153. pip install "twine>=6.1.0" "packaging>=24.2"
  154. - name: Download sdist
  155. uses: actions/download-artifact@v5.0.0
  156. with:
  157. name: artifact-source
  158. path: dist
  159. - name: Test sdist
  160. run: twine check dist/*
  161. - name: Test installation from sdist
  162. run: pip install dist/*.tar.gz
  163. publish:
  164. runs-on: ubuntu-latest
  165. needs:
  166. - build-wheels
  167. # - build-android-wheels
  168. - build-sdist
  169. - build-pure-wheels
  170. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/dulwich-')
  171. permissions:
  172. id-token: write
  173. environment:
  174. name: pypi
  175. url: https://pypi.org/p/dulwich
  176. steps:
  177. - name: Download distributions
  178. uses: actions/download-artifact@v5.0.0
  179. with:
  180. merge-multiple: true
  181. pattern: artifact-*
  182. path: dist
  183. - name: Publish package distributions to PyPI
  184. uses: pypa/gh-action-pypi-publish@v1.13