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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. name: Build single-exe
  2. # Single-file executable (single-exe) builds of the DeepSeek Harness SDK
  3. # runtime. The build pipeline and target platforms are specified in
  4. # docs/rfc/implemented/architecture/2026-07-10-single-file-executable-sdk-runtime-distribution.md:
  5. # each target is built natively on a runner of its own platform (no
  6. # cross-compilation) by scripts/build-exe-for-python-sdk.ts, which deploys
  7. # the dsh-jsonrpc-agent-pkg closure manifest with @yao-pkg/pkg into
  8. # dist-exe/.
  9. #
  10. # Each build leg uploads two artifacts:
  11. # - dsh-jsonrpc-agent-pkg-<target> — the bare single-file exe, for
  12. # consumers that want just the binary.
  13. # - deepseek-harness-python-<target> — the whole python/ directory as a
  14. # tar.gz with that exe already embedded (the build script syncs it into
  15. # the Python runtime package): unpack and both packages pip install
  16. # as-is, the checked-in default runtime/cordis.yml is editable in
  17. # place, and the embedded exe also runs directly.
  18. #
  19. # Two explicit triggers, deliberately no per-commit CI: the exe is a
  20. # release-style deliverable, and the build (full pnpm build + pnpm deploy +
  21. # pkg across a 3-platform matrix, ~100MB per artifact) is far too expensive
  22. # to run on every push. Either dispatch it from the Actions tab, or put the
  23. # `build-exe` label on a pull request to build that PR's merge result
  24. # (remove and re-apply the label to rerun); any other label leaves the jobs
  25. # skipped. There is no `ref` input on purpose: actions/checkout already
  26. # checks out the ref the run was triggered on — the dispatched branch/tag,
  27. # or the PR merge ref.
  28. on:
  29. workflow_dispatch:
  30. inputs:
  31. targets:
  32. description: >-
  33. Comma-separated pkg targets to build. Any subset of:
  34. node24-linux-x64, node24-linux-arm64, node24-macos-arm64.
  35. Empty builds all three.
  36. type: string
  37. required: false
  38. default: ''
  39. pull_request:
  40. types: [labeled]
  41. # Runs on the same ref supersede each other (per branch/tag for dispatch,
  42. # per PR merge ref for label runs).
  43. concurrency:
  44. group: ${{ github.workflow }}-${{ github.ref }}
  45. cancel-in-progress: true
  46. # Least privilege: the jobs only read the repo; artifact upload needs no
  47. # extra scope.
  48. permissions:
  49. contents: read
  50. jobs:
  51. # Turn the `targets` input into the build matrix. The `matrix` context is
  52. # not available in a job-level `if:` (jobs.<job_id>.if only sees
  53. # github/needs/vars/inputs), so target selection happens here instead of
  54. # skipping matrix legs; an unknown target name fails the whole run loudly
  55. # instead of being silently ignored. The label gate lives here too: `build`
  56. # needs this job, so skipping it skips the whole run.
  57. plan:
  58. name: plan targets
  59. if: github.event_name == 'workflow_dispatch' || github.event.label.name == 'build-exe'
  60. runs-on: ubuntu-latest
  61. timeout-minutes: 5
  62. outputs:
  63. matrix: ${{ steps.plan.outputs.matrix }}
  64. steps:
  65. - name: Compute matrix from targets input
  66. id: plan
  67. env:
  68. # Empty on label runs and on dispatch with the input left blank —
  69. # both mean "all three targets".
  70. TARGETS: ${{ inputs.targets || 'node24-linux-x64,node24-linux-arm64,node24-macos-arm64' }}
  71. run: |
  72. set -euo pipefail
  73. matrix='[]'
  74. IFS=',' read -r -a targets <<< "$TARGETS"
  75. for raw in "${targets[@]}"; do
  76. t="$(echo "$raw" | xargs)" # trim surrounding whitespace
  77. [ -z "$t" ] && continue
  78. # Native builds only — each target maps to a runner of its own
  79. # platform: linux-arm64 uses GitHub's hosted arm64 label
  80. # ubuntu-24.04-arm (there is no ubuntu-latest-arm), macos-arm64
  81. # uses macos-latest (Apple Silicon since macos-14).
  82. case "$t" in
  83. node24-linux-x64) runner=ubuntu-latest ;;
  84. node24-linux-arm64) runner=ubuntu-24.04-arm ;;
  85. node24-macos-arm64) runner=macos-latest ;;
  86. *)
  87. echo "::error::Unknown target '$t'. Supported: node24-linux-x64, node24-linux-arm64, node24-macos-arm64."
  88. exit 1
  89. ;;
  90. esac
  91. matrix="$(jq -c --arg target "$t" --arg runner "$runner" '. + [{target: $target, runner: $runner}]' <<< "$matrix")"
  92. done
  93. if [ "$matrix" = '[]' ]; then
  94. echo "::error::The targets input selected nothing to build."
  95. exit 1
  96. fi
  97. echo "Matrix: $matrix"
  98. echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
  99. build:
  100. needs: plan
  101. name: ${{ matrix.target }}
  102. runs-on: ${{ matrix.runner }}
  103. timeout-minutes: 45
  104. strategy:
  105. fail-fast: false
  106. matrix:
  107. include: ${{ fromJSON(needs.plan.outputs.matrix) }}
  108. steps:
  109. - uses: actions/checkout@v6
  110. - uses: actions/setup-node@v6
  111. with:
  112. node-version: 24
  113. - name: Enable corepack (pnpm)
  114. run: corepack enable
  115. - name: Resolve pnpm store path
  116. id: pnpm-store
  117. run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
  118. # Unlike ci.yml (x64-only), this matrix spans two Linux architectures
  119. # that share runner.os, so runner.arch is part of the key.
  120. - uses: actions/cache@v4
  121. with:
  122. path: ${{ steps.pnpm-store.outputs.path }}
  123. key: ${{ runner.os }}-${{ runner.arch }}-node-24-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
  124. restore-keys: |
  125. ${{ runner.os }}-${{ runner.arch }}-node-24-pnpm-
  126. # The first run per target has pkg-fetch download yao-pkg's patched
  127. # Node binary into ~/.pkg-cache; cache it so later runs skip the
  128. # download. The target string pins Node major + platform + arch;
  129. # pnpm-lock.yaml rolls the key when @yao-pkg/pkg (and with it the
  130. # pinned patched-binary version) is bumped, with restore-keys still
  131. # seeding from the previous cache.
  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. # The script runs the whole pipeline itself (pnpm run build → pnpm
  141. # deploy --prod → pkg) and writes its output to dist-exe/ by default.
  142. - name: Build single-exe
  143. run: pnpm exec tsx scripts/build-exe-for-python-sdk.ts --targets=${{ matrix.target }}
  144. - uses: actions/upload-artifact@v6
  145. with:
  146. name: dsh-jsonrpc-agent-pkg-${{ matrix.target }}
  147. path: dist-exe/
  148. if-no-files-found: error
  149. # After the build step, python/ is already in its complete
  150. # distributable shape — the script synced this leg's exe into
  151. # python/sdk-runtime/src/deepseek_harness_runtime/runtime/ next to the
  152. # checked-in default cordis.yml — so packing is all that is left.
  153. # Everything goes under one top-level deepseek-harness-python/
  154. # directory so unpacking never scatters files. Shipping a tar (rather
  155. # than uploading the tree bare) preserves the exe's executable bit —
  156. # tar keeps file modes; upload-artifact's zip does not.
  157. #
  158. # Excluded: runtime/node/ (dev-only node-mode carrier, ~140MB) plus
  159. # __pycache__ / .pytest_cache / .venv / node_modules anywhere (install
  160. # or test leftovers); uv.lock stays in.
  161. #
  162. # Portability: GNU tar (ubuntu) and bsdtar (macos) both accept
  163. # `tar -czf out.tar.gz --exclude=… -C <parent> <dir>` and both treat
  164. # an excluded directory as pruned (no descent). The top-level rename
  165. # is done by copying into a temp dir first — GNU --transform / BSD -s
  166. # are single-implementation flags.
  167. - name: Pack Python SDK bundle
  168. id: pack
  169. env:
  170. TARGET: ${{ matrix.target }}
  171. run: |
  172. set -euo pipefail
  173. platform_arch="${TARGET#*-}" # node24-macos-arm64 -> macos-arm64
  174. exe="python/sdk-runtime/src/deepseek_harness_runtime/runtime/dsh-jsonrpc-agent-pkg-${platform_arch}"
  175. if [ ! -x "$exe" ]; then
  176. echo "::error::$exe missing or not executable — the build step did not sync this leg's exe into the Python runtime package; refusing to pack a half-empty bundle."
  177. exit 1
  178. fi
  179. staging="$(mktemp -d)"
  180. cp -R python "$staging/deepseek-harness-python"
  181. bundle="deepseek-harness-python-${platform_arch}.tar.gz"
  182. tar -czf "$bundle" \
  183. --exclude='deepseek-harness-python/sdk-runtime/src/deepseek_harness_runtime/runtime/node' \
  184. --exclude='__pycache__' \
  185. --exclude='.pytest_cache' \
  186. --exclude='.venv' \
  187. --exclude='node_modules' \
  188. -C "$staging" deepseek-harness-python
  189. rm -rf "$staging"
  190. ls -lh "$bundle"
  191. echo "bundle=$bundle" >> "$GITHUB_OUTPUT"
  192. - uses: actions/upload-artifact@v6
  193. with:
  194. name: deepseek-harness-python-${{ matrix.target }}
  195. path: ${{ steps.pack.outputs.bundle }}
  196. if-no-files-found: error