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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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 four 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 four.
  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. node24-win-x64. Empty builds all four.
  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,node24-win-x64' }}
  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. node24-win-x64) runner=windows-2025 ;;
  100. *)
  101. echo "::error::Unknown target '$t'. Supported: node24-linux-x64, node24-linux-arm64, node24-macos-arm64, node24-win-x64."
  102. exit 1
  103. ;;
  104. esac
  105. matrix="$(jq -c --arg target "$t" --arg runner "$runner" '. + [{target: $target, runner: $runner}]' <<< "$matrix")"
  106. done
  107. if [ "$matrix" = '[]' ]; then
  108. echo "::error::The targets input selected nothing to build."
  109. exit 1
  110. fi
  111. echo "Matrix: $matrix"
  112. echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
  113. sdk-wheel:
  114. needs: plan
  115. name: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  116. runs-on: ubuntu-latest
  117. timeout-minutes: 5
  118. steps:
  119. - uses: actions/checkout@v6
  120. - uses: actions/setup-python@v6.3.0
  121. with:
  122. python-version: '3.10'
  123. - name: Install Python build tooling
  124. run: python -m pip install uv==0.11.23
  125. - name: Build release-shaped SDK wheel
  126. run: >-
  127. python scripts/build-python-release.py
  128. --package sdk
  129. --output-dir dist-python
  130. - uses: actions/upload-artifact@v7
  131. with:
  132. name: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  133. path: dist-python/deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  134. if-no-files-found: error
  135. retention-days: 7
  136. build:
  137. needs: [plan, sdk-wheel]
  138. name: ${{ matrix.target }}
  139. runs-on: ${{ matrix.runner }}
  140. timeout-minutes: 45
  141. strategy:
  142. fail-fast: false
  143. matrix:
  144. include: ${{ fromJSON(needs.plan.outputs.matrix) }}
  145. steps:
  146. - uses: actions/checkout@v6
  147. - uses: pnpm/action-setup@v4
  148. with:
  149. dest: ${{ runner.temp }}/setup-pnpm-js
  150. - name: Enable Windows Developer Mode (symlink support)
  151. if: runner.os == 'Windows'
  152. shell: pwsh
  153. run: >-
  154. reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
  155. /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
  156. # setup-node's built-in pnpm store cache keys on platform AND arch, so
  157. # the Linux architectures sharing runner.os stay on separate caches.
  158. - uses: actions/setup-node@v6
  159. with:
  160. node-version: 24
  161. cache: pnpm
  162. - uses: actions/setup-python@v6.3.0
  163. with:
  164. python-version: '3.10'
  165. - name: Install Python build tooling
  166. run: python -m pip install uv==0.11.23
  167. # Cache pkg's target Node binary; lockfile changes roll the
  168. # exact key while the restore prefix can seed its replacement.
  169. - uses: actions/cache@v4
  170. with:
  171. path: ~/.pkg-cache
  172. key: pkg-fetch-${{ matrix.target }}-${{ hashFiles('pnpm-lock.yaml') }}
  173. restore-keys: |
  174. pkg-fetch-${{ matrix.target }}-
  175. - name: Install (immutable)
  176. run: pnpm install --frozen-lockfile
  177. - name: Rebuild Linux node-pty against manylinux 2.28
  178. if: runner.os == 'Linux'
  179. env:
  180. RUNNER_ARCH: ${{ runner.arch }}
  181. run: |
  182. set -euo pipefail
  183. case "$RUNNER_ARCH" in
  184. X64) image=quay.io/pypa/manylinux_2_28_x86_64 ;;
  185. ARM64) image=quay.io/pypa/manylinux_2_28_aarch64 ;;
  186. *) echo "::error::Unsupported Linux runner architecture $RUNNER_ARCH"; exit 1 ;;
  187. esac
  188. addon_dir="$(realpath packages/subprocess/subprocess-local/node_modules/node-pty)"
  189. pnpm_setup_root="$(realpath "$(dirname "$(dirname "$PNPM_HOME")")")"
  190. (cd "$addon_dir" && npm_config_build_from_source=true pnpm run install)
  191. addon="$addon_dir/build/Release/pty.node"
  192. [ -f "$addon_dir/build/Makefile" ] || {
  193. echo "::error::node-pty install did not generate $addon_dir/build/Makefile"
  194. exit 1
  195. }
  196. docker run --rm \
  197. --user "$(id -u):$(id -g)" \
  198. -v "$PWD:$PWD" \
  199. -v "$HOME/.cache/node-gyp:$HOME/.cache/node-gyp:ro" \
  200. -v "$pnpm_setup_root:$pnpm_setup_root:ro" \
  201. -w "$addon_dir" \
  202. "$image" \
  203. bash -euxo pipefail -c \
  204. 'rm -rf build/Release && make -C build -j2 BUILDTYPE=Release'
  205. [ -f "$addon" ] || { echo "::error::$addon missing after manylinux rebuild"; exit 1; }
  206. readelf --version-info "$addon" | tee node-pty-glibc-versions.txt
  207. maximum="$(sed -n 's/.*Name: GLIBC_\([0-9.]*\).*/\1/p' node-pty-glibc-versions.txt | sort -V | tail -1)"
  208. [ -n "$maximum" ] || { echo "::error::No GLIBC requirements found in $addon"; exit 1; }
  209. dpkg --compare-versions "$maximum" le 2.28 || {
  210. echo "::error::node-pty addon requires GLIBC_$maximum but wheel claims manylinux_2_28"
  211. exit 1
  212. }
  213. - name: Build single-exe
  214. env:
  215. DSH_BUILD_CLIENT_PROFILE: official
  216. run: pnpm exec tsx scripts/build-exe-for-python-sdk.ts --targets=${{ matrix.target }}
  217. - name: Resolve platform outputs (POSIX)
  218. id: runtime-posix
  219. if: runner.os != 'Windows'
  220. env:
  221. TARGET: ${{ matrix.target }}
  222. VERSION: ${{ needs.plan.outputs.version }}
  223. run: |
  224. set -euo pipefail
  225. platform="${TARGET#node24-}"
  226. exe="$PWD/dist-exe/deepseek-harness-sdk-runtime-$platform"
  227. case "$platform" in
  228. linux-x64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl ;;
  229. linux-arm64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_aarch64.whl ;;
  230. macos-arm64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-macosx_14_0_arm64.whl ;;
  231. *) echo "::error::Unsupported runtime platform $platform"; exit 1 ;;
  232. esac
  233. [ -x "$exe" ] || { echo "::error::$exe missing or not executable"; exit 1; }
  234. echo "platform=$platform" >> "$GITHUB_OUTPUT"
  235. echo "exe=$exe" >> "$GITHUB_OUTPUT"
  236. echo "wheel=$wheel" >> "$GITHUB_OUTPUT"
  237. - name: Resolve platform outputs (Windows)
  238. id: runtime-windows
  239. if: runner.os == 'Windows'
  240. shell: pwsh
  241. env:
  242. TARGET: ${{ matrix.target }}
  243. VERSION: ${{ needs.plan.outputs.version }}
  244. run: |
  245. if ($env:TARGET -ne 'node24-win-x64') { throw "Unsupported runtime target $env:TARGET" }
  246. $platform = 'win-x64'
  247. $exe = Join-Path $PWD 'dist-exe\deepseek-harness-sdk-runtime-win-x64.exe'
  248. $wheel = "deepseek_harness_runtime_bin-$env:VERSION-py3-none-win_amd64.whl"
  249. if (-not (Test-Path -LiteralPath $exe -PathType Leaf)) { throw "Runtime executable is missing at $exe" }
  250. "platform=$platform" >> $env:GITHUB_OUTPUT
  251. "exe=$exe" >> $env:GITHUB_OUTPUT
  252. "wheel=$wheel" >> $env:GITHUB_OUTPUT
  253. - name: Build release-shaped runtime wheel
  254. run: >-
  255. python scripts/build-python-release.py
  256. --package runtime
  257. --platform "${{ steps.runtime-posix.outputs.platform || steps.runtime-windows.outputs.platform }}"
  258. --runtime-exe "${{ steps.runtime-posix.outputs.exe || steps.runtime-windows.outputs.exe }}"
  259. --output-dir dist-python
  260. - uses: actions/download-artifact@v8
  261. with:
  262. name: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  263. path: dist-python
  264. - name: Install local SDK and runtime wheels into a clean venv (POSIX)
  265. id: smoke-venv-posix
  266. if: runner.os != 'Windows'
  267. env:
  268. RUNTIME_WHEEL: ${{ steps.runtime-posix.outputs.wheel }}
  269. SDK_WHEEL: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  270. run: |
  271. set -euo pipefail
  272. venv="$(python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-smoke-"))')"
  273. python -m venv "$venv"
  274. smoke_python="$venv/bin/python"
  275. "$smoke_python" -m pip install \
  276. "dist-python/$SDK_WHEEL" \
  277. "dist-python/$RUNTIME_WHEEL"
  278. echo "python=$smoke_python" >> "$GITHUB_OUTPUT"
  279. - name: Install local SDK and runtime wheels into a clean venv (Windows)
  280. id: smoke-venv-windows
  281. if: runner.os == 'Windows'
  282. shell: pwsh
  283. env:
  284. RUNTIME_WHEEL: ${{ steps.runtime-windows.outputs.wheel }}
  285. SDK_WHEEL: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  286. run: |
  287. $venv = (& python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-smoke-"))').Trim()
  288. python -m venv $venv
  289. $smokePython = Join-Path $venv 'Scripts\python.exe'
  290. & $smokePython -m pip install "dist-python/$env:SDK_WHEEL" "dist-python/$env:RUNTIME_WHEEL"
  291. if ($LASTEXITCODE -ne 0) { throw "Wheel installation failed with exit code $LASTEXITCODE" }
  292. "python=$smokePython" >> $env:GITHUB_OUTPUT
  293. - name: Run installed-wheel keyless black-box tests (POSIX)
  294. if: runner.os != 'Windows'
  295. run: |
  296. set -euo pipefail
  297. blackbox_root="$(python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-blackbox-"))')"
  298. cd "$blackbox_root"
  299. env -u PYTHONPATH -u DSH_RUNTIME_MODE \
  300. "${{ steps.smoke-venv-posix.outputs.python }}" \
  301. "$GITHUB_WORKSPACE/scripts/smoke-python-runtime.py" \
  302. --scenario all \
  303. --installed-wheel
  304. - name: Run installed-wheel keyless black-box tests (Windows)
  305. if: runner.os == 'Windows'
  306. shell: pwsh
  307. run: |
  308. $blackboxRoot = (& python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-blackbox-"))').Trim()
  309. Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
  310. Remove-Item Env:DSH_RUNTIME_MODE -ErrorAction SilentlyContinue
  311. Push-Location $blackboxRoot
  312. try {
  313. & "${{ steps.smoke-venv-windows.outputs.python }}" "$env:GITHUB_WORKSPACE\scripts\smoke-python-runtime.py" --scenario all --installed-wheel
  314. if ($LASTEXITCODE -ne 0) { throw "Installed-wheel black-box failed with exit code $LASTEXITCODE" }
  315. } finally {
  316. Pop-Location
  317. }
  318. - name: Preflight installed-wheel real API test (POSIX)
  319. if: >-
  320. inputs.ci
  321. && runner.os != 'Windows'
  322. && (github.event_name != 'pull_request'
  323. || !(github.event.pull_request.head.repo.fork
  324. || github.event.pull_request.user.login == 'dependabot[bot]'))
  325. env:
  326. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  327. run: |
  328. set -euo pipefail
  329. if [ -z "${DEEPSEEK_API_KEY:-}" ]; then
  330. echo "::error::DEEPSEEK_API_KEY_EXTERNAL is empty; the installed-wheel real API test cannot self-skip."
  331. exit 1
  332. fi
  333. - name: Preflight installed-wheel real API test (Windows)
  334. if: >-
  335. inputs.ci
  336. && runner.os == 'Windows'
  337. && (github.event_name != 'pull_request'
  338. || !(github.event.pull_request.head.repo.fork
  339. || github.event.pull_request.user.login == 'dependabot[bot]'))
  340. shell: pwsh
  341. env:
  342. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  343. run: |
  344. if ([string]::IsNullOrWhiteSpace($env:DEEPSEEK_API_KEY)) {
  345. throw 'DEEPSEEK_API_KEY_EXTERNAL is empty; the installed-wheel real API test cannot self-skip.'
  346. }
  347. - name: Run installed-wheel real API black-box test (POSIX)
  348. if: >-
  349. inputs.ci
  350. && runner.os != 'Windows'
  351. && (github.event_name != 'pull_request'
  352. || !(github.event.pull_request.head.repo.fork
  353. || github.event.pull_request.user.login == 'dependabot[bot]'))
  354. env:
  355. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  356. DEEPSEEK_BASE_URL: https://api.deepseek.com
  357. run: |
  358. set -euo pipefail
  359. blackbox_root="$(python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-blackbox-live-"))')"
  360. cd "$blackbox_root"
  361. env -u PYTHONPATH -u DSH_RUNTIME_MODE \
  362. "${{ steps.smoke-venv-posix.outputs.python }}" \
  363. "$GITHUB_WORKSPACE/scripts/smoke-python-runtime.py" \
  364. --scenario sdk-live \
  365. --installed-wheel
  366. - name: Run installed-wheel real API black-box test (Windows)
  367. if: >-
  368. inputs.ci
  369. && runner.os == 'Windows'
  370. && (github.event_name != 'pull_request'
  371. || !(github.event.pull_request.head.repo.fork
  372. || github.event.pull_request.user.login == 'dependabot[bot]'))
  373. shell: pwsh
  374. env:
  375. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  376. DEEPSEEK_BASE_URL: https://api.deepseek.com
  377. run: |
  378. $blackboxRoot = (& python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-blackbox-live-"))').Trim()
  379. Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
  380. Remove-Item Env:DSH_RUNTIME_MODE -ErrorAction SilentlyContinue
  381. Push-Location $blackboxRoot
  382. try {
  383. & "${{ steps.smoke-venv-windows.outputs.python }}" "$env:GITHUB_WORKSPACE\scripts\smoke-python-runtime.py" --scenario sdk-live --installed-wheel
  384. if ($LASTEXITCODE -ne 0) { throw "Installed-wheel live API smoke failed with exit code $LASTEXITCODE" }
  385. } finally {
  386. Pop-Location
  387. }
  388. - name: Check Linux GLIBC requirements
  389. if: runner.os == 'Linux'
  390. run: |
  391. set -euo pipefail
  392. readelf --version-info "${{ steps.runtime-posix.outputs.exe }}" | tee glibc-versions.txt
  393. maximum="$(sed -n 's/.*Name: GLIBC_\([0-9.]*\).*/\1/p' glibc-versions.txt | sort -V | tail -1)"
  394. [ -n "$maximum" ] || { echo "::error::No GLIBC requirements found"; exit 1; }
  395. dpkg --compare-versions "$maximum" le 2.28 || {
  396. echo "::error::Executable requires GLIBC_$maximum but wheel claims manylinux_2_28"
  397. exit 1
  398. }
  399. - name: Check macOS deployment target
  400. if: runner.os == 'macOS'
  401. env:
  402. EXE: ${{ steps.runtime-posix.outputs.exe }}
  403. run: >-
  404. python3 scripts/check-macos-deployment-target.py
  405. "$EXE" "$EXE-spawn-helper"
  406. - name: Run wheel in a manylinux 2.28 container
  407. if: runner.os == 'Linux'
  408. env:
  409. RUNNER_ARCH: ${{ runner.arch }}
  410. RUNTIME_WHEEL: ${{ steps.runtime-posix.outputs.wheel }}
  411. SDK_WHEEL: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  412. run: |
  413. set -euo pipefail
  414. case "$RUNNER_ARCH" in
  415. X64) image=quay.io/pypa/manylinux_2_28_x86_64 ;;
  416. ARM64) image=quay.io/pypa/manylinux_2_28_aarch64 ;;
  417. *) echo "::error::Unsupported Linux runner architecture $RUNNER_ARCH"; exit 1 ;;
  418. esac
  419. docker run --rm -e RUNTIME_WHEEL -e SDK_WHEEL -e DSH_TELEMETRY_DISABLED -v "$PWD:/work" -w /work "$image" bash -euxo pipefail -c '
  420. /opt/python/cp310-cp310/bin/python -m venv /tmp/dsh-sdk
  421. /tmp/dsh-sdk/bin/python -m pip install "/work/dist-python/$SDK_WHEEL" "/work/dist-python/$RUNTIME_WHEEL"
  422. mkdir -p /tmp/dsh-sdk-manylinux-smoke
  423. cd /tmp/dsh-sdk-manylinux-smoke
  424. env -u PYTHONPATH -u DSH_RUNTIME_MODE /tmp/dsh-sdk/bin/python /work/scripts/smoke-python-runtime.py --scenario sdk-default --installed-wheel
  425. env -u PYTHONPATH -u DSH_RUNTIME_MODE /tmp/dsh-sdk/bin/python /work/scripts/smoke-python-runtime.py --scenario sdk-mcp --installed-wheel
  426. '
  427. - uses: actions/upload-artifact@v7
  428. with:
  429. name: ${{ steps.runtime-posix.outputs.wheel || steps.runtime-windows.outputs.wheel }}
  430. path: dist-python/${{ steps.runtime-posix.outputs.wheel || steps.runtime-windows.outputs.wheel }}
  431. if-no-files-found: error
  432. retention-days: 7