python-release.yml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. name: Release (Python)
  2. # A PR labeled python-release-dry-run or a manual run with publish=false builds
  3. # and validates the complete release without registry credentials. Publication
  4. # is accepted only from a manual run on the matching python-v* tag when the
  5. # private publisher-repository identity and public-PyPI switch are configured.
  6. on:
  7. workflow_dispatch:
  8. inputs:
  9. publish:
  10. description: Publish the validated wheels to public PyPI. Must run from a python-v* tag.
  11. required: true
  12. type: boolean
  13. default: false
  14. pull_request:
  15. types: [labeled]
  16. permissions:
  17. contents: read
  18. concurrency:
  19. # Public runs stay globally serialized across tags. Dry runs remain isolated
  20. # by ref so they do not block an intentional publication.
  21. group: ${{ github.event_name == 'workflow_dispatch' && inputs.publish && 'python-publication' || format('{0}-{1}', github.workflow, github.ref) }}
  22. cancel-in-progress: false
  23. jobs:
  24. build:
  25. name: Build four wheels
  26. if: github.event_name == 'workflow_dispatch' || github.event.label.name == 'python-release-dry-run'
  27. uses: ./.github/workflows/build-exe-for-python-sdk.yml
  28. with:
  29. targets: node24-linux-x64,node24-linux-arm64,node24-macos-arm64
  30. release: true
  31. python-compat:
  32. name: Python ${{ matrix.python }} / installed SDK
  33. needs: build
  34. runs-on: ubuntu-latest
  35. timeout-minutes: 10
  36. strategy:
  37. fail-fast: false
  38. matrix:
  39. python: ['3.10', '3.14']
  40. steps:
  41. - uses: actions/checkout@v6
  42. with:
  43. persist-credentials: false
  44. - uses: actions/setup-python@v6.3.0
  45. with:
  46. python-version: ${{ matrix.python }}
  47. - uses: actions/download-artifact@v8
  48. with:
  49. pattern: deepseek_harness_*
  50. path: dist
  51. merge-multiple: true
  52. - name: Resolve installed wheel version
  53. id: compatibility-version
  54. run: |
  55. python - <<'PY' >> "$GITHUB_OUTPUT"
  56. import runpy
  57. release = runpy.run_path("scripts/build-python-release.py")
  58. repository_version = release["repository_version"]()
  59. print(f"version={release['pep440_version'](repository_version)}")
  60. PY
  61. - name: Install and run the published entry path
  62. run: |
  63. python -m pip install --find-links dist "deepseek-harness-sdk==${{ steps.compatibility-version.outputs.version }}"
  64. python scripts/smoke-python-runtime.py --scenario sdk-default
  65. validate:
  66. name: Validate release candidate
  67. needs: [build, python-compat]
  68. runs-on: ubuntu-latest
  69. timeout-minutes: 10
  70. outputs:
  71. version: ${{ steps.version.outputs.version }}
  72. steps:
  73. - uses: actions/checkout@v6
  74. with:
  75. persist-credentials: false
  76. - uses: actions/setup-python@v6.3.0
  77. with:
  78. python-version: '3.10'
  79. - name: Resolve release version
  80. id: version
  81. run: |
  82. python3 - <<'PY' >> "$GITHUB_OUTPUT"
  83. import runpy
  84. release = runpy.run_path("scripts/build-python-release.py")
  85. repository_version = release["repository_version"]()
  86. wheel_version = release["pep440_version"](repository_version)
  87. print(f"repository-version={repository_version}")
  88. print(f"version={wheel_version}")
  89. PY
  90. - name: Authorize publication request
  91. env:
  92. PUBLISH: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }}
  93. PUBLIC_PYPI_RELEASE_ENABLED: ${{ vars.PUBLIC_PYPI_RELEASE_ENABLED }}
  94. PYPI_PUBLISHER_REPOSITORY: ${{ vars.PYPI_PUBLISHER_REPOSITORY }}
  95. REPOSITORY: ${{ github.repository }}
  96. REF_NAME: ${{ github.ref_name }}
  97. REF_TYPE: ${{ github.ref_type }}
  98. REPOSITORY_VERSION: ${{ steps.version.outputs.repository-version }}
  99. run: |
  100. set -euo pipefail
  101. if [ "$PUBLISH" = true ]; then
  102. [ -n "$PYPI_PUBLISHER_REPOSITORY" ] || {
  103. echo "::error::Set the repository variable PYPI_PUBLISHER_REPOSITORY before publication."
  104. exit 1
  105. }
  106. [ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ] || {
  107. echo "::error::This repository is not the configured PyPI publisher repository."
  108. exit 1
  109. }
  110. [ "$PUBLIC_PYPI_RELEASE_ENABLED" = true ] || {
  111. echo "::error::Set PUBLIC_PYPI_RELEASE_ENABLED=true before public publication."
  112. exit 1
  113. }
  114. [ "$REF_TYPE" = tag ] && [ "$REF_NAME" = "python-v$REPOSITORY_VERSION" ] || {
  115. echo "::error::Publication must run from tag python-v$REPOSITORY_VERSION."
  116. exit 1
  117. }
  118. fi
  119. - uses: actions/download-artifact@v8
  120. with:
  121. pattern: deepseek_harness_*
  122. path: dist
  123. merge-multiple: true
  124. - name: Check release contents
  125. env:
  126. VERSION: ${{ steps.version.outputs.version }}
  127. run: |
  128. set -euo pipefail
  129. expected="$(mktemp)"
  130. actual="$(mktemp)"
  131. printf '%s\n' \
  132. "deepseek_harness_runtime_bin-$VERSION-py3-none-macosx_14_0_arm64.whl" \
  133. "deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_aarch64.whl" \
  134. "deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl" \
  135. "deepseek_harness_sdk-$VERSION-py3-none-any.whl" > "$expected"
  136. find dist -maxdepth 1 -type f -name '*.whl' -exec basename {} \; | sort > "$actual"
  137. diff -u "$expected" "$actual"
  138. while IFS= read -r wheel; do
  139. size="$(stat -c '%s' "dist/$wheel")"
  140. [ "$size" -lt 100000000 ] || {
  141. echo "::error::$wheel is $size bytes; public PyPI accepts at most 100000000 bytes by default."
  142. exit 1
  143. }
  144. done < "$actual"
  145. - name: Validate package metadata
  146. run: |
  147. python -m pip install twine==6.2.0
  148. python -m twine check dist/*.whl
  149. - name: Record artifact hashes
  150. run: |
  151. cd dist
  152. sha256sum *.whl | sort -k2 > SHA256SUMS
  153. cat SHA256SUMS
  154. - uses: actions/upload-artifact@v7
  155. with:
  156. name: python-release-${{ steps.version.outputs.version }}
  157. path: dist/*
  158. if-no-files-found: error
  159. retention-days: 7
  160. publish-runtime:
  161. name: Publish runtime wheels to public PyPI
  162. if: github.event_name == 'workflow_dispatch' && inputs.publish
  163. needs: validate
  164. runs-on: ubuntu-latest
  165. timeout-minutes: 10
  166. environment: pypi-runtime
  167. permissions:
  168. contents: read
  169. id-token: write
  170. steps:
  171. - uses: actions/download-artifact@v8
  172. with:
  173. name: python-release-${{ needs.validate.outputs.version }}
  174. path: dist
  175. - name: Verify release artifact hashes
  176. run: cd dist && sha256sum -c SHA256SUMS
  177. - name: Select runtime wheels
  178. run: |
  179. mkdir -p dist/runtime
  180. mv dist/deepseek_harness_runtime_bin-*.whl dist/runtime/
  181. - name: Publish runtime wheels
  182. uses: pypa/gh-action-pypi-publish@release/v1
  183. with:
  184. packages-dir: dist/runtime/
  185. # Public attestations reveal the private publisher repository. OIDC
  186. # authentication remains enabled without uploading that provenance.
  187. attestations: false
  188. # Keep the SDK in a dependent job. If its upload fails after the immutable
  189. # runtime files arrive, "re-run failed jobs" resumes here without attempting
  190. # to overwrite the runtime release.
  191. publish-sdk:
  192. name: Publish SDK wheel to public PyPI
  193. if: github.event_name == 'workflow_dispatch' && inputs.publish
  194. needs: [validate, publish-runtime]
  195. runs-on: ubuntu-latest
  196. timeout-minutes: 10
  197. environment: pypi
  198. permissions:
  199. contents: read
  200. id-token: write
  201. steps:
  202. - uses: actions/download-artifact@v8
  203. with:
  204. name: python-release-${{ needs.validate.outputs.version }}
  205. path: dist
  206. - name: Verify release artifact hashes
  207. run: cd dist && sha256sum -c SHA256SUMS
  208. - name: Select SDK wheel
  209. run: |
  210. mkdir -p dist/sdk
  211. mv dist/deepseek_harness_sdk-*.whl dist/sdk/
  212. - name: Publish SDK wheel
  213. uses: pypa/gh-action-pypi-publish@release/v1
  214. with:
  215. packages-dir: dist/sdk/
  216. attestations: false