Improve session initialization to check storage first #588
Workflow file for this run
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: Pull Request | |
| permissions: | |
| contents: read | |
| on: | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # Unit tests (client + container) | |
| unit-tests: | |
| timeout-minutes: 10 | |
| runs-on: ubuntu-latest | |
| 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-unit | |
| path: sandbox_test.log | |
| retention-days: 7 | |
| - name: Run container unit tests | |
| run: npm run test -w @repo/sandbox-container | |
| # E2E tests against deployed worker | |
| e2e-tests: | |
| needs: unit-tests | |
| if: ${{ !contains(github.event.pull_request.title, 'Version Packages') }} | |
| timeout-minutes: 30 | |
| runs-on: ubuntu-latest | |
| 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 | |
| # Set environment name (pr-X for PRs, branch name for pushes) | |
| - name: Set environment name | |
| id: env-name | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "env_name=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | |
| echo "worker_name=sandbox-e2e-test-worker-pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "env_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| echo "worker_name=sandbox-e2e-test-worker-${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| fi | |
| # Generate unique wrangler config for this PR/branch | |
| - name: Generate wrangler config | |
| run: | | |
| cd tests/e2e/test-worker | |
| ./generate-config.sh ${{ steps.env-name.outputs.worker_name }} | |
| # Build Docker image for test worker with caching | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build test worker Docker images (base + python) | |
| run: | | |
| VERSION=${{ needs.unit-tests.outputs.version || '0.0.0' }} | |
| # Build base image (no Python) - used by SandboxBase 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 Sandbox binding | |
| docker build -f packages/sandbox/Dockerfile --target python --platform linux/amd64 \ | |
| --build-arg SANDBOX_VERSION=$VERSION -t cloudflare/sandbox-test:$VERSION-python . | |
| # Deploy test worker using official Cloudflare action | |
| - name: Deploy test worker | |
| id: deploy | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| command: deploy --name ${{ steps.env-name.outputs.worker_name }} | |
| workingDirectory: tests/e2e/test-worker | |
| secrets: | | |
| AWS_ACCESS_KEY_ID | |
| AWS_SECRET_ACCESS_KEY | |
| CLOUDFLARE_ACCOUNT_ID | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| # Construct worker URL from worker name | |
| - name: Get deployment URL | |
| id: get-url | |
| run: | | |
| echo "worker_url=https://${{ steps.env-name.outputs.worker_name }}.agents-b8a.workers.dev" >> $GITHUB_OUTPUT | |
| # Run E2E tests against deployed worker | |
| - name: Run E2E tests | |
| run: npx vitest run --config vitest.e2e.config.ts | |
| env: | |
| TEST_WORKER_URL: ${{ steps.get-url.outputs.worker_url }} | |
| CI: true | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| # Note: Resources are NOT cleaned up after each run to speed up subsequent CI runs. | |
| # Cleanup happens via: | |
| # - cleanup.yml: Triggered when PR is closed | |
| # - cleanup-stale.yml: Daily cron job for orphaned/stale resources | |
| # Validate changesets don't contain internal packages | |
| validate-changesets: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| - name: Validate changesets | |
| run: node scripts/validate-changesets.js .changeset/*.md |