2
0

python-distributions.yml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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@v6
  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@v6
  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.6.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@v5.0.0
  81. with:
  82. name: artifact-${{ matrix.build-identifier }}
  83. path: ./wheelhouse/*.whl
  84. build-android-wheels:
  85. runs-on: ubuntu-latest
  86. steps:
  87. - uses: actions/checkout@v5.0.0
  88. - uses: actions/setup-python@v6
  89. with:
  90. cache: pip
  91. - name: Install dependencies
  92. run: |
  93. python -m pip install --upgrade pip
  94. pip install setuptools wheel cibuildwheel setuptools-rust
  95. - name: Build Android wheels
  96. run: python -m cibuildwheel --output-dir wheelhouse
  97. env:
  98. CIBW_PLATFORM: android
  99. CIBW_ARCHS_ANDROID: arm64_v8a x86_64
  100. - name: Upload Android wheels
  101. uses: actions/upload-artifact@v5.0.0
  102. with:
  103. name: artifact-android
  104. path: ./wheelhouse/*.whl
  105. build-pure-wheels:
  106. runs-on: ubuntu-latest
  107. steps:
  108. - uses: actions/checkout@v5.0.0
  109. - uses: actions/setup-python@v6
  110. with:
  111. cache: pip
  112. - run: pip install build
  113. - run: PURE=true python -m build --wheel
  114. - name: Upload pure wheels
  115. uses: actions/upload-artifact@v5.0.0
  116. with:
  117. name: artifact-pure
  118. path: ./dist/*.whl
  119. build-sdist:
  120. runs-on: ubuntu-latest
  121. steps:
  122. - uses: actions/checkout@v5.0.0
  123. - uses: actions/setup-python@v6
  124. with:
  125. cache: pip
  126. - name: Install dependencies
  127. run: |
  128. python -m pip install --upgrade pip
  129. pip install build
  130. - name: Build sdist
  131. run: python -m build --sdist
  132. - name: Upload sdist
  133. uses: actions/upload-artifact@v5.0.0
  134. with:
  135. name: artifact-source
  136. path: ./dist/*.tar.gz
  137. test-sdist:
  138. needs:
  139. - build-sdist
  140. runs-on: ubuntu-latest
  141. steps:
  142. - uses: actions/setup-python@v6
  143. with:
  144. cache: pip
  145. - name: Install dependencies
  146. run: |
  147. python -m pip install --upgrade pip
  148. # Upgrade packging to avoid a bug in twine.
  149. # See https://github.com/pypa/twine/issues/1216
  150. pip install "twine>=6.1.0" "packaging>=24.2"
  151. - name: Download sdist
  152. uses: actions/download-artifact@v6.0.0
  153. with:
  154. name: artifact-source
  155. path: dist
  156. - name: Test sdist
  157. run: twine check dist/*
  158. - name: Test installation from sdist
  159. run: pip install dist/*.tar.gz
  160. publish:
  161. runs-on: ubuntu-latest
  162. needs:
  163. - build-wheels
  164. - build-android-wheels
  165. - build-sdist
  166. - build-pure-wheels
  167. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/dulwich-')
  168. permissions:
  169. id-token: write
  170. environment:
  171. name: pypi
  172. url: https://pypi.org/p/dulwich
  173. steps:
  174. - name: Download distributions
  175. uses: actions/download-artifact@v6.0.0
  176. with:
  177. merge-multiple: true
  178. pattern: artifact-*
  179. path: dist
  180. - name: Publish package distributions to PyPI
  181. uses: pypa/gh-action-pypi-publish@v1.13.0