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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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 or call it from the Python
  7. # release workflow. There is no `pull_request` trigger: a label trigger would
  8. # list gray skipped checks on every unrelated PR label event. Checkout uses the
  9. # triggering ref, so dispatch needs no separate ref input.
  10. on:
  11. workflow_call:
  12. inputs:
  13. targets:
  14. description: Comma-separated pkg targets to build; empty builds all four.
  15. type: string
  16. required: false
  17. default: ''
  18. release:
  19. description: Run as the native builder for the Python release workflow.
  20. type: boolean
  21. required: false
  22. default: false
  23. ci:
  24. description: Run as the required all-target Python runtime pull-request check.
  25. type: boolean
  26. required: false
  27. default: false
  28. secrets:
  29. DEEPSEEK_API_KEY_EXTERNAL:
  30. description: Real DeepSeek API key for trusted installed-wheel pull-request tests.
  31. required: false
  32. workflow_dispatch:
  33. inputs:
  34. targets:
  35. description: >-
  36. Comma-separated pkg targets to build. Any subset of:
  37. node24-linux-x64, node24-linux-arm64, node24-macos-arm64,
  38. node24-win-x64. Empty builds all four.
  39. type: string
  40. required: false
  41. default: ''
  42. concurrency:
  43. # Keep the called workflow distinct from its caller's concurrency group;
  44. # github.workflow identifies the caller inside a reusable workflow and keeps
  45. # an ordinary CI run from cancelling a full release validation on the same ref.
  46. group: build-single-exe-${{ github.workflow }}-${{ github.ref }}
  47. cancel-in-progress: true
  48. permissions:
  49. contents: read
  50. env:
  51. # CI runs must never report to the production telemetry endpoint baked
  52. # into apps/cli/cordis.yml (AppCLIEntry disables the row when set).
  53. DSH_TELEMETRY_DISABLED: '1'
  54. jobs:
  55. # Job-level conditions cannot inspect `matrix`, so validate target names and
  56. # construct the matrix before the dependent jobs.
  57. plan:
  58. name: plan targets
  59. if: inputs.ci || inputs.release || github.event_name == 'workflow_dispatch'
  60. runs-on: ubuntu-latest
  61. timeout-minutes: 5
  62. outputs:
  63. matrix: ${{ steps.plan.outputs.matrix }}
  64. version: ${{ steps.version.outputs.version }}
  65. repository-version: ${{ steps.version.outputs.repository-version }}
  66. steps:
  67. - uses: actions/checkout@v6
  68. - name: Resolve repository version
  69. id: version
  70. run: |
  71. set -euo pipefail
  72. python3 - <<'PY' >> "$GITHUB_OUTPUT"
  73. import runpy
  74. release = runpy.run_path("scripts/build-python-release.py")
  75. repository_version = release["repository_version"]()
  76. wheel_version = release["pep440_version"](repository_version)
  77. print(f"repository-version={repository_version}")
  78. print(f"version={wheel_version}")
  79. PY
  80. - name: Compute matrix from targets input
  81. id: plan
  82. env:
  83. # Blank dispatch inputs build all targets.
  84. TARGETS: ${{ inputs.targets || 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64,node24-win-x64' }}
  85. run: |
  86. set -euo pipefail
  87. matrix='[]'
  88. IFS=',' read -r -a targets <<< "$TARGETS"
  89. for raw in "${targets[@]}"; do
  90. t="$(echo "$raw" | xargs)" # trim surrounding whitespace
  91. [ -z "$t" ] && continue
  92. # Native-only: hosted arm64 Linux uses ubuntu-24.04-arm, while
  93. # macos-latest is Apple Silicon.
  94. case "$t" in
  95. node24-linux-x64) runner=ubuntu-latest ;;
  96. node24-linux-arm64) runner=ubuntu-24.04-arm ;;
  97. node24-macos-arm64) runner=macos-latest ;;
  98. node24-win-x64) runner=windows-2025 ;;
  99. *)
  100. echo "::error::Unknown target '$t'. Supported: node24-linux-x64, node24-linux-arm64, node24-macos-arm64, node24-win-x64."
  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. with:
  148. dest: ${{ runner.temp }}/setup-pnpm-js-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}
  149. - name: Enable Windows Developer Mode (symlink support)
  150. if: runner.os == 'Windows'
  151. shell: pwsh
  152. run: >-
  153. reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
  154. /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
  155. # setup-node's built-in pnpm store cache keys on platform AND arch, so
  156. # the Linux architectures sharing runner.os stay on separate caches.
  157. - uses: actions/setup-node@v6
  158. with:
  159. node-version: 24
  160. cache: pnpm
  161. - uses: actions/setup-python@v6.3.0
  162. with:
  163. python-version: '3.10'
  164. - name: Install Python build tooling
  165. run: python -m pip install uv==0.11.23
  166. # Cache pkg's target Node binary; lockfile changes roll the
  167. # exact key while the restore prefix can seed its replacement.
  168. - uses: actions/cache@v4
  169. with:
  170. path: ~/.pkg-cache
  171. key: pkg-fetch-${{ matrix.target }}-${{ hashFiles('pnpm-lock.yaml') }}
  172. restore-keys: |
  173. pkg-fetch-${{ matrix.target }}-
  174. - name: Install (immutable)
  175. run: pnpm install --frozen-lockfile
  176. - name: Rebuild Linux node-pty against manylinux 2.28
  177. if: runner.os == 'Linux'
  178. env:
  179. RUNNER_ARCH: ${{ runner.arch }}
  180. run: |
  181. set -euo pipefail
  182. case "$RUNNER_ARCH" in
  183. X64) image=quay.io/pypa/manylinux_2_28_x86_64 ;;
  184. ARM64) image=quay.io/pypa/manylinux_2_28_aarch64 ;;
  185. *) echo "::error::Unsupported Linux runner architecture $RUNNER_ARCH"; exit 1 ;;
  186. esac
  187. addon_dir="$(realpath packages/subprocess/subprocess-local/node_modules/node-pty)"
  188. pnpm_setup_root="$(realpath "$(dirname "$(dirname "$PNPM_HOME")")")"
  189. (cd "$addon_dir" && npm_config_build_from_source=true pnpm run install)
  190. addon="$addon_dir/build/Release/pty.node"
  191. [ -f "$addon_dir/build/Makefile" ] || {
  192. echo "::error::node-pty install did not generate $addon_dir/build/Makefile"
  193. exit 1
  194. }
  195. docker run --rm \
  196. --user "$(id -u):$(id -g)" \
  197. -v "$PWD:$PWD" \
  198. -v "$HOME/.cache/node-gyp:$HOME/.cache/node-gyp:ro" \
  199. -v "$pnpm_setup_root:$pnpm_setup_root:ro" \
  200. -w "$addon_dir" \
  201. "$image" \
  202. bash -euxo pipefail -c \
  203. 'rm -rf build/Release && make -C build -j2 BUILDTYPE=Release'
  204. [ -f "$addon" ] || { echo "::error::$addon missing after manylinux rebuild"; exit 1; }
  205. readelf --version-info "$addon" | tee node-pty-glibc-versions.txt
  206. maximum="$(sed -n 's/.*Name: GLIBC_\([0-9.]*\).*/\1/p' node-pty-glibc-versions.txt | sort -V | tail -1)"
  207. [ -n "$maximum" ] || { echo "::error::No GLIBC requirements found in $addon"; exit 1; }
  208. dpkg --compare-versions "$maximum" le 2.28 || {
  209. echo "::error::node-pty addon requires GLIBC_$maximum but wheel claims manylinux_2_28"
  210. exit 1
  211. }
  212. - name: Build single-exe
  213. env:
  214. DSH_BUILD_CLIENT_PROFILE: official
  215. run: pnpm exec tsx scripts/build-exe-for-python-sdk.ts --targets=${{ matrix.target }}
  216. - name: Resolve platform outputs (POSIX)
  217. id: runtime-posix
  218. if: runner.os != 'Windows'
  219. env:
  220. TARGET: ${{ matrix.target }}
  221. VERSION: ${{ needs.plan.outputs.version }}
  222. run: |
  223. set -euo pipefail
  224. platform="${TARGET#node24-}"
  225. exe="$PWD/dist-exe/deepseek-harness-sdk-runtime-$platform"
  226. case "$platform" in
  227. linux-x64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl ;;
  228. linux-arm64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_aarch64.whl ;;
  229. macos-arm64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-macosx_14_0_arm64.whl ;;
  230. *) echo "::error::Unsupported runtime platform $platform"; exit 1 ;;
  231. esac
  232. [ -x "$exe" ] || { echo "::error::$exe missing or not executable"; exit 1; }
  233. echo "platform=$platform" >> "$GITHUB_OUTPUT"
  234. echo "exe=$exe" >> "$GITHUB_OUTPUT"
  235. echo "wheel=$wheel" >> "$GITHUB_OUTPUT"
  236. - name: Resolve platform outputs (Windows)
  237. id: runtime-windows
  238. if: runner.os == 'Windows'
  239. shell: pwsh
  240. env:
  241. TARGET: ${{ matrix.target }}
  242. VERSION: ${{ needs.plan.outputs.version }}
  243. run: |
  244. if ($env:TARGET -ne 'node24-win-x64') { throw "Unsupported runtime target $env:TARGET" }
  245. $platform = 'win-x64'
  246. $exe = Join-Path $PWD 'dist-exe\deepseek-harness-sdk-runtime-win-x64.exe'
  247. $wheel = "deepseek_harness_runtime_bin-$env:VERSION-py3-none-win_amd64.whl"
  248. if (-not (Test-Path -LiteralPath $exe -PathType Leaf)) { throw "Runtime executable is missing at $exe" }
  249. "platform=$platform" >> $env:GITHUB_OUTPUT
  250. "exe=$exe" >> $env:GITHUB_OUTPUT
  251. "wheel=$wheel" >> $env:GITHUB_OUTPUT
  252. - name: Build release-shaped runtime wheel
  253. run: >-
  254. python scripts/build-python-release.py
  255. --package runtime
  256. --platform "${{ steps.runtime-posix.outputs.platform || steps.runtime-windows.outputs.platform }}"
  257. --runtime-exe "${{ steps.runtime-posix.outputs.exe || steps.runtime-windows.outputs.exe }}"
  258. --output-dir dist-python
  259. - uses: actions/download-artifact@v8
  260. with:
  261. name: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  262. path: dist-python
  263. - name: Install local SDK and runtime wheels into a clean venv (POSIX)
  264. id: smoke-venv-posix
  265. if: runner.os != 'Windows'
  266. env:
  267. RUNTIME_WHEEL: ${{ steps.runtime-posix.outputs.wheel }}
  268. SDK_WHEEL: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  269. run: |
  270. set -euo pipefail
  271. venv="$(python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-smoke-"))')"
  272. python -m venv "$venv"
  273. smoke_python="$venv/bin/python"
  274. "$smoke_python" -m pip install \
  275. "dist-python/$SDK_WHEEL" \
  276. "dist-python/$RUNTIME_WHEEL"
  277. echo "python=$smoke_python" >> "$GITHUB_OUTPUT"
  278. - name: Install local SDK and runtime wheels into a clean venv (Windows)
  279. id: smoke-venv-windows
  280. if: runner.os == 'Windows'
  281. shell: pwsh
  282. env:
  283. RUNTIME_WHEEL: ${{ steps.runtime-windows.outputs.wheel }}
  284. SDK_WHEEL: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  285. run: |
  286. $venv = (& python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-smoke-"))').Trim()
  287. python -m venv $venv
  288. $smokePython = Join-Path $venv 'Scripts\python.exe'
  289. & $smokePython -m pip install "dist-python/$env:SDK_WHEEL" "dist-python/$env:RUNTIME_WHEEL"
  290. if ($LASTEXITCODE -ne 0) { throw "Wheel installation failed with exit code $LASTEXITCODE" }
  291. "python=$smokePython" >> $env:GITHUB_OUTPUT
  292. - name: Run installed-wheel keyless black-box tests (POSIX)
  293. if: runner.os != 'Windows'
  294. run: |
  295. set -euo pipefail
  296. blackbox_root="$(python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-blackbox-"))')"
  297. cd "$blackbox_root"
  298. env -u PYTHONPATH -u DSH_RUNTIME_MODE \
  299. "${{ steps.smoke-venv-posix.outputs.python }}" \
  300. "$GITHUB_WORKSPACE/scripts/smoke-python-runtime.py" \
  301. --scenario all \
  302. --installed-wheel
  303. - name: Run installed-wheel keyless black-box tests (Windows)
  304. if: runner.os == 'Windows'
  305. shell: pwsh
  306. run: |
  307. $blackboxRoot = (& python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-blackbox-"))').Trim()
  308. Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
  309. Remove-Item Env:DSH_RUNTIME_MODE -ErrorAction SilentlyContinue
  310. Push-Location $blackboxRoot
  311. try {
  312. & "${{ steps.smoke-venv-windows.outputs.python }}" "$env:GITHUB_WORKSPACE\scripts\smoke-python-runtime.py" --scenario all --installed-wheel
  313. if ($LASTEXITCODE -ne 0) { throw "Installed-wheel black-box failed with exit code $LASTEXITCODE" }
  314. } finally {
  315. Pop-Location
  316. }
  317. - name: Preflight installed-wheel real API test (POSIX)
  318. if: >-
  319. inputs.ci
  320. && runner.os != 'Windows'
  321. && (github.event_name != 'pull_request'
  322. || !(github.event.pull_request.head.repo.fork
  323. || github.event.pull_request.user.login == 'dependabot[bot]'))
  324. env:
  325. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  326. run: |
  327. set -euo pipefail
  328. if [ -z "${DEEPSEEK_API_KEY:-}" ]; then
  329. echo "::error::DEEPSEEK_API_KEY_EXTERNAL is empty; the installed-wheel real API test cannot self-skip."
  330. exit 1
  331. fi
  332. - name: Preflight installed-wheel real API test (Windows)
  333. if: >-
  334. inputs.ci
  335. && runner.os == 'Windows'
  336. && (github.event_name != 'pull_request'
  337. || !(github.event.pull_request.head.repo.fork
  338. || github.event.pull_request.user.login == 'dependabot[bot]'))
  339. shell: pwsh
  340. env:
  341. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  342. run: |
  343. if ([string]::IsNullOrWhiteSpace($env:DEEPSEEK_API_KEY)) {
  344. throw 'DEEPSEEK_API_KEY_EXTERNAL is empty; the installed-wheel real API test cannot self-skip.'
  345. }
  346. - name: Run installed-wheel real API black-box test (POSIX)
  347. if: >-
  348. inputs.ci
  349. && runner.os != 'Windows'
  350. && (github.event_name != 'pull_request'
  351. || !(github.event.pull_request.head.repo.fork
  352. || github.event.pull_request.user.login == 'dependabot[bot]'))
  353. env:
  354. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  355. DEEPSEEK_BASE_URL: https://api.deepseek.com
  356. run: |
  357. set -euo pipefail
  358. blackbox_root="$(python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-blackbox-live-"))')"
  359. cd "$blackbox_root"
  360. env -u PYTHONPATH -u DSH_RUNTIME_MODE \
  361. "${{ steps.smoke-venv-posix.outputs.python }}" \
  362. "$GITHUB_WORKSPACE/scripts/smoke-python-runtime.py" \
  363. --scenario sdk-live \
  364. --installed-wheel
  365. - name: Run installed-wheel real API black-box test (Windows)
  366. if: >-
  367. inputs.ci
  368. && runner.os == 'Windows'
  369. && (github.event_name != 'pull_request'
  370. || !(github.event.pull_request.head.repo.fork
  371. || github.event.pull_request.user.login == 'dependabot[bot]'))
  372. shell: pwsh
  373. env:
  374. DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY_EXTERNAL }}
  375. DEEPSEEK_BASE_URL: https://api.deepseek.com
  376. run: |
  377. $blackboxRoot = (& python -c 'import tempfile; print(tempfile.mkdtemp(prefix="dsh-sdk-blackbox-live-"))').Trim()
  378. Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue
  379. Remove-Item Env:DSH_RUNTIME_MODE -ErrorAction SilentlyContinue
  380. Push-Location $blackboxRoot
  381. try {
  382. & "${{ steps.smoke-venv-windows.outputs.python }}" "$env:GITHUB_WORKSPACE\scripts\smoke-python-runtime.py" --scenario sdk-live --installed-wheel
  383. if ($LASTEXITCODE -ne 0) { throw "Installed-wheel live API smoke failed with exit code $LASTEXITCODE" }
  384. } finally {
  385. Pop-Location
  386. }
  387. - name: Check Linux GLIBC requirements
  388. if: runner.os == 'Linux'
  389. run: |
  390. set -euo pipefail
  391. readelf --version-info "${{ steps.runtime-posix.outputs.exe }}" | tee glibc-versions.txt
  392. maximum="$(sed -n 's/.*Name: GLIBC_\([0-9.]*\).*/\1/p' glibc-versions.txt | sort -V | tail -1)"
  393. [ -n "$maximum" ] || { echo "::error::No GLIBC requirements found"; exit 1; }
  394. dpkg --compare-versions "$maximum" le 2.28 || {
  395. echo "::error::Executable requires GLIBC_$maximum but wheel claims manylinux_2_28"
  396. exit 1
  397. }
  398. - name: Check macOS deployment target
  399. if: runner.os == 'macOS'
  400. env:
  401. EXE: ${{ steps.runtime-posix.outputs.exe }}
  402. run: >-
  403. python3 scripts/check-macos-deployment-target.py
  404. "$EXE" "$EXE-spawn-helper"
  405. - name: Run wheel in a manylinux 2.28 container
  406. if: runner.os == 'Linux'
  407. env:
  408. RUNNER_ARCH: ${{ runner.arch }}
  409. RUNTIME_WHEEL: ${{ steps.runtime-posix.outputs.wheel }}
  410. SDK_WHEEL: deepseek_harness_sdk-${{ needs.plan.outputs.version }}-py3-none-any.whl
  411. run: |
  412. set -euo pipefail
  413. case "$RUNNER_ARCH" in
  414. X64) image=quay.io/pypa/manylinux_2_28_x86_64 ;;
  415. ARM64) image=quay.io/pypa/manylinux_2_28_aarch64 ;;
  416. *) echo "::error::Unsupported Linux runner architecture $RUNNER_ARCH"; exit 1 ;;
  417. esac
  418. docker run --rm -e RUNTIME_WHEEL -e SDK_WHEEL -e DSH_TELEMETRY_DISABLED -v "$PWD:/work" -w /work "$image" bash -euxo pipefail -c '
  419. /opt/python/cp310-cp310/bin/python -m venv /tmp/dsh-sdk
  420. /tmp/dsh-sdk/bin/python -m pip install "/work/dist-python/$SDK_WHEEL" "/work/dist-python/$RUNTIME_WHEEL"
  421. mkdir -p /tmp/dsh-sdk-manylinux-smoke
  422. cd /tmp/dsh-sdk-manylinux-smoke
  423. env -u PYTHONPATH -u DSH_RUNTIME_MODE /tmp/dsh-sdk/bin/python /work/scripts/smoke-python-runtime.py --scenario sdk-default --installed-wheel
  424. env -u PYTHONPATH -u DSH_RUNTIME_MODE /tmp/dsh-sdk/bin/python /work/scripts/smoke-python-runtime.py --scenario sdk-mcp --installed-wheel
  425. '
  426. - uses: actions/upload-artifact@v7
  427. with:
  428. name: ${{ steps.runtime-posix.outputs.wheel || steps.runtime-windows.outputs.wheel }}
  429. path: dist-python/${{ steps.runtime-posix.outputs.wheel || steps.runtime-windows.outputs.wheel }}
  430. if-no-files-found: error
  431. retention-days: 7