Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
910e9cd
boilerplate to generate api ref for js code interpreter
0div Nov 25, 2024
b7cb651
change python deps to allow pydoc-markdown to work
0div Nov 26, 2024
ff36efe
boilerplate to generate api ref for python code interpreter
0div Nov 26, 2024
9a7cecc
rebrand to SDK Reference
0div Nov 26, 2024
c46eba2
fix typefoc config out folder
0div Nov 26, 2024
43fdc0d
fix typos and better naming for python api ref
0div Nov 27, 2024
6994564
Merge branch 'main' of https://github.com/e2b-dev/code-interpreter in…
0div Nov 27, 2024
b1c2c3a
add sdk autogen workflow and make it a part of the release workflow
0div Nov 27, 2024
f3b08b6
trigger workflow on feature branch push
0div Nov 27, 2024
7177fc4
fix python path in install step
0div Nov 27, 2024
30a0335
fix path in show docs step
0div Nov 27, 2024
9c6f448
fix path in show docs step
0div Nov 27, 2024
1cc5b85
[skip ci] Release new Code Interpreter Python and JS SDK references d…
github-actions[bot] Nov 27, 2024
4f8bb9e
remove dredundant pkg diff step
0div Nov 27, 2024
6730cd2
Merge branch 'generate-api-reference-for-code-interpreter-sdk-e2b-123…
0div Nov 27, 2024
ccfcd33
make black and pydoc-markdown dev-deps
0div Nov 27, 2024
6022f33
include generate sdk workflow inside release workflow, make pnpm recu…
0div Nov 27, 2024
cdb01f2
remove sdk gen workflow call from release
0div Nov 27, 2024
1fcacd9
fix python package.json generate ref command
0div Nov 27, 2024
7b172d8
temporarily disable docker and template build for workflow testing pu…
0div Nov 27, 2024
494c5b4
[skip ci] Release new versions
github-actions[bot] Nov 27, 2024
41b157d
remove temp changes to test release workflow
0div Nov 27, 2024
1eb099a
Merge branch 'generate-api-reference-for-code-interpreter-sdk-e2b-123…
0div Nov 27, 2024
a154d0a
Update .github/workflows/release.yml
0div Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/scripts/is_new_sdk_ref.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

# This script checks for diffs in the js/ and python/ directory.
# If there are diffs, it means we need to generate new SDK references.
if git diff --name-only HEAD^ | grep -q '^js/\|^python/'; then
echo "true"
else
echo "false"
fi
144 changes: 77 additions & 67 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- main
# Remove after testing
- generate-api-reference-for-code-interpreter-sdk-e2b-1235

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand Down Expand Up @@ -154,74 +156,74 @@ jobs:
run: |
echo "::set-output name=version::$(pnpm pkg get version --workspaces=false | tr -d \\\")"

build-docker-image:
name: Build Docker Image
runs-on: ubuntu-latest
needs: [changes, charts-release]
if: always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
(needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true')
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set package version
working-directory: ./template
run: |
if [ -z "${{ needs.charts-release.outputs.version }}" ]; then
VERSION=$(cat ../chart_data_extractor/pyproject.toml | grep version | cut -d '"' -f 2)
else
VERSION=${{ needs.charts-release.outputs.version }}
fi
echo "Version: $VERSION"

sed -i "s/e2b_charts/e2b_charts==${VERSION}/g" requirements.txt

- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: ./template
push: true
platforms: linux/amd64
tags: ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest

build-template:
name: Build E2B template
runs-on: ubuntu-latest
needs: [build-docker-image]
if: always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install E2B CLI
run: npm install -g @e2b/cli

- name: Build e2b
run: e2b template build
working-directory: ./template
env:
E2B_ACCESS_TOKEN: ${{ secrets.E2B_ACCESS_TOKEN }}
#build-docker-image:
# name: Build Docker Image
# runs-on: ubuntu-latest
# needs: [changes, charts-release]
# if: always() &&
# !contains(needs.*.result, 'failure') &&
# !contains(needs.*.result, 'cancelled') &&
# (needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true')
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3
# with:
# fetch-depth: 0

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

# - name: Log in to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}

# - name: Set package version
# working-directory: ./template
# run: |
# if [ -z "${{ needs.charts-release.outputs.version }}" ]; then
# VERSION=$(cat ../chart_data_extractor/pyproject.toml | grep version | cut -d '"' -f 2)
# else
# VERSION=${{ needs.charts-release.outputs.version }}
# fi
# echo "Version: $VERSION"

# sed -i "s/e2b_charts/e2b_charts==${VERSION}/g" requirements.txt

# - name: Build Docker image
# uses: docker/build-push-action@v6
# with:
# context: ./template
# push: true
# platforms: linux/amd64
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest

#build-template:
# name: Build E2B template
# runs-on: ubuntu-latest
# needs: [build-docker-image]
# if: always() &&
# !contains(needs.*.result, 'failure') &&
# !contains(needs.*.result, 'cancelled') &&
# needs.changes.outputs.template == 'true' || needs.changes.outputs.charts == 'true'
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3
# with:
# fetch-depth: 0
# - name: Install E2B CLI
# run: npm install -g @e2b/cli

# - name: Build e2b
# run: e2b template build
# working-directory: ./template
# env:
# E2B_ACCESS_TOKEN: ${{ secrets.E2B_ACCESS_TOKEN }}

python-tests:
name: Python Tests
needs: [changes, build-template]
needs: [changes] #, build-template]
if: always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
Expand All @@ -231,7 +233,7 @@ jobs:

js-tests:
name: JS Tests
needs: [changes, build-template]
needs: [changes] #, build-template]
if: always() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
Expand Down Expand Up @@ -296,6 +298,13 @@ jobs:
run: pnpm run version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Generate SDK reference
id: sdk-ref
run: pnpm run --recursive generate-ref

- name: Show docs file structure
run: tree ./sdk-reference

- name: Release new versions
uses: changesets/action@v1
Expand All @@ -313,7 +322,8 @@ jobs:
- name: Commit new versions
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ./sdk-reference
git commit -am "[skip ci] Release new versions" || exit 0
git push
env:
Expand Down
6 changes: 5 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@e2b/code-interpreter",
"version": "1.0.4",
"packageManager": "[email protected]",
"description": "E2B Code Interpreter - Stateful code execution",
"homepage": "https://e2b.dev",
"license": "MIT",
Expand Down Expand Up @@ -32,7 +33,8 @@
"update-deps": "ncu -u && pnpm i",
"example": "npx tsx example.mts",
"test:bun": "bun test tests/runtimes/bun --env-file=.env",
"test:deno": "deno test tests/runtimes/deno/ --allow-net --allow-read --allow-env --unstable-sloppy-imports --trace-leaks"
"test:deno": "deno test tests/runtimes/deno/ --allow-net --allow-read --allow-env --unstable-sloppy-imports --trace-leaks",
"generate-ref": "./scripts/generate_sdk_ref.sh"
},
"devDependencies": {
"@types/node": "^18.18.6",
Expand All @@ -41,6 +43,8 @@
"knip": "^5.25.1",
"npm-check-updates": "^16.14.20",
"tsup": "^8.1.0",
"typedoc": "^0.26.8",
"typedoc-plugin-markdown": "^4.2.7",
"typescript": "^5.5.3",
"vitest": "^2.0.1"
},
Expand Down
64 changes: 64 additions & 0 deletions js/scripts/CustomMarkdownTheme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const { MarkdownTheme, MarkdownPageEvent } = require('typedoc-plugin-markdown')

function load(app) {
// Listen to the render event
app.renderer.on(MarkdownPageEvent.END, (page) => {
// Remove Markdown links from the document contents
page.contents = removeMarkdownLinks(
removeFirstNLines(
convertH5toH3(removeLinesWithConditions(page.contents)),
6
)
)
})
}

// this is a hacky way to make methods in the js-sdk sdk reference look more prominent
function convertH5toH3(text) {
return text.replace(/^##### (.*)$/gm, '### $1')
}

// Function to remove Markdown-style links
function removeMarkdownLinks(text) {
// Regular expression to match Markdown links [text](url)
return text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') // Replace with just the link text
}

function removeFirstNLines(text, n, condition) {
// Split the text into lines, then join back excluding the first four lines
return text.split('\n').slice(n).join('\n')
}

// Function to remove lines based on conditions
function removeLinesWithConditions(text) {
const lines = text.split('\n')
const filteredLines = []

for (let i = 0; i < lines.length; i++) {
// Check if the current line starts with "#### Extends" or "###### Overrides"
if (
lines[i].startsWith('#### Extends') ||
lines[i].startsWith('###### Overrides') ||
lines[i].startsWith('###### Inherited from')
) {
// If it does, skip this line and the next three lines
i += 3 // Skip this line and the next three
continue
}

if (lines[i].startsWith('##### new')) {
// avoid promoting constructors
i += 1
continue
}

// If not removed, add the line to filteredLines
filteredLines.push(convertH5toH3(lines[i]))
}

// Join the filtered lines back into a single string
return filteredLines.join('\n')
}

// Export the load function
module.exports = { load }
35 changes: 35 additions & 0 deletions js/scripts/generate_sdk_ref.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail

# This script generates the Code Interpreter JS SDK reference markdown files
# Run it in the `js/` directory

# generate raw SDK reference markdown files
npx typedoc

PKG_VERSION="v$(node -p "require('./package.json').version")"
ROUTES_DIR="../sdk-reference/code-interpreter-js-sdk/${PKG_VERSION}"
mkdir -p "${ROUTES_DIR}"

rm -rf sdk_ref/README.md

# Flatten the sdk_ref directory by moving all nested files to the root level and remove empty subdirectories
find sdk_ref -mindepth 2 -type f | while read -r file; do
mv "$file" sdk_ref/
done
find sdk_ref -type d -empty -delete

# Transfrom top level MD files into folders of the same name with page.mdx inside
find sdk_ref -maxdepth 1 -type f -name "*.md" | while read -r file; do
# Extract the filename without extension
filename=$(basename "$file" .md)
# Create the directory of the same name in sdk_ref
mkdir -p "sdk_ref/${filename}"
# Move the file inside the newly created directory
mv "$file" "sdk_ref/${filename}/page.mdx"
done

cp -r sdk_ref/* "${ROUTES_DIR}"

rm -rf sdk_ref
31 changes: 31 additions & 0 deletions js/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"out": "sdk_ref",
"plugin": ["typedoc-plugin-markdown", "./scripts/CustomMarkdownTheme.js"],
"exclude": ["**/*.spec.ts"],
"entryPoints": [
"src/index.ts",
"src/charts.ts",
"src/consts.ts",
"src/messaging.ts",
"src/sandbox.ts"
],
"excludeExternals": true,
"excludePrivate": true,
"excludeProtected": true,
"navigation": {
"includeGroups": false,
"includeCategories": false
},
"outputFileStrategy": "modules",
"readme": "none",
"disableSources": true,
// typedoc-plugin-markdown options
"classPropertiesFormat": "table",
"typeDeclarationFormat": "table",
"enumMembersFormat": "table",
"parametersFormat": "table",
"expandParameters": true,
"useCodeBlocks": true,
"hidePageTitle": true,
"hideBreadcrumbs": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"changeset": "^0.2.6"
},
"engines": {
"pnpm": ">=9.0.0 <10"
"pnpm": ">=9.0.0 <10"
}
}
Loading