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

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