python-release.yml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. python scripts/smoke-python-runtime.py --scenario sdk-mcp
  66. validate:
  67. name: Validate release candidate
  68. needs: [build, python-compat]
  69. runs-on: ubuntu-latest
  70. timeout-minutes: 10
  71. outputs:
  72. version: ${{ steps.version.outputs.version }}
  73. steps:
  74. - uses: actions/checkout@v6
  75. with:
  76. persist-credentials: false
  77. - uses: actions/setup-python@v6.3.0
  78. with:
  79. python-version: '3.10'
  80. - name: Resolve release version
  81. id: version
  82. run: |
  83. python3 - <<'PY' >> "$GITHUB_OUTPUT"
  84. import runpy
  85. release = runpy.run_path("scripts/build-python-release.py")
  86. repository_version = release["repository_version"]()
  87. wheel_version = release["pep440_version"](repository_version)
  88. print(f"repository-version={repository_version}")
  89. print(f"version={wheel_version}")
  90. PY
  91. - name: Authorize publication request
  92. env:
  93. PUBLISH: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }}
  94. PUBLIC_PYPI_RELEASE_ENABLED: ${{ vars.PUBLIC_PYPI_RELEASE_ENABLED }}
  95. PYPI_PUBLISHER_REPOSITORY: ${{ vars.PYPI_PUBLISHER_REPOSITORY }}
  96. REPOSITORY: ${{ github.repository }}
  97. REF_NAME: ${{ github.ref_name }}
  98. REF_TYPE: ${{ github.ref_type }}
  99. REPOSITORY_VERSION: ${{ steps.version.outputs.repository-version }}
  100. run: |
  101. set -euo pipefail
  102. if [ "$PUBLISH" = true ]; then
  103. [ -n "$PYPI_PUBLISHER_REPOSITORY" ] || {
  104. echo "::error::Set the repository variable PYPI_PUBLISHER_REPOSITORY before publication."
  105. exit 1
  106. }
  107. [ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ] || {
  108. echo "::error::This repository is not the configured PyPI publisher repository."
  109. exit 1
  110. }
  111. [ "$PUBLIC_PYPI_RELEASE_ENABLED" = true ] || {
  112. echo "::error::Set PUBLIC_PYPI_RELEASE_ENABLED=true before public publication."
  113. exit 1
  114. }
  115. [ "$REF_TYPE" = tag ] && [ "$REF_NAME" = "python-v$REPOSITORY_VERSION" ] || {
  116. echo "::error::Publication must run from tag python-v$REPOSITORY_VERSION."
  117. exit 1
  118. }
  119. fi
  120. - uses: actions/download-artifact@v8
  121. with:
  122. pattern: deepseek_harness_*
  123. path: dist
  124. merge-multiple: true
  125. - name: Check release contents
  126. env:
  127. VERSION: ${{ steps.version.outputs.version }}
  128. run: |
  129. set -euo pipefail
  130. expected="$(mktemp)"
  131. actual="$(mktemp)"
  132. printf '%s\n' \
  133. "deepseek_harness_runtime_bin-$VERSION-py3-none-macosx_14_0_arm64.whl" \
  134. "deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_aarch64.whl" \
  135. "deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl" \
  136. "deepseek_harness_sdk-$VERSION-py3-none-any.whl" > "$expected"
  137. find dist -maxdepth 1 -type f -name '*.whl' -exec basename {} \; | sort > "$actual"
  138. diff -u "$expected" "$actual"
  139. while IFS= read -r wheel; do
  140. size="$(stat -c '%s' "dist/$wheel")"
  141. [ "$size" -lt 100000000 ] || {
  142. echo "::error::$wheel is $size bytes; public PyPI accepts at most 100000000 bytes by default."
  143. exit 1
  144. }
  145. done < "$actual"
  146. - name: Validate package metadata
  147. run: |
  148. python -m pip install twine==6.2.0
  149. python -m twine check dist/*.whl
  150. - name: Record artifact hashes
  151. run: |
  152. cd dist
  153. sha256sum *.whl | sort -k2 > SHA256SUMS
  154. cat SHA256SUMS
  155. - uses: actions/upload-artifact@v7
  156. with:
  157. name: python-release-${{ steps.version.outputs.version }}
  158. path: dist/*
  159. if-no-files-found: error
  160. retention-days: 7
  161. publish-runtime:
  162. name: Publish runtime wheels to public PyPI
  163. if: github.event_name == 'workflow_dispatch' && inputs.publish
  164. needs: validate
  165. runs-on: ubuntu-latest
  166. timeout-minutes: 10
  167. environment: pypi-runtime
  168. permissions:
  169. contents: read
  170. id-token: write
  171. steps:
  172. - uses: actions/download-artifact@v8
  173. with:
  174. name: python-release-${{ needs.validate.outputs.version }}
  175. path: dist
  176. - name: Verify release artifact hashes
  177. run: cd dist && sha256sum -c SHA256SUMS
  178. - name: Select runtime wheels
  179. run: |
  180. mkdir -p dist/runtime
  181. mv dist/deepseek_harness_runtime_bin-*.whl dist/runtime/
  182. - name: Publish runtime wheels
  183. uses: pypa/gh-action-pypi-publish@release/v1
  184. with:
  185. packages-dir: dist/runtime/
  186. # Public attestations reveal the private publisher repository. OIDC
  187. # authentication remains enabled without uploading that provenance.
  188. attestations: false
  189. # Keep the SDK in a dependent job. If its upload fails after the immutable
  190. # runtime files arrive, "re-run failed jobs" resumes here without attempting
  191. # to overwrite the runtime release.
  192. publish-sdk:
  193. name: Publish SDK wheel to public PyPI
  194. if: github.event_name == 'workflow_dispatch' && inputs.publish
  195. needs: [validate, publish-runtime]
  196. runs-on: ubuntu-latest
  197. timeout-minutes: 10
  198. environment: pypi
  199. permissions:
  200. contents: read
  201. id-token: write
  202. steps:
  203. - uses: actions/download-artifact@v8
  204. with:
  205. name: python-release-${{ needs.validate.outputs.version }}
  206. path: dist
  207. - name: Verify release artifact hashes
  208. run: cd dist && sha256sum -c SHA256SUMS
  209. - name: Select SDK wheel
  210. run: |
  211. mkdir -p dist/sdk
  212. mv dist/deepseek_harness_sdk-*.whl dist/sdk/
  213. - name: Publish SDK wheel
  214. uses: pypa/gh-action-pypi-publish@release/v1
  215. with:
  216. packages-dir: dist/sdk/
  217. attestations: false