Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mlejva committed Oct 12, 2024
2 parents b7cafcd + e5448c9 commit 047039c
Show file tree
Hide file tree
Showing 39 changed files with 13,268 additions and 90 deletions.
11 changes: 11 additions & 0 deletions .github/scripts/is_new_api_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 packages directory.
# If there are diffs, it means we need to generate a new API references.
if git diff --name-only HEAD^ | grep -q '^packages/'; then
echo "true"
else
echo "false"
fi
112 changes: 112 additions & 0 deletions .github/workflows/generate_api_ref.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Generate SDK API references

on:
workflow_dispatch:
push:
branches:
- main
- beta

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

permissions:
contents: write

jobs:
is_new_api_ref:
name: Is new API reference?
runs-on: ubuntu-latest
outputs:
new_api_ref: ${{ steps.sdk-changes.outputs.new_api_ref }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Check if SDK changes
id: sdk-changes
run: |
IS_NEW_API_REF=$(./.github/scripts/is_new_api_ref.sh)
echo "new_api_ref=$IS_NEW_API_REF" >> "$GITHUB_OUTPUT"
sdk-changes:
name: SDK changes
needs: [is_new_api_ref]
if: always()
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v3
id: pnpm-install
with:
version: 9.5

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
cache: pnpm
cache-dependency-path: pnpm-lock.yaml

- name: Configure pnpm
run: |
pnpm config set auto-install-peers true
pnpm config set exclude-links-from-lockfile true
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Install dependencies
working-directory: ./packages/python-sdk
run: poetry install --no-interaction --no-root

- name: Generate Python SDK API reference
id: python-sdk-api-ref
working-directory: ./packages/python-sdk
run: |
source .venv/bin/activate
./scripts/generate_api_ref.sh
- name: Generate JS SDK API reference
id: js-sdk-api-ref
working-directory: packages/js-sdk
run: ./scripts/generate_api_ref.sh

- name: Generate CLI API reference
id: cli-api-ref
working-directory: packages/cli
run: ./scripts/generate_api_ref.sh

- name: Show docs file structure
run: tree apps/web/src/app/\(docs\)/docs/api-reference

- name: Commit new SDK API reference versions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add apps/web/src/app/\(docs\)/docs/api-reference
git commit -m "[skip ci] Release new SDK API reference doc versions" || exit 0
git push
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
secrets: inherit

release:
needs: [python-tests, js-tests, cli-tests]
needs: [is_release, python-tests, js-tests, cli-tests]
if: always() && !contains(needs.*.result, 'failure') && needs.is_release.outputs.release == 'true'
name: Release
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,7 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# API reference artifacts
api_ref/
apiRefRoutes.json
5 changes: 3 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"version": "0.1.6",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"dev": "node prebuild.js && next dev",
"prebuild": "node prebuild.js",
"build": "node prebuild.js && next build",
"start": "next start",
"lint": "next lint",
"rm-next-cache": "rm -rf .next/cache",
Expand Down
144 changes: 144 additions & 0 deletions apps/web/prebuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
const fs = require('fs')
const path = require('path')

const ApiRefRoutesFilePath = './src/components/Navigation/apiRefRoutes.json'

// Current directory hierarchy:
//
// {
// 'sdk-name': {
// 'version': {
// 'module': null
// }
// }
// }
let hierarchy = {}

function buildDirectoryHierarchy(dirPath) {
const result = {}
const entries = fs.readdirSync(dirPath, { withFileTypes: true })

entries.forEach((entry) => {
if (entry.isDirectory()) {
result[entry.name] = buildDirectoryHierarchy(
path.join(dirPath, entry.name)
)
}
})

return Object.keys(result).length === 0 ? null : result
}

const filesCreated = new Set()

function buildRoutes(dirName, dir, basePath = '', depth = 1) {
const entries = fs.readdirSync(dir, { withFileTypes: true })
const parentDirName = path.basename(path.dirname(dir))

return entries
.map((entry) => {
const relativePath = path.join(basePath, entry.name)

if (entry.isDirectory()) {
let route = {
title: depth === 1 ? entry.name.toLocaleUpperCase() : entry.name,
}
const entryName = entry.name
const childPath = path.join(dir, entry.name)
const links = buildRoutes(entryName, childPath, relativePath, depth + 1)

if (links.length > 0) {
route.href = '/docs/api-reference/' + relativePath
// SDK level
if (depth === 2) {
const mdxFilePath = path.join(dir, 'page.mdx')
if (filesCreated.has(mdxFilePath)) return route

// Generate SDK version TOC markdown file
let mdxContent = `# ${dirName}\n\n## ${entryName}\n\n${links
.map(
(link) =>
`- [${
link.title.charAt(0).toUpperCase() +
link.title.slice(1).toLowerCase()
}](./${dirName}/${entryName}/${link.title})`
)
.join('\n')}`

if (
hierarchy[dirName] &&
Object.keys(hierarchy[dirName]).length > 1
) {
const versions = Object.keys(hierarchy[dirName])
const versionLinks = `${versions
.map(
(version) =>
`<a href="/docs/api-reference/${dirName}/${version}" class="version-link">[${version}]</a>`
)
.join('\n ')}`

mdxContent = `${versionLinks}\n\n\n${mdxContent}`
}

console.log('Generated TOC file:', mdxFilePath)
fs.writeFileSync(mdxFilePath, mdxContent)
filesCreated.add(mdxFilePath)
}
}

// Version level
if (depth === 3) {
const mdxFilePath = path.join(dir, 'page.mdx')
if (filesCreated.has(mdxFilePath)) return route

// Generate modules TOC markdown file
const modules = Object.keys(hierarchy[parentDirName][dirName])
let mdxContent = `# ${parentDirName.toLocaleUpperCase()} ${dirName}\n\n${modules
.map(
(module) =>
`- [${
module.charAt(0).toUpperCase() + module.slice(1).toLowerCase()
}](./${dirName}/${module})`
)
.join('\n')}`

console.log('Generated TOC file:', mdxFilePath)
fs.writeFileSync(mdxFilePath, mdxContent)
filesCreated.add(mdxFilePath)
}

return route
}
})
.filter(Boolean)
}

function generateApiRefRoutes() {
const apiRefPath = path.join(__dirname, './src/app/(docs)/docs/api-reference')

if (!fs.existsSync(apiRefPath)) {
return []
}

hierarchy = buildDirectoryHierarchy(apiRefPath)

const routes = buildRoutes('api-reference', apiRefPath)
return routes
}

const apiRefRoutes = [
{
title: 'References',
links: generateApiRefRoutes(),
},
]

fs.writeFileSync(
path.join(__dirname, ApiRefRoutesFilePath),
JSON.stringify(apiRefRoutes, null, 2)
)

console.log(
'\n\nAPI reference TOCs and routes file generated successfully:\n\n'
)
console.log('routes', JSON.stringify(apiRefRoutes, null, 2), '\n\n')
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# e2b auth


authentication commands

## Usage

```bash
e2b auth [options] [command]
```
# e2b auth login


log in to CLI

## Usage

```bash
e2b auth login [options]
```


# e2b auth logout


log out of CLI

## Usage

```bash
e2b auth logout [options]
```


# e2b auth info


get information about the current user

## Usage

```bash
e2b auth info [options]
```


# e2b auth configure


configure user

## Usage

```bash
e2b auth configure [options]
```


Loading

0 comments on commit 047039c

Please sign in to comment.