python-distributions.yml 6.9 KB

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