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

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