python-distributions.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 | tr '\n' ' ')" >> $GITHUB_OUTPUT
  29. echo "macos=$(cibuildwheel --platform macos --print-build-identifiers | tr '\n' ' ')" >> $GITHUB_OUTPUT
  30. echo "windows=$(cibuildwheel --platform windows --print-build-identifiers | 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-pure-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. - run: pip install build
  89. - run: PURE=true python -m build --wheel
  90. - name: Upload pure wheels
  91. uses: actions/upload-artifact@v4
  92. with:
  93. name: artifact-pure
  94. path: ./dist/*.whl
  95. build-sdist:
  96. runs-on: ubuntu-latest
  97. steps:
  98. - uses: actions/checkout@v4
  99. - uses: actions/setup-python@v5
  100. with:
  101. cache: pip
  102. - name: Install dependencies
  103. run: |
  104. python -m pip install --upgrade pip
  105. pip install build
  106. - name: Build sdist
  107. run: python -m build --sdist
  108. - name: Upload sdist
  109. uses: actions/upload-artifact@v4
  110. with:
  111. name: artifact-source
  112. path: ./dist/*.tar.gz
  113. test-sdist:
  114. needs:
  115. - build-sdist
  116. runs-on: ubuntu-latest
  117. steps:
  118. - uses: actions/setup-python@v5
  119. with:
  120. cache: pip
  121. - name: Install dependencies
  122. run: |
  123. python -m pip install --upgrade pip
  124. pip install twine
  125. - name: Download sdist
  126. uses: actions/download-artifact@v4
  127. with:
  128. name: artifact-source
  129. path: dist
  130. - name: Test sdist
  131. run: twine check dist/*
  132. - name: Test installation from sdist
  133. run: pip install dist/*.tar.gz
  134. publish:
  135. runs-on: ubuntu-latest
  136. needs:
  137. - build-wheels
  138. - build-sdist
  139. - build-pure-wheels
  140. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/dulwich-')
  141. permissions:
  142. id-token: write
  143. environment:
  144. name: pypi
  145. url: https://pypi.org/p/dulwich
  146. steps:
  147. - name: Download distributions
  148. uses: actions/download-artifact@v4
  149. with:
  150. merge-multiple: true
  151. pattern: artifact-*
  152. path: dist
  153. - name: Publish package distributions to PyPI
  154. uses: pypa/gh-action-pypi-publish@release/v1