Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

fix(release): build workspace dependencies before publishing (#1798)

Matt Brockmanc275393cbece
diff --git a/.changeset/four-masks-make.md b/.changeset/four-masks-make.md
new file mode 100644
index 000000000..74a208f83
--- /dev/null
+++ b/.changeset/four-masks-make.md
@@ -0,0 +1,5 @@
+---
+'@e2b/python-sdk': patch
+---
+
+Improve reliability for high-concurrency sandbox workloads by spreading envd traffic across four HTTP/2 connection pools. Set `E2B_ENVD_POOL_SHARDS` before importing the SDK to adjust the pool count.
diff --git a/.github/scripts/release.test.cjs b/.github/scripts/release.test.cjs
new file mode 100644
index 000000000..0c48c7ea5
--- /dev/null
+++ b/.github/scripts/release.test.cjs
@@ -0,0 +1,64 @@
+const assert = require('node:assert/strict')
+const { spawnSync } = require('node:child_process')
+const fs = require('node:fs')
+const os = require('node:os')
+const path = require('node:path')
+const { test } = require('node:test')
+
+const { scripts } = require('../../package.json')
+
+function publish(t, fail = '') {
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'e2b-release-'))
+ t.after(() => fs.rmSync(cwd, { recursive: true, force: true }))
+ const bin = path.join(cwd, 'bin')
+ fs.mkdirSync(bin)
+ // Never invoke a registry publisher. Record the real root script's commands.
+ fs.writeFileSync(
+ path.join(bin, 'pnpm'),
+ '#!/bin/sh\nprintf "%s\\n" "$*" >> "$RELEASE_COMMANDS"\n[ "$*" != "$FAIL_COMMAND" ]\n',
+ { mode: 0o755 }
+ )
+ const log = path.join(cwd, 'commands')
+ const result = spawnSync('sh', ['-c', scripts.publish], {
+ cwd,
+ env: {
+ ...process.env,
+ PATH: `${bin}${path.delimiter}${process.env.PATH}`,
+ RELEASE_COMMANDS: log,
+ FAIL_COMMAND: fail,
+ },
+ encoding: 'utf8',
+ })
+ return {
+ ...result,
+ commands: fs.readFileSync(log, 'utf8').trim().split('\n'),
+ }
+}
+
+const build = '--dir packages/js-sdk build'
+const python = 'run -r postPublish'
+const npm = 'changeset publish'
+
+test('builds the workspace SDK even when npm skips its already-published version', (t) => {
+ const result = publish(t)
+ assert.equal(result.status, 0, result.stderr)
+ assert.deepEqual(result.commands, [build, python, npm])
+})
+
+test('a dependency build failure prevents all publishing', (t) => {
+ const result = publish(t, build)
+ assert.notEqual(result.status, 0)
+ assert.deepEqual(result.commands, [build])
+})
+
+test('a Python publish failure prevents Changesets from tagging unpublished Python versions', (t) => {
+ const result = publish(t, python)
+ assert.notEqual(result.status, 0)
+ assert.deepEqual(result.commands, [build, python])
+})
+
+test('an npm failure remains a failed release after Python succeeds', (t) => {
+ const result = publish(t, npm)
+ assert.notEqual(result.status, 0)
+ assert.deepEqual(result.commands, [build, python, npm])
+})
diff --git a/.github/workflows/publish_packages.yml b/.github/workflows/publish_packages.yml
index a3565bbce..5b91b5b80 100644
--- a/.github/workflows/publish_packages.yml
+++ b/.github/workflows/publish_packages.yml
@@ -74,13 +74,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit new versions
+ id: commit
# Commit before publishing, because `changeset publish` tags whatever HEAD
# it publishes from — tagging afterwards is what left every tag on the
- # commit before its own version bump (SDK-298). Nothing in the tree
- # references the artifacts about to be uploaded, so the commit is already
- # complete. It stays local until something is actually published, so a
- # publish that uploads nothing leaves the branch untouched and the
- # changesets intact for a re-run.
+ # commit before its own version bump (SDK-298).
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
@@ -106,18 +103,11 @@ jobs:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
- name: Push new versions
- # Gate on the tags rather than on whether the publish step succeeded: they
- # are what has to end up reachable. `changeset publish` tags at HEAD and the
- # step above pushes them to origin, so if any exist — even from a publish
- # that then failed partway — the commit they point at has to land, or they
- # hang off no branch, which is the SDK-298 breakage this change prevents.
- if: always()
+ # A failed publish may have uploaded some Python packages before tagging.
+ # Preserve the versions after any attempt so a later release cannot reuse
+ # them for different contents.
+ if: always() && steps.commit.outcome == 'success' && steps.release.outcome != 'skipped'
run: |
- if [ -z "$(git tag --points-at HEAD)" ]; then
- echo "Nothing was published; the version bump stays local and the changesets are intact for a re-dispatch."
- exit 0
- fi
-
if ! git push; then
# A PR merged mid-release. Merge rather than rebase: the tags already
# point at this commit and rewriting it would strand them off the branch.
diff --git a/.github/workflows/release_tests.yml b/.github/workflows/release_tests.yml
new file mode 100644
index 000000000..2cfb6f41c
--- /dev/null
+++ b/.github/workflows/release_tests.yml
@@ -0,0 +1,33 @@
+name: Release tooling tests
+
+on:
+ pull_request:
+ paths:
+ - '.github/scripts/**'
+ - '.github/workflows/release*.yml'
+ - '.github/workflows/publish_packages.yml'
+ - 'package.json'
+ - 'pnpm-lock.yaml'
+
+permissions:
+ contents: read
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
+ - uses: wistia/parse-tool-versions@32f568a4ffd4bfa7720ebf93f171597d1ebc979a # v2.1.1
+ with:
+ filename: '.tool-versions'
+ uppercase: 'true'
+ prefix: 'tool_version_'
+ - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0
+ with:
+ version: '${{ env.TOOL_VERSION_PNPM }}'
+ - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
+ with:
+ node-version: '${{ env.TOOL_VERSION_NODEJS }}'
+ cache: pnpm
+ - run: pnpm install --frozen-lockfile
+ - run: pnpm run test:release
diff --git a/package.json b/package.json
index a89b5116b..5892e2a71 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,8 @@
"private": true,
"scripts": {
"version": "pnpm changeset version && pnpm run -r postVersion",
- "publish": "pnpm changeset publish && pnpm run -r postPublish",
+ "publish": "pnpm --dir packages/js-sdk build && pnpm run -r postPublish && pnpm changeset publish",
+ "test:release": "node --test .github/scripts/release.test.cjs",
"test": "pnpm --dir packages/js-sdk build && pnpm --recursive --if-present run test",
"rm-node-modules": "find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +",
"pnpm-install-hack": "cd packages/js-sdk && sed -i '' 's/\"version\": \".*\"/\"version\": \"9.9.9\"/g' package.json && cd ../.. && pnpm i && git checkout -- packages/js-sdk/package.json",