diff --git a/.github/workflows/build_test_template.yml b/.github/workflows/build_test_template.yml new file mode 100644 index 00000000..e8d6edb2 --- /dev/null +++ b/.github/workflows/build_test_template.yml @@ -0,0 +1,55 @@ +name: Build Template + +on: + workflow_call: + secrets: + E2B_TESTS_ACCESS_TOKEN: + required: true + inputs: + E2B_DOMAIN: + required: false + type: string + outputs: + template_id: + description: "The ID of the built template" + value: ${{ jobs.build.outputs.template_id }} + +permissions: + contents: read + +jobs: + build: + name: Build E2B Template + runs-on: ubuntu-latest + outputs: + template_id: ${{ steps.build-template.outputs.template_id }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set package version + working-directory: ./template + run: | + VERSION=$(cat ../chart_data_extractor/pyproject.toml | grep version | cut -d '"' -f 2) + echo "Version: $VERSION" + sed -i "s/e2b_charts/e2b_charts==${VERSION}/g" requirements.txt + + - name: Install E2B CLI + run: npm install -g @e2b/cli + + - name: Build E2B template + id: build-template + run: | + rm -f e2b.toml + e2b template build --memory-mb 1024 -c "/root/.jupyter/start-up.sh" -d "Dockerfile" + TEMPLATE_ID=$(grep "template_id" e2b.toml | cut -d '"' -f 2) + echo "Captured Template ID: $TEMPLATE_ID" + echo "template_id=$TEMPLATE_ID" >> $GITHUB_OUTPUT + working-directory: ./template + env: + E2B_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }} + E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }} + + - name: Output template ID + run: | + echo "Template ID from step output: ${{ steps.build-template.outputs.template_id }}" diff --git a/.github/workflows/charts_tests.yml b/.github/workflows/charts_tests.yml index 985e7d99..6cbc59e1 100644 --- a/.github/workflows/charts_tests.yml +++ b/.github/workflows/charts_tests.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 diff --git a/.github/workflows/cleanup_build_template.yml b/.github/workflows/cleanup_build_template.yml new file mode 100644 index 00000000..9878474c --- /dev/null +++ b/.github/workflows/cleanup_build_template.yml @@ -0,0 +1,33 @@ +name: Cleanup Build Template + +on: + workflow_call: + secrets: + E2B_TESTS_ACCESS_TOKEN: + required: true + inputs: + E2B_DOMAIN: + required: false + type: string + E2B_TESTS_TEMPLATE: + required: true + type: string + +permissions: + contents: read + +jobs: + cleanup: + name: Cleanup Build Template + runs-on: ubuntu-latest + steps: + - name: Install E2B CLI + run: npm install -g @e2b/cli + + - name: Cleanup E2B template + id: cleanup-template + run: | + e2b template delete -y "${{ inputs.E2B_TESTS_TEMPLATE }}" + env: + E2B_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }} + E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }} diff --git a/.github/workflows/js_tests.yml b/.github/workflows/js_tests.yml index f791115a..144603f6 100644 --- a/.github/workflows/js_tests.yml +++ b/.github/workflows/js_tests.yml @@ -5,6 +5,13 @@ on: secrets: E2B_API_KEY: required: true + inputs: + E2B_DOMAIN: + required: false + type: string + E2B_TESTS_TEMPLATE: + required: false + type: string permissions: contents: read @@ -18,7 +25,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v3 @@ -49,16 +56,20 @@ jobs: run: pnpm test env: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }} - name: Install Bun uses: oven-sh/setup-bun@v2 with: - version: 1.1.x + bun-version: 1.2.15 - name: Run Bun tests run: pnpm test:bun env: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }} - name: Install Deno uses: denoland/setup-deno@v1 @@ -69,3 +80,5 @@ jobs: run: pnpm test:deno env: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }} \ No newline at end of file diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 78b42016..29aa1e15 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -14,13 +14,36 @@ on: - main jobs: + build-template: + uses: ./.github/workflows/build_test_template.yml + secrets: + E2B_TESTS_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }} + with: + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} js-sdk: uses: ./.github/workflows/js_tests.yml + needs: build-template secrets: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + with: + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ needs.build-template.outputs.template_id }} python-sdk: uses: ./.github/workflows/python_tests.yml + needs: build-template secrets: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + with: + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ needs.build-template.outputs.template_id }} + cleanup-build-template: + uses: ./.github/workflows/cleanup_build_template.yml + needs: [build-template, js-sdk, python-sdk] + if: always() && !contains(needs.build-template.result, 'failure') && !contains(needs.build-template.result, 'cancelled') + secrets: + E2B_TESTS_ACCESS_TOKEN: ${{ secrets.E2B_TESTS_ACCESS_TOKEN }} + with: + E2B_DOMAIN: ${{ vars.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ needs.build-template.outputs.template_id }} charts-tests: uses: ./.github/workflows/charts_tests.yml diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index 5bb46fea..22c85536 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -5,6 +5,13 @@ on: secrets: E2B_API_KEY: required: true + inputs: + E2B_DOMAIN: + required: false + type: string + E2B_TESTS_TEMPLATE: + required: false + type: string permissions: contents: read @@ -18,7 +25,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 @@ -43,3 +50,5 @@ jobs: run: poetry run pytest --verbose -x env: E2B_API_KEY: ${{ secrets.E2B_API_KEY }} + E2B_DOMAIN: ${{ inputs.E2B_DOMAIN }} + E2B_TESTS_TEMPLATE: ${{ inputs.E2B_TESTS_TEMPLATE }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 523f8531..8ee6313b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: release: ${{ steps.version.outputs.release }} steps: - name: Checkout Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v3 @@ -60,7 +60,7 @@ jobs: template: ${{ steps.template.outputs.release }} steps: - name: Checkout Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v3 @@ -117,7 +117,7 @@ jobs: version: ${{ steps.output_version.outputs.version }} steps: - name: Checkout Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v3 @@ -177,9 +177,7 @@ jobs: (needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true') steps: - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -220,9 +218,7 @@ jobs: (needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true') steps: - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 + uses: actions/checkout@v4 - name: Install E2B CLI run: npm install -g @e2b/cli @@ -268,9 +264,8 @@ jobs: private-key: ${{ secrets.VERSION_BUMPER_SECRET }} - name: Checkout Repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: - fetch-depth: 0 token: ${{ steps.app-token.outputs.token }} diff --git a/js/tests/setup.ts b/js/tests/setup.ts index b4466365..52cd7c65 100644 --- a/js/tests/setup.ts +++ b/js/tests/setup.ts @@ -3,6 +3,8 @@ import { test as base } from 'vitest' const timeoutMs = 60_000 +const template = process.env.E2B_TESTS_TEMPLATE || 'code-interpreter-v1' + interface SandboxFixture { sandbox: Sandbox } @@ -10,7 +12,9 @@ interface SandboxFixture { export const sandboxTest = base.extend({ sandbox: [ async ({}, use) => { - const sandbox = await Sandbox.create({ timeoutMs }) + const sandbox = await Sandbox.create(template, { + timeoutMs, + }) try { await use(sandbox) } finally { diff --git a/python/tests/conftest.py b/python/tests/conftest.py index efb6c1d7..796eab91 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -11,8 +11,13 @@ @pytest.fixture() -def sandbox(debug): - sandbox = Sandbox(timeout=timeout) +def template(): + return os.getenv("E2B_TESTS_TEMPLATE", "code-interpreter-v1") + + +@pytest.fixture() +def sandbox(template, debug): + sandbox = Sandbox(template, timeout=timeout) try: yield sandbox @@ -27,14 +32,14 @@ def sandbox(debug): @pytest_asyncio.fixture -async def async_sandbox(debug): - sandbox = await AsyncSandbox.create(timeout=timeout) +async def async_sandbox(template, debug): + async_sandbox = await AsyncSandbox.create(template, timeout=timeout) try: - yield sandbox + yield async_sandbox finally: try: - await sandbox.kill() + await async_sandbox.kill() except: if not debug: warning(