python-distributions.yml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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-sdist:
  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 build
  92. - name: Build sdist
  93. run: python -m build --sdist
  94. - name: Upload sdist
  95. uses: actions/upload-artifact@v4
  96. with:
  97. name: artifact-source
  98. path: ./dist/*.tar.gz
  99. test-sdist:
  100. needs:
  101. - build-sdist
  102. runs-on: ubuntu-latest
  103. steps:
  104. - uses: actions/setup-python@v5
  105. with:
  106. cache: pip
  107. - name: Install dependencies
  108. run: |
  109. python -m pip install --upgrade pip
  110. pip install twine
  111. - name: Download sdist
  112. uses: actions/download-artifact@v4
  113. with:
  114. name: artifact-source
  115. path: dist
  116. - name: Test sdist
  117. run: twine check dist/*
  118. - name: Test installation from sdist
  119. run: pip install dist/*.tar.gz
  120. publish:
  121. runs-on: ubuntu-latest
  122. needs:
  123. - build-wheels
  124. - build-sdist
  125. if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/dulwich-')
  126. permissions:
  127. id-token: write
  128. environment:
  129. name: pypi
  130. url: https://pypi.org/p/dulwich
  131. steps:
  132. - name: Download distributions
  133. uses: actions/download-artifact@v4
  134. with:
  135. merge-multiple: true
  136. pattern: artifact-*
  137. path: dist
  138. - name: Publish package distributions to PyPI
  139. uses: pypa/gh-action-pypi-publish@release/v1