python-distributions.yml 5.4 KB

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