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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 or label a PR
  7. # `build-exe` (remove and reapply to rerun). Checkout uses the triggering ref,
  8. # so dispatch needs no separate ref input.
  9. on:
  10. workflow_dispatch:
  11. inputs:
  12. targets:
  13. description: >-
  14. Comma-separated pkg targets to build. Any subset of:
  15. node24-linux-x64, node24-linux-arm64, node24-macos-arm64.
  16. Empty builds all three.
  17. type: string
  18. required: false
  19. default: ''
  20. pull_request:
  21. types: [labeled]
  22. concurrency:
  23. group: ${{ github.workflow }}-${{ github.ref }}
  24. cancel-in-progress: true
  25. permissions:
  26. contents: read
  27. env:
  28. # CI runs must never report to the production telemetry endpoint baked
  29. # into apps/cli/cordis.yml (AppCLIEntry disables the row when set).
  30. DSH_TELEMETRY_DISABLED: '1'
  31. jobs:
  32. # Job-level conditions cannot inspect `matrix`, so validate target names and
  33. # construct the matrix before the dependent jobs.
  34. plan:
  35. name: plan targets
  36. if: github.event_name == 'workflow_dispatch' || github.event.label.name == 'build-exe'
  37. runs-on: ubuntu-latest
  38. timeout-minutes: 5
  39. outputs:
  40. matrix: ${{ steps.plan.outputs.matrix }}
  41. version: ${{ steps.version.outputs.version }}
  42. steps:
  43. - uses: actions/checkout@v6
  44. - name: Resolve repository version
  45. id: version
  46. run: |
  47. set -euo pipefail
  48. version="$(jq -r '.version // empty' package.json)"
  49. [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || {
  50. echo "::error::package.json version must be stable X.Y.Z, got '$version'"
  51. exit 1
  52. }
  53. echo "version=$version" >> "$GITHUB_OUTPUT"
  54. - name: Compute matrix from targets input
  55. id: plan
  56. env:
  57. # Label runs and blank dispatch inputs build all targets.
  58. TARGETS: ${{ inputs.targets || 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64' }}
  59. run: |
  60. set -euo pipefail
  61. matrix='[]'
  62. IFS=',' read -r -a targets <<< "$TARGETS"
  63. for raw in "${targets[@]}"; do
  64. t="$(echo "$raw" | xargs)" # trim surrounding whitespace
  65. [ -z "$t" ] && continue
  66. # Native-only: hosted arm64 Linux uses ubuntu-24.04-arm, while
  67. # macos-latest is Apple Silicon.
  68. case "$t" in
  69. node24-linux-x64) runner=ubuntu-latest ;;
  70. node24-linux-arm64) runner=ubuntu-24.04-arm ;;
  71. node24-macos-arm64) runner=macos-latest ;;
  72. *)
  73. echo "::error::Unknown target '$t'. Supported: node24-linux-x64, node24-linux-arm64, node24-macos-arm64."
  74. exit 1
  75. ;;
  76. esac
  77. matrix="$(jq -c --arg target "$t" --arg runner "$runner" '. + [{target: $target, runner: $runner}]' <<< "$matrix")"
  78. done
  79. if [ "$matrix" = '[]' ]; then
  80. echo "::error::The targets input selected nothing to build."
  81. exit 1
  82. fi
  83. echo "Matrix: $matrix"
  84. echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
  85. sdk-wheel:
  86. needs: plan
  87. name: deepseek_harness-${{ needs.plan.outputs.version }}-py3-none-any.whl
  88. runs-on: ubuntu-latest
  89. timeout-minutes: 5
  90. steps:
  91. - uses: actions/checkout@v6
  92. - uses: actions/setup-python@v6.3.0
  93. with:
  94. python-version: '3.10'
  95. - name: Install Python build tooling
  96. run: python -m pip install uv==0.11.23
  97. - name: Build release-shaped SDK wheel
  98. run: >-
  99. python scripts/build-python-release.py
  100. --package sdk
  101. --output-dir dist-python
  102. - uses: actions/upload-artifact@v7
  103. with:
  104. name: deepseek_harness-${{ needs.plan.outputs.version }}-py3-none-any.whl
  105. path: dist-python/deepseek_harness-${{ needs.plan.outputs.version }}-py3-none-any.whl
  106. if-no-files-found: error
  107. build:
  108. needs: [plan, sdk-wheel]
  109. name: ${{ matrix.target }}
  110. runs-on: ${{ matrix.runner }}
  111. timeout-minutes: 45
  112. strategy:
  113. fail-fast: false
  114. matrix:
  115. include: ${{ fromJSON(needs.plan.outputs.matrix) }}
  116. steps:
  117. - uses: actions/checkout@v6
  118. - uses: pnpm/action-setup@v4
  119. # setup-node's built-in pnpm store cache keys on platform AND arch, so
  120. # the Linux architectures sharing runner.os stay on separate caches.
  121. - uses: actions/setup-node@v6
  122. with:
  123. node-version: 24
  124. cache: pnpm
  125. - uses: actions/setup-python@v6.3.0
  126. with:
  127. python-version: '3.10'
  128. - name: Install Python build tooling
  129. run: python -m pip install uv==0.11.23
  130. # Cache pkg's target Node binary; lockfile changes roll the
  131. # exact key while the restore prefix can seed its replacement.
  132. - uses: actions/cache@v4
  133. with:
  134. path: ~/.pkg-cache
  135. key: pkg-fetch-${{ matrix.target }}-${{ hashFiles('pnpm-lock.yaml') }}
  136. restore-keys: |
  137. pkg-fetch-${{ matrix.target }}-
  138. - name: Install (immutable)
  139. run: pnpm install --frozen-lockfile
  140. - name: Build single-exe
  141. run: pnpm exec tsx scripts/build-exe-for-python-sdk.ts --targets=${{ matrix.target }}
  142. - name: Resolve platform outputs
  143. id: runtime
  144. env:
  145. TARGET: ${{ matrix.target }}
  146. VERSION: ${{ needs.plan.outputs.version }}
  147. run: |
  148. set -euo pipefail
  149. platform="${TARGET#node24-}"
  150. exe="$PWD/dist-exe/dsh-jsonrpc-agent-pkg-$platform"
  151. [ -x "$exe" ] || { echo "::error::$exe missing or not executable"; exit 1; }
  152. case "$platform" in
  153. linux-x64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_x86_64.whl ;;
  154. linux-arm64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-manylinux_2_28_aarch64.whl ;;
  155. macos-arm64) wheel=deepseek_harness_runtime_bin-$VERSION-py3-none-macosx_11_0_arm64.whl ;;
  156. *) echo "::error::Unsupported runtime platform $platform"; exit 1 ;;
  157. esac
  158. echo "platform=$platform" >> "$GITHUB_OUTPUT"
  159. echo "exe=$exe" >> "$GITHUB_OUTPUT"
  160. echo "wheel=$wheel" >> "$GITHUB_OUTPUT"
  161. - name: Full-turn SDK, executable snapshot, and direct-binary smoke
  162. run: >-
  163. uv run --python 3.10 --group test --project python/sdk
  164. python scripts/smoke-python-runtime.py
  165. --scenario all
  166. --exe "${{ steps.runtime.outputs.exe }}"
  167. - name: Build release-shaped runtime wheel
  168. run: >-
  169. python scripts/build-python-release.py
  170. --package runtime
  171. --platform "${{ steps.runtime.outputs.platform }}"
  172. --runtime-exe "${{ steps.runtime.outputs.exe }}"
  173. --output-dir dist-python
  174. - uses: actions/download-artifact@v8
  175. with:
  176. name: deepseek_harness-${{ needs.plan.outputs.version }}-py3-none-any.whl
  177. path: dist-python
  178. - name: Install only the SDK into a clean venv and run zero-config
  179. env:
  180. VERSION: ${{ needs.plan.outputs.version }}
  181. run: |
  182. set -euo pipefail
  183. python -m venv "$RUNNER_TEMP/dsh-sdk-smoke"
  184. "$RUNNER_TEMP/dsh-sdk-smoke/bin/python" -m pip install \
  185. --find-links dist-python \
  186. deepseek-harness=="$VERSION"
  187. "$RUNNER_TEMP/dsh-sdk-smoke/bin/python" scripts/smoke-python-runtime.py \
  188. --scenario sdk-default
  189. - name: Check Linux GLIBC requirements
  190. if: runner.os == 'Linux'
  191. run: |
  192. set -euo pipefail
  193. readelf --version-info "${{ steps.runtime.outputs.exe }}" | tee glibc-versions.txt
  194. maximum="$(sed -n 's/.*Name: GLIBC_\([0-9.]*\).*/\1/p' glibc-versions.txt | sort -V | tail -1)"
  195. [ -n "$maximum" ] || { echo "::error::No GLIBC requirements found"; exit 1; }
  196. dpkg --compare-versions "$maximum" le 2.28 || {
  197. echo "::error::Executable requires GLIBC_$maximum but wheel claims manylinux_2_28"
  198. exit 1
  199. }
  200. - name: Run wheel in a manylinux 2.28 container
  201. if: runner.os == 'Linux'
  202. env:
  203. RUNNER_ARCH: ${{ runner.arch }}
  204. VERSION: ${{ needs.plan.outputs.version }}
  205. run: |
  206. set -euo pipefail
  207. case "$RUNNER_ARCH" in
  208. X64) image=quay.io/pypa/manylinux_2_28_x86_64 ;;
  209. ARM64) image=quay.io/pypa/manylinux_2_28_aarch64 ;;
  210. *) echo "::error::Unsupported Linux runner architecture $RUNNER_ARCH"; exit 1 ;;
  211. esac
  212. docker run --rm -e VERSION -v "$PWD:/work" -w /work "$image" bash -euxo pipefail -c '
  213. /opt/python/cp310-cp310/bin/python -m venv /tmp/dsh-sdk
  214. /tmp/dsh-sdk/bin/python -m pip install --find-links /work/dist-python deepseek-harness=="$VERSION"
  215. /tmp/dsh-sdk/bin/python /work/scripts/smoke-python-runtime.py --scenario sdk-default
  216. '
  217. - uses: actions/upload-artifact@v7
  218. with:
  219. name: ${{ steps.runtime.outputs.wheel }}
  220. path: dist-python/${{ steps.runtime.outputs.wheel }}
  221. if-no-files-found: error