1
0

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 five wheels
  24. uses: ./.github/workflows/build-exe-for-python-sdk.yml
  25. with:
  26. targets: node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-win-x64
  27. release: true
  28. python-compat:
  29. name: Python ${{ matrix.python }} / installed SDK
  30. needs: build
  31. runs-on: ubuntu-latest
  32. timeout-minutes: 10
  33. strategy:
  34. fail-fast: false
  35. matrix:
  36. python: ['3.10', '3.14']
  37. steps:
  38. - uses: actions/checkout@v6
  39. with:
  40. persist-credentials: false
  41. - uses: actions/setup-python@v6.3.0
  42. with:
  43. python-version: ${{ matrix.python }}
  44. - uses: actions/download-artifact@v8
  45. with:
  46. pattern: deepseek_harness_*
  47. path: dist
  48. merge-multiple: true
  49. - name: Resolve installed wheel version
  50. id: compatibility-version
  51. run: |
  52. python - <<'PY' >> "$GITHUB_OUTPUT"
  53. import runpy
  54. release = runpy.run_path("scripts/build-python-release.py")
  55. repository_version = release["repository_version"]()
  56. print(f"version={release['pep440_version'](repository_version)}")
  57. PY
  58. - name: Install local release wheels and run the public entry path
  59. env:
  60. VERSION: ${{ steps.compatibility-version.outputs.version }}
  61. run: |
  62. python -m pip install \
  63. "dist/deepseek_harness_sdk-$VERSION-py3-none-any.whl" \
  64. "dist/deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl"
  65. python scripts/smoke-python-runtime.py --scenario sdk-default
  66. python scripts/smoke-python-runtime.py --scenario sdk-mcp
  67. validate:
  68. name: Validate release candidate
  69. needs: [build, python-compat]
  70. runs-on: ubuntu-latest
  71. timeout-minutes: 10
  72. outputs:
  73. version: ${{ steps.version.outputs.version }}
  74. steps:
  75. - uses: actions/checkout@v6
  76. with:
  77. persist-credentials: false
  78. - uses: actions/setup-python@v6.3.0
  79. with:
  80. python-version: '3.10'
  81. - name: Resolve release version
  82. id: version
  83. run: |
  84. python3 - <<'PY' >> "$GITHUB_OUTPUT"
  85. import runpy
  86. release = runpy.run_path("scripts/build-python-release.py")
  87. repository_version = release["repository_version"]()
  88. wheel_version = release["pep440_version"](repository_version)
  89. print(f"repository-version={repository_version}")
  90. print(f"version={wheel_version}")
  91. PY
  92. - name: Authorize publication request
  93. env:
  94. PUBLISH: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }}
  95. PUBLIC_PYPI_RELEASE_ENABLED: ${{ vars.PUBLIC_PYPI_RELEASE_ENABLED }}
  96. PYPI_PUBLISHER_REPOSITORY: ${{ vars.PYPI_PUBLISHER_REPOSITORY }}
  97. REPOSITORY: ${{ github.repository }}
  98. REF_NAME: ${{ github.ref_name }}
  99. REF_TYPE: ${{ github.ref_type }}
  100. REPOSITORY_VERSION: ${{ steps.version.outputs.repository-version }}
  101. run: |
  102. set -euo pipefail
  103. if [ "$PUBLISH" = true ]; then
  104. [ -n "$PYPI_PUBLISHER_REPOSITORY" ] || {
  105. echo "::error::Set the repository variable PYPI_PUBLISHER_REPOSITORY before publication."
  106. exit 1
  107. }
  108. [ "$REPOSITORY" = "$PYPI_PUBLISHER_REPOSITORY" ] || {
  109. echo "::error::This repository is not the configured PyPI publisher repository."
  110. exit 1
  111. }
  112. [ "$PUBLIC_PYPI_RELEASE_ENABLED" = true ] || {
  113. echo "::error::Set PUBLIC_PYPI_RELEASE_ENABLED=true before public publication."
  114. exit 1
  115. }
  116. [ "$REF_TYPE" = tag ] && [ "$REF_NAME" = "python-v$REPOSITORY_VERSION" ] || {
  117. echo "::error::Publication must run from tag python-v$REPOSITORY_VERSION."
  118. exit 1
  119. }
  120. fi
  121. - uses: actions/download-artifact@v8
  122. with:
  123. pattern: deepseek_harness_*
  124. path: dist
  125. merge-multiple: true
  126. - name: Check release contents
  127. env:
  128. VERSION: ${{ steps.version.outputs.version }}
  129. run: |
  130. set -euo pipefail
  131. expected="$(mktemp)"
  132. actual="$(mktemp)"
  133. printf '%s\n' \
  134. "deepseek_harness_runtime_bin-$VERSION-py3-none-macosx_14_0_arm64.whl" \
  135. "deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_aarch64.whl" \
  136. "deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl" \
  137. "deepseek_harness_runtime_bin-$VERSION-py3-none-win_amd64.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