-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f04e450
Showing
15 changed files
with
2,714 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": ["@changesets/changelog-github", { "repo": "magicbell/magicbell-go-project-client" }], | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [], | ||
"privatePackages": {"tag": true, "version": true} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
magicbell/magicbell: | ||
- source: docs-dist | ||
dest: src/go/app/site/docs/mdx/03-libraries/magicbell-go-project-client |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Publish Docs | ||
|
||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- uses: bahmutov/npm-install@v1 | ||
|
||
- name: Build docs | ||
run: yarn build:docs | ||
|
||
- name: Push docs to remote repo | ||
uses: BetaHuhn/repo-file-sync-action@v1 | ||
with: | ||
GH_PAT: ${{ secrets.BELLA_ACTION_TOKEN }} | ||
COMMIT_PREFIX: 'docs: ' | ||
GIT_USERNAME: 'MagicBella' | ||
GIT_EMAIL: '${{ secrets.BELLA_EMAIL_ADDRESS }}' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Regen | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 6 * * 1' # At 06:00 on Monday. | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
jobs: | ||
regen: | ||
name: Regen | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.BELLA_ACTION_TOKEN }} | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- uses: bahmutov/npm-install@v1 | ||
|
||
- name: Regen `magicbell-go-project-client` | ||
run: yarn codegen | ||
env: | ||
LIBLAB_TOKEN: ${{ secrets.LIBLAB_ACTION_TOKEN }} | ||
|
||
- name: Generate Changeset | ||
shell: bash | ||
run: | | ||
TIMESTAMP=$(date +%s) | ||
mkdir -p .changeset | ||
PACKAGE_NAME=$(jq -r '.name' package.json) | ||
FILE_NAME=".changeset/auto-bump-${PACKAGE_NAME}-${TIMESTAMP}.md" | ||
if [ -z "$PACKAGE_NAME" ] || [ "$PACKAGE_NAME" == "null" ]; then | ||
echo "Warning: Could not find 'name' in package.json. Skipping..." | ||
continue | ||
fi | ||
# Create the Changeset file with the correct package name and minor bump | ||
{ | ||
echo "---" | ||
echo ""\"$PACKAGE_NAME\"": minor" | ||
echo "---" | ||
echo "" | ||
echo "Automatic minor version bump for changes in \`$PACKAGE_NAME\`." | ||
} > "$FILE_NAME" | ||
echo "Created Changeset: $FILE_NAME" | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
token: ${{ secrets.BELLA_ACTION_TOKEN }} | ||
branch: 'feature/regen-sdks' | ||
base: 'main' | ||
title: 'chore: regen sdk' | ||
body: 'Automated PR to update the generated SDK' | ||
commit-message: 'chore: regen sdk' | ||
committer: 'MagicBella <${{ secrets.BELLA_EMAIL_ADDRESS }}>' | ||
author: 'MagicBella <${{ secrets.BELLA_EMAIL_ADDRESS }}>' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Release To Discussions | ||
|
||
on: | ||
release: | ||
types: [created, edited, deleted] | ||
|
||
concurrency: release-discussion-action | ||
|
||
jobs: | ||
publish-release-notes: | ||
name: Publish Release Notes | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: publish discussion | ||
uses: magicbell/release-discussion-action@main | ||
with: | ||
repo: magicbell/community | ||
category: changelog | ||
cycle: week | ||
release-prefix: magicbell-go-project-client | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.BELLA_ACTION_TOKEN }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.BELLA_ACTION_TOKEN }} | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.18' | ||
|
||
- uses: bahmutov/npm-install@v1 | ||
|
||
- name: Create release Pull Request or publish release | ||
id: changesets | ||
uses: changesets/action@v1 | ||
with: | ||
version: yarn changeset version | ||
publish: 'echo handing publishing in the next step' | ||
commit: 'chore: version package' | ||
title: 'chore: version package' | ||
createGithubReleases: true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.BELLA_ACTION_TOKEN }} | ||
|
||
- name: Publish to pkg.go.dev | ||
if: steps.changesets.outputs.published == 'true' | ||
run: | | ||
MODULE_NAME=$(jq -r '.config.languageOptions.go.goModuleName' .manifest.json) | ||
GOPROXY=proxy.golang.org | ||
go mod download | ||
go list -m $MODULE_NAME | ||
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Tooling | ||
node_modules/ | ||
target | ||
|
||
docs-dist | ||
|
||
# act | ||
.env | ||
.secrets | ||
|
||
# Binaries and executables | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
.DStore | ||
|
||
# Output of go coverage | ||
*.out |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
The MIT License (MIT) | ||
Copyright © 2024 MagicBell, Inc | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module github.com/magicbell/magicbell-go-project-client | ||
|
||
|
||
go 1.18 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"sdkName": "magicbell-project-client", | ||
"specFilePath": "https://site.magicbell.cloud/docs/api/openapi.project.json", | ||
"apiName": "magicbell-api", | ||
"languages": ["go"], | ||
"auth": ["bearer"], | ||
"customizations": { | ||
"devContainer": false, | ||
"generateEnv": false, | ||
"includeOptionalSnippetParameters": true, | ||
"authentication": { | ||
"access": { | ||
"prefix": "Bearer" | ||
} | ||
}, | ||
"inferServiceNames": false, | ||
"injectedModels": [], | ||
"license": { | ||
"type": "MIT" | ||
}, | ||
"responseHeaders": false, | ||
"retry": { | ||
"enabled": true, | ||
"maxAttempts": 3, | ||
"retryDelay": 150 | ||
} | ||
}, | ||
"languageOptions": { | ||
"go": { | ||
"githubRepoName": "magicbell-go-project-client", | ||
"sdkVersion": "0.0.0", | ||
"goModuleName": "github.com/magicbell/magicbell-go-project-client" | ||
} | ||
}, | ||
"publishing": { | ||
"githubOrg": "magicbell" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "magicbell-go-project-client", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"changeset": "changeset", | ||
"codegen": "tsx scripts/liblab-gen.ts", | ||
"build:docs": "tsx scripts/liblab-docs.ts" | ||
}, | ||
"devDependencies": { | ||
"@changesets/changelog-github": "^0.5.0", | ||
"@changesets/cli": "^2.27.10", | ||
"@magicbell/codegen": "^0.3.0", | ||
"@types/node": "^22.10.2", | ||
"glob": "^11.0.0", | ||
"tsx": "^4.19.2" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
|
||
import { exists, getDirs } from '@magicbell/codegen/fs'; | ||
import * as md from '@magicbell/codegen/markdown'; | ||
import * as glob from 'glob'; | ||
|
||
function pascalToHyphenCase(str: string): string { | ||
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | ||
} | ||
|
||
function rewriteHref(url: string) { | ||
if (!url.endsWith('.md')) return url; | ||
return url.replace(/^documentation\//, '').replace(/([^/]+)\.md$/, (_, fileName) => pascalToHyphenCase(fileName)); | ||
} | ||
|
||
const root = process.cwd(); | ||
const outdir = path.join(root, 'docs-dist'); | ||
await fs.rm(outdir, { recursive: true, force: true }); | ||
|
||
const pkg = JSON.parse(await fs.readFile('package.json', 'utf-8')); | ||
|
||
// process readme | ||
const [readme] = glob.sync('README.md', { cwd: root }); | ||
const readmeAst = await md.read(readme); | ||
md.removeAllBeforeHeading(readmeAst, 'Setup & Configuration'); | ||
md.reIndentHeadings(readmeAst, 1); | ||
md.mapLinks(readmeAst, rewriteHref); | ||
md.insertFrontMatter(readmeAst, { title: pkg.name }); | ||
|
||
await md.write(readmeAst, path.join(outdir, 'index.mdx')); | ||
|
||
// process pages | ||
const docs = glob.sync('**/*.md', { | ||
cwd: path.join(root, 'documentation'), | ||
}); | ||
|
||
for (const file of docs) { | ||
const ast = await md.read(path.join(root, 'documentation', file)); | ||
|
||
md.reIndentHeadings(ast, 1); | ||
md.mapLinks(ast, rewriteHref); | ||
|
||
const title = md.getTitle(ast); | ||
md.insertFrontMatter(ast, { title }); | ||
md.removeFirstHeading(ast); | ||
|
||
await md.write(ast, path.join(outdir, pascalToHyphenCase(file) + 'x')); | ||
} | ||
|
||
for (const dir of getDirs(docs)) { | ||
const file = path.join(outdir, dir, 'index.mdx'); | ||
if (await exists(file)) continue; | ||
const ast: md.Root = { type: 'root', children: [] }; | ||
md.insertFrontMatter(ast, { title: path.basename(dir) }); | ||
await md.write(ast, file); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { execSync } from "node:child_process"; | ||
import * as fs from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
|
||
async function move(oldPath: string, newPath: string) { | ||
await fs.rm(newPath, { recursive: true, force: true }); | ||
await fs.mkdir(path.dirname(newPath), { recursive: true }); | ||
await fs.rename(oldPath, newPath); | ||
} | ||
|
||
async function readJSON(path: string) { | ||
return fs | ||
.readFile(path, { encoding: "utf-8" }) | ||
.then((data) => JSON.parse(data)); | ||
} | ||
|
||
function hasChangesInPath(path: string) { | ||
try { | ||
execSync(`git diff --quiet HEAD ${path}`, { stdio: "ignore" }); | ||
return false; | ||
} catch (error) { | ||
return true; | ||
} | ||
} | ||
|
||
async function build() { | ||
let pkgJson = await readJSON("./package.json"); | ||
const liblabConfig = await readJSON("./liblab.config.json"); | ||
console.log( | ||
`Building '${pkgJson.name}' using spec '${liblabConfig.specFilePath}'` | ||
); | ||
|
||
execSync("npx -y liblab@latest build -y --skip-validation", { | ||
stdio: "inherit", | ||
}); | ||
|
||
await move('output/go/pkg', './pkg'); | ||
await move('output/go/internal', './internal'); | ||
await move('output/go/go.mod', './go.mod'); | ||
|
||
if (!hasChangesInPath("./pkg") && !hasChangesInPath("./internal") && !hasChangesInPath("./go.mod")) { | ||
console.log("No changes detected in output."); | ||
return; | ||
} | ||
|
||
await move('output/go/cmd', './cmd'); | ||
await move('output/go/documentation', './documentation'); | ||
await move('output/go/README.md', './README.md'); | ||
} | ||
|
||
void build().finally(() => fs.rm("output", { recursive: true, force: true })); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2018", | ||
"module": "es2022", | ||
"moduleResolution": "Node16", | ||
"allowSyntheticDefaultImports": true | ||
} | ||
} |
Oops, something went wrong.