build-exe-for-python-sdk.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. name: Build single-exe
  2. # Native builds for the release targets; see
  3. # .agents/notes/implemented/architecture/2026-07-10-single-file-executable-sdk-runtime-distribution.md.
  4. # A full target run retains one SDK wheel and three runtime wheels; subset
  5. # dispatch retains the SDK wheel and selected runtime wheels. Bare executables
  6. # and source closures are test inputs. Run manually, label a PR `build-exe`
  7. # (remove and reapply to rerun), or call it from the Python release workflow.
  8. # Checkout uses the triggering ref, so dispatch needs no separate ref input.
  9. on:
  10. workflow_call:
  11. inputs:
  12. targets:
  13. description: Comma-separated pkg targets to build; empty builds all three.
  14. type: string
  15. required: false
  16. default: ''
  17. release:
  18. description: Run as the native builder for the Python release workflow.
  19. type: boolean
  20. required: false
  21. default: false
  22. ci:
  23. description: Run as the required Linux x64 Python runtime pull-request check.
  24. type: boolean
  25. required: false
  26. default: false
  27. workflow_dispatch:
  28. inputs:
  29. targets:
  30. description: >-
  31. Comma-separated pkg targets to build. Any subset of:
  32. node24-linux-x64, node24-linux-arm64, node24-macos-arm64.
  33. Empty builds all three.
  34. type: string
  35. required: false
  36. default: ''
  37. pull_request:
  38. types: [labeled]
  39. concurrency:
  40. # Keep the called workflow distinct from its caller's concurrency group;
  41. # github.workflow identifies the caller inside a reusable workflow and keeps
  42. # an ordinary CI run from cancelling a full release validation on the same ref.
  43. group: build-single-exe-${{ github.workflow }}-${{ github.ref }}
  44. cancel-in-progress: true
  45. permissions:
  46. contents: read
  47. env:
  48. DSH_CLIENT_BRAND: official
  49. # CI runs must never report to the production telemetry endpoint baked
  50. # into apps/cli/cordis.yml (AppCLIEntry disables the row when set).
  51. DSH_TELEMETRY_DISABLED: '1'
  52. jobs:
  53. # Job-level conditions cannot inspect `matrix`, so validate target names and
  54. # construct the matrix before the dependent jobs.
  55. plan:
  56. name: plan targets
  57. if: inputs.ci || inputs.release || github.event_name == 'workflow_dispatch' || github.event.label.name == 'build-exe'
  58. runs-on: ubuntu-latest
  59. timeout-minutes: 5
  60. outputs:
  61. matrix: ${{ steps.plan.outputs.matrix }}
  62. version: ${{ steps.version.outputs.version }}
  63. repository-version: ${{ steps.version.outputs.repository-version }}
  64. steps:
  65. - uses: actions/checkout@v6
  66. - name: Resolve repository version
  67. id: version
  68. run: |
  69. set -euo pipefail
  70. python3 - <<'PY' >> "$GITHUB_OUTPUT"
  71. import runpy
  72. release = runpy.run_path("scripts/build-python-release.py")
  73. repository_version = release["repository_version"]()
  74. wheel_version = release["pep440_version"](repository_version)
  75. print(f"repository-version={repository_version}")
  76. print(f"version={wheel_version}")
  77. PY
  78. - name: Compute matrix from targets input
  79. id: plan
  80. env:
  81. # Label runs and blank dispatch inputs build all targets.
  82. TARGETS: ${{ inputs.targets || 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64' }}
  83. run: |
  84. set -euo pipefail
  85. matrix='[]'
  86. IFS=',' read -r -a targets <<< "$TARGETS"
  87. for raw in "${targets[@]}"; do
  88. t="$(echo "$raw" | xargs)" # trim surrounding whitespace
  89. [ -z "$t" ] && continue
  90. # Native-only: hosted arm64 Linux uses ubuntu-24.04-arm, while
  91. # macos-latest is Apple Silicon.
  92. case "$t" in
  93. node24-linux-x64) runner=ubuntu-latest ;;
  94. node24-linux-arm64) runner=ubuntu-24.04-arm ;;
  95. node24-macos-arm64) runner=macos-latest ;;
  96. *)
  97. echo "::error::Unknown target '$t'. Supported: node24-linux-x64, node24-linux-arm64, node24-macos-arm64."
  98. exit 1
  99. ;;
  100. esac
  101. matrix="$(jq -c --arg target "$t" --arg runner "$runner" '. + [{target: $target, runner: $runner}]' <<< "$matrix")"
  102. done
  103. if [ "$matrix" = '[]' ]; then
  104. echo "::error::The targets input selected nothing to build."
  105. exit 1
  106. fi
  107. echo "Matrix: $matrix"
  108. echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
  109. sdk-wheel:
  110. needs: plan
  111. name: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  112. runs-on: ubuntu-latest
  113. timeout-minutes: 5
  114. steps:
  115. - uses: actions/checkout@v6
  116. - uses: actions/setup-python@v6.3.0
  117. with:
  118. python-version: '3.10'
  119. - name: Install Python build tooling
  120. run: python -m pip install uv==0.11.23
  121. - name: Build release-shaped SDK wheel
  122. run: >-
  123. python scripts/build-python-release.py
  124. --package sdk
  125. --output-dir dist-python
  126. - uses: actions/upload-artifact@v7
  127. with:
  128. name: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  129. path: dist-python/deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  130. if-no-files-found: error
  131. retention-days: 7
  132. build:
  133. needs: [plan, sdk-wheel]
  134. name: ${{ matrix.target }}
  135. runs-on: ${{ matrix.runner }}
  136. timeout-minutes: 45
  137. strategy:
  138. fail-fast: false
  139. matrix:
  140. include: ${{ fromJSON(needs.plan.outputs.matrix) }}
  141. steps:
  142. - uses: actions/checkout@v6
  143. - uses: pnpm/action-setup@v4
  144. # setup-node's built-in pnpm store cache keys on platform AND arch, so
  145. # the Linux architectures sharing runner.os stay on separate caches.
  146. - uses: actions/setup-node@v6
  147. with:
  148. node-version: 24
  149. cache: pnpm
  150. - uses: actions/setup-python@v6.3.0
  151. with:
  152. python-version: '3.10'
  153. - name: Install Python build tooling
  154. run: python -m pip install uv==0.11.23
  155. # Cache pkg's target Node binary; lockfile changes roll the
  156. # exact key while the restore prefix can seed its replacement.
  157. - uses: actions/cache@v4
  158. with:
  159. path: ~/.pkg-cache
  160. key: pkg-fetch-${{ matrix.target }}-${{ hashFiles('pnpm-lock.yaml') }}
  161. restore-keys: |
  162. pkg-fetch-${{ matrix.target }}-
  163. - name: Install (immutable)
  164. run: pnpm install --frozen-lockfile
  165. - name: Rebuild Linux node-pty against manylinux 2.28
  166. if: runner.os == 'Linux'
  167. env:
  168. RUNNER_ARCH: ${{ runner.arch }}
  169. run: |
  170. set -euo pipefail
  171. case "$RUNNER_ARCH" in
  172. X64) image=quay.io/pypa/manylinux_2_28_x86_64 ;;
  173. ARM64) image=quay.io/pypa/manylinux_2_28_aarch64 ;;
  174. *) echo "::error::Unsupported Linux runner architecture $RUNNER_ARCH"; exit 1 ;;
  175. esac
  176. addon_dir="$(realpath packages/subprocess/subprocess-local/node_modules/node-pty)"
  177. (cd "$addon_dir" && npm_config_build_from_source=true pnpm run install)
  178. addon="$addon_dir/build/Release/pty.node"
  179. [ -f "$addon_dir/build/Makefile" ] || {
  180. echo "::error::node-pty install did not generate $addon_dir/build/Makefile"
  181. exit 1
  182. }
  183. docker run --rm \
  184. --user "$(id -u):$(id -g)" \
  185. -v "$PWD:$PWD" \
  186. -v "$HOME/.cache/node-gyp:$HOME/.cache/node-gyp:ro" \
  187. -v "$HOME/setup-pnpm:$HOME/setup-pnpm:ro" \
  188. -w "$addon_dir" \
  189. "$image" \
  190. bash -euxo pipefail -c \
  191. 'rm -rf build/Release && make -C build -j2 BUILDTYPE=Release'
  192. [ -f "$addon" ] || { echo "::error::$addon missing after manylinux rebuild"; exit 1; }
  193. readelf --version-info "$addon" | tee node-pty-glibc-versions.txt
  194. maximum="$(sed -n 's/.*Name: GLIBC_\([0-9.]*\).*/\1/p' node-pty-glibc-versions.txt | sort -V | tail -1)"
  195. [ -n "$maximum" ] || { echo "::error::No GLIBC requirements found in $addon"; exit 1; }
  196. dpkg --compare-versions "$maximum" le 2.28 || {
  197. echo "::error::node-pty addon requires GLIBC_$maximum but wheel claims manylinux_2_28"
  198. exit 1
  199. }
  200. - name: Build single-exe
  201. run: pnpm exec tsx scripts/build-exe-for-python-sdk.ts --targets=${{ matrix.target }}
  202. - name: Resolve platform outputs
  203. id: runtime
  204. env:
  205. TARGET: ${{ matrix.target }}
  206. VERSION: ${{ needs.plan.outputs.version }}
  207. run: |
  208. set -euo pipefail
  209. platform="${TARGET#node24-}"
  210. exe="$PWD/dist-exe/dsh-jsonrpc-agent-pkg-$platform"
  211. [ -x "$exe" ] || { echo "::error::$exe missing or not executable"; exit 1; }
  212. case "$platform" in
  213. linux-x64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl ;;
  214. linux-arm64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_aarch64.whl ;;
  215. macos-arm64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-macosx_14_0_arm64.whl ;;
  216. *) echo "::error::Unsupported runtime platform $platform"; exit 1 ;;
  217. esac
  218. echo "platform=$platform" >> "$GITHUB_OUTPUT"
  219. echo "exe=$exe" >> "$GITHUB_OUTPUT"
  220. echo "wheel=$wheel" >> "$GITHUB_OUTPUT"
  221. - name: Full-turn SDK, executable snapshot, and direct-binary smoke
  222. run: >-
  223. uv run --python 3.10 --group test --project python/sdk
  224. python scripts/smoke-python-runtime.py
  225. --scenario all
  226. --exe "${{ steps.runtime.outputs.exe }}"
  227. - name: Build release-shaped runtime wheel
  228. run: >-
  229. python scripts/build-python-release.py
  230. --package runtime
  231. --platform "${{ steps.runtime.outputs.platform }}"
  232. --runtime-exe "${{ steps.runtime.outputs.exe }}"
  233. --output-dir dist-python
  234. - uses: actions/download-artifact@v8
  235. with:
  236. name: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  237. path: dist-python
  238. - name: Install local SDK and runtime wheels into a clean venv
  239. env:
  240. RUNTIME_WHEEL: ${{ steps.runtime.outputs.wheel }}
  241. SDK_WHEEL: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  242. run: |
  243. set -euo pipefail
  244. python -m venv "$RUNNER_TEMP/dsh-sdk-smoke"
  245. "$RUNNER_TEMP/dsh-sdk-smoke/bin/python" -m pip install \
  246. "dist-python/$SDK_WHEEL" \
  247. "dist-python/$RUNTIME_WHEEL"
  248. "$RUNNER_TEMP/dsh-sdk-smoke/bin/python" scripts/smoke-python-runtime.py \
  249. --scenario sdk-default
  250. "$RUNNER_TEMP/dsh-sdk-smoke/bin/python" scripts/smoke-python-runtime.py \
  251. --scenario sdk-mcp
  252. - name: Check Linux GLIBC requirements
  253. if: runner.os == 'Linux'
  254. run: |
  255. set -euo pipefail
  256. readelf --version-info "${{ steps.runtime.outputs.exe }}" | tee glibc-versions.txt
  257. maximum="$(sed -n 's/.*Name: GLIBC_\([0-9.]*\).*/\1/p' glibc-versions.txt | sort -V | tail -1)"
  258. [ -n "$maximum" ] || { echo "::error::No GLIBC requirements found"; exit 1; }
  259. dpkg --compare-versions "$maximum" le 2.28 || {
  260. echo "::error::Executable requires GLIBC_$maximum but wheel claims manylinux_2_28"
  261. exit 1
  262. }
  263. - name: Check macOS deployment target
  264. if: runner.os == 'macOS'
  265. env:
  266. EXE: ${{ steps.runtime.outputs.exe }}
  267. run: >-
  268. python3 scripts/check-macos-deployment-target.py
  269. "$EXE" "$EXE-spawn-helper"
  270. - name: Run wheel in a manylinux 2.28 container
  271. if: runner.os == 'Linux'
  272. env:
  273. RUNNER_ARCH: ${{ runner.arch }}
  274. RUNTIME_WHEEL: ${{ steps.runtime.outputs.wheel }}
  275. SDK_WHEEL: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  276. run: |
  277. set -euo pipefail
  278. case "$RUNNER_ARCH" in
  279. X64) image=quay.io/pypa/manylinux_2_28_x86_64 ;;
  280. ARM64) image=quay.io/pypa/manylinux_2_28_aarch64 ;;
  281. *) echo "::error::Unsupported Linux runner architecture $RUNNER_ARCH"; exit 1 ;;
  282. esac
  283. docker run --rm -e RUNTIME_WHEEL -e SDK_WHEEL -e DSH_TELEMETRY_DISABLED -v "$PWD:/work" -w /work "$image" bash -euxo pipefail -c '
  284. /opt/python/cp310-cp310/bin/python -m venv /tmp/dsh-sdk
  285. /tmp/dsh-sdk/bin/python -m pip install "/work/dist-python/$SDK_WHEEL" "/work/dist-python/$RUNTIME_WHEEL"
  286. /tmp/dsh-sdk/bin/python /work/scripts/smoke-python-runtime.py --scenario sdk-default
  287. /tmp/dsh-sdk/bin/python /work/scripts/smoke-python-runtime.py --scenario sdk-mcp
  288. '
  289. - uses: actions/upload-artifact@v7
  290. with:
  291. name: ${{ steps.runtime.outputs.wheel }}
  292. path: dist-python/${{ steps.runtime.outputs.wheel }}
  293. if-no-files-found: error
  294. retention-days: 7