python-distributions.yml 6.8 KB

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