python-release.yml 8.4 KB

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