Update examples list in README #266
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| id-token: write # Required for OIDC | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # Unit tests run in parallel | |
| unit-tests: | |
| if: ${{ github.repository_owner == 'cloudflare' }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| outputs: | |
| version: ${{ steps.get-version.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: 'npm' | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build packages | |
| run: npm run build | |
| - name: Get package version | |
| id: get-version | |
| run: | | |
| VERSION=$(node -p "require('./packages/sandbox/package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Run sandbox unit tests | |
| run: | | |
| set +e | |
| timeout --preserve-status 30 npm run test -w @cloudflare/sandbox > sandbox_test.log 2>&1 | |
| EXIT_CODE=$? | |
| cat sandbox_test.log | |
| if grep -q "Test Files.*passed" sandbox_test.log && grep -q "Tests.*passed" sandbox_test.log; then | |
| echo "Sandbox tests passed" | |
| if [ $EXIT_CODE -eq 124 ] || [ $EXIT_CODE -eq 143 ]; then | |
| echo "::warning::Killed due to workerd shutdown hang (known vitest-pool-workers issue)" | |
| fi | |
| exit 0 | |
| else | |
| echo "Sandbox tests failed" | |
| exit 1 | |
| fi | |
| - name: Upload sandbox test logs | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: sandbox-test-logs-release | |
| path: sandbox_test.log | |
| retention-days: 7 | |
| - name: Run container unit tests | |
| run: npm run test -w @repo/sandbox-container | |
| # E2E tests - runs on every push to main | |
| e2e-tests: | |
| needs: [unit-tests] | |
| if: ${{ github.repository_owner == 'cloudflare' }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: 'npm' | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build packages | |
| run: npm run build | |
| - name: Generate wrangler config | |
| run: | | |
| cd tests/e2e/test-worker | |
| ./generate-config.sh sandbox-e2e-test-worker-main | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build test worker Docker images (base + python + opencode + standalone) | |
| run: | | |
| VERSION=${{ needs.unit-tests.outputs.version }} | |
| # Build base image (no Python) - used by Sandbox binding | |
| docker build -f packages/sandbox/Dockerfile --target default --platform linux/amd64 \ | |
| --build-arg SANDBOX_VERSION=$VERSION -t cloudflare/sandbox-test:$VERSION . | |
| # Build python image - used by SandboxPython binding | |
| docker build -f packages/sandbox/Dockerfile --target python --platform linux/amd64 \ | |
| --build-arg SANDBOX_VERSION=$VERSION -t cloudflare/sandbox-test:$VERSION-python . | |
| # Build opencode image - used by SandboxOpencode binding | |
| docker build -f packages/sandbox/Dockerfile --target opencode --platform linux/amd64 \ | |
| --build-arg SANDBOX_VERSION=$VERSION -t cloudflare/sandbox-test:$VERSION-opencode . | |
| # Build standalone image (arbitrary base with binary) - used by SandboxStandalone binding | |
| # Use regex to replace any version number, avoiding hardcoded version mismatch | |
| # Build from test-worker directory so COPY startup-test.sh works | |
| cd tests/e2e/test-worker | |
| sed -E "s|cloudflare/sandbox-test:[0-9]+\.[0-9]+\.[0-9]+|cloudflare/sandbox-test:$VERSION|g" \ | |
| Dockerfile.standalone > Dockerfile.standalone.tmp | |
| docker build -f Dockerfile.standalone.tmp --platform linux/amd64 \ | |
| -t cloudflare/sandbox-test:$VERSION-standalone . | |
| rm Dockerfile.standalone.tmp | |
| cd ../../.. | |
| - name: Deploy test worker | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: tests/e2e/test-worker | |
| command: deploy --name sandbox-e2e-test-worker-main | |
| - name: Run E2E tests | |
| env: | |
| TEST_WORKER_URL: https://sandbox-e2e-test-worker-main.agents-b8a.workers.dev | |
| run: npm run test:e2e | |
| - name: Cleanup test deployment | |
| if: always() | |
| continue-on-error: true | |
| run: | | |
| cd tests/e2e/test-worker | |
| ../../../scripts/cleanup-test-deployment.sh sandbox-e2e-test-worker-main | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| # Release publish - only runs if changesets exist | |
| publish-release: | |
| needs: [unit-tests, e2e-tests] | |
| if: ${{ github.repository_owner == 'cloudflare' }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| permissions: | |
| id-token: write # Required for trusted publishing | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Upgrade npm for OIDC trusted publishing | |
| run: npm install -g npm@latest | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build packages | |
| run: npm run build | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
| - name: Build and push Docker image (default) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: packages/sandbox/Dockerfile | |
| target: default | |
| platforms: linux/amd64 | |
| push: true | |
| tags: cloudflare/sandbox:${{ needs.unit-tests.outputs.version }} | |
| cache-from: type=gha,scope=release-default | |
| cache-to: type=gha,mode=max,scope=release-default | |
| build-args: | | |
| SANDBOX_VERSION=${{ needs.unit-tests.outputs.version }} | |
| - name: Build and push Docker image (python) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: packages/sandbox/Dockerfile | |
| target: python | |
| platforms: linux/amd64 | |
| push: true | |
| tags: cloudflare/sandbox:${{ needs.unit-tests.outputs.version }}-python | |
| cache-from: type=gha,scope=release-python | |
| cache-to: type=gha,mode=max,scope=release-python | |
| build-args: | | |
| SANDBOX_VERSION=${{ needs.unit-tests.outputs.version }} | |
| - name: Build and push Docker image (opencode) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: packages/sandbox/Dockerfile | |
| target: opencode | |
| platforms: linux/amd64 | |
| push: true | |
| tags: cloudflare/sandbox:${{ needs.unit-tests.outputs.version }}-opencode | |
| cache-from: type=gha,scope=release-opencode | |
| cache-to: type=gha,mode=max,scope=release-opencode | |
| build-args: | | |
| SANDBOX_VERSION=${{ needs.unit-tests.outputs.version }} | |
| - name: Extract standalone binary from Docker image | |
| run: | | |
| VERSION=${{ needs.unit-tests.outputs.version }} | |
| CONTAINER_ID=$(docker create --platform linux/amd64 cloudflare/sandbox:$VERSION) | |
| docker cp $CONTAINER_ID:/container-server/sandbox ./sandbox-linux-x64 | |
| docker rm $CONTAINER_ID | |
| file ./sandbox-linux-x64 | |
| ls -la ./sandbox-linux-x64 | |
| - id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| version: npx tsx .github/changeset-version.ts | |
| publish: npx tsx .github/changeset-publish.ts | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_CONFIG_PROVENANCE: true | |
| - name: Upload standalone binary to GitHub release | |
| if: steps.changesets.outputs.published == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION=${{ needs.unit-tests.outputs.version }} | |
| sha256sum sandbox-linux-x64 > sandbox-linux-x64.sha256 | |
| # Tag format matches changesets: @cloudflare/sandbox@VERSION | |
| gh release upload "@cloudflare/sandbox@${VERSION}" ./sandbox-linux-x64 ./sandbox-linux-x64.sha256 --clobber |