Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 33 additions & 9 deletions .github/workflows/pr-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
name: Publish Preview
runs-on: ubuntu-latest
if: github.event.label.name == 'preview'
timeout-minutes: 30
steps:
- name: Checkout PR Code
uses: actions/checkout@v4
Expand Down Expand Up @@ -64,34 +65,55 @@ jobs:
run: cd packages/types && bun publish --access public --tag ${{ steps.version.outputs.tag }}
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
BTS_TELEMETRY: 0

- name: Update CLI package version and types dependency
- name: Update CLI package version and dependencies
run: |
cd apps/cli
jq --arg v "${{ steps.version.outputs.version }}" '.version = $v | .dependencies["@better-t-stack/types"] = $v' package.json > tmp.json && mv tmp.json package.json
VERSION="${{ steps.version.outputs.version }}"
jq --arg v "$VERSION" '
.version = $v |
.dependencies["@better-t-stack/types"] = $v |
.optionalDependencies["@better-t-stack/cli-darwin-arm64"] = $v |
.optionalDependencies["@better-t-stack/cli-darwin-x64"] = $v |
.optionalDependencies["@better-t-stack/cli-linux-arm64"] = $v |
.optionalDependencies["@better-t-stack/cli-linux-x64"] = $v |
.optionalDependencies["@better-t-stack/cli-windows-x64"] = $v
' package.json > tmp.json && mv tmp.json package.json

- name: Update create-bts alias package version
run: |
cd packages/create-bts
jq --arg v "${{ steps.version.outputs.version }}" '.version = $v | .dependencies["create-better-t-stack"] = $v' package.json > tmp.json && mv tmp.json package.json

- name: Build CLI
- name: Build CLI binaries
run: cd apps/cli && bun run build
env:
BTS_TELEMETRY: 0

- name: Publish CLI platform packages to NPM
run: |
cd apps/cli/dist
ls -la
for dir in */; do
if [ -f "$dir/package.json" ]; then
echo "Publishing $dir..."
cd "$dir"
bun publish --access public --tag ${{ steps.version.outputs.tag }}
cd ..
fi
done
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish CLI to NPM
run: cd apps/cli && bun publish --access public --tag ${{ steps.version.outputs.tag }}
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
BTS_TELEMETRY: 0

- name: Publish create-bts to NPM
run: cd packages/create-bts && bun publish --access public --tag ${{ steps.version.outputs.tag }}
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
BTS_TELEMETRY: 0

- name: Find existing preview comment
uses: peter-evans/find-comment@v3
Expand All @@ -117,22 +139,24 @@ jobs:
| `create-better-t-stack` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
| `create-bts` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
| `@better-t-stack/types` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
| `@better-t-stack/cli-darwin-arm64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
| `@better-t-stack/cli-darwin-x64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
| `@better-t-stack/cli-linux-arm64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
| `@better-t-stack/cli-linux-x64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
| `@better-t-stack/cli-windows-x64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |

**Commit:** `${{ steps.version.outputs.commit }}`

### Install

```bash
# Using the PR tag (always gets latest for this PR)
bunx create-better-t-stack@pr${{ steps.version.outputs.pr }}
npx create-better-t-stack@pr${{ steps.version.outputs.pr }}

# Using exact version
bunx create-better-t-stack@${{ steps.version.outputs.version }}
npx create-better-t-stack@${{ steps.version.outputs.version }}

# Using the alias
bunx create-bts@pr${{ steps.version.outputs.pr }}
npx create-bts@pr${{ steps.version.outputs.pr }}
```

Expand Down
77 changes: 60 additions & 17 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: Release to NPM
if: startsWith(github.event.head_commit.message, 'chore(release):')
runs-on: ubuntu-latest
timeout-minutes: 15
timeout-minutes: 30
steps:
- name: Checkout Code
uses: actions/checkout@v4
Expand Down Expand Up @@ -104,22 +104,52 @@ jobs:
run: cd packages/types && bun publish --access public
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
BTS_TELEMETRY: 1
CONVEX_INGEST_URL: ${{ secrets.CONVEX_INGEST_URL }}

- name: Update CLI types dependency and version
- name: Update CLI version and types dependency
if: steps.check-version.outputs.exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
cd apps/cli
jq --arg v "^$VERSION" '.dependencies["@better-t-stack/types"] = $v' package.json > tmp.json && mv tmp.json package.json
jq --arg v "$VERSION" --arg dep "^$VERSION" '.version = $v | .dependencies["@better-t-stack/types"] = $dep' package.json > tmp.json && mv tmp.json package.json

- name: Build CLI
- name: Update CLI optionalDependencies versions
if: steps.check-version.outputs.exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
cd apps/cli
jq --arg v "$VERSION" '
.optionalDependencies["@better-t-stack/cli-darwin-arm64"] = $v |
.optionalDependencies["@better-t-stack/cli-darwin-x64"] = $v |
.optionalDependencies["@better-t-stack/cli-linux-arm64"] = $v |
.optionalDependencies["@better-t-stack/cli-linux-x64"] = $v |
.optionalDependencies["@better-t-stack/cli-windows-x64"] = $v
' package.json > tmp.json && mv tmp.json package.json

- name: Build CLI binaries
if: steps.check-version.outputs.exists == 'false'
run: cd apps/cli && bun run build

- name: Publish CLI platform packages to NPM
if: steps.check-version.outputs.exists == 'false'
run: |
cd apps/cli/dist
ls -la
for dir in */; do
if [ -f "$dir/package.json" ]; then
echo "Publishing $dir..."
cd "$dir"
bun publish --access public
cd ..
fi
done
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
Comment on lines +132 to +146

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add error handling to prevent partial platform releases.

The publishing loop continues even if a platform package fails to publish, which could result in a partial release where some platform binaries are available but others are not. This would create an inconsistent release state.

🔎 Proposed fix to fail fast on publish errors
       - name: Publish CLI platform packages to NPM
         if: steps.check-version.outputs.exists == 'false'
         run: |
+          set -e
           cd apps/cli/dist
           ls -la
           for dir in */; do
             if [ -f "$dir/package.json" ]; then
               echo "Publishing $dir..."
-              cd "$dir"
-              bun publish --access public
-              cd ..
+              (cd "$dir" && bun publish --access public) || exit 1
             fi
           done
         env:
           NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Publish CLI platform packages to NPM
if: steps.check-version.outputs.exists == 'false'
run: |
cd apps/cli/dist
ls -la
for dir in */; do
if [ -f "$dir/package.json" ]; then
echo "Publishing $dir..."
cd "$dir"
bun publish --access public
cd ..
fi
done
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish CLI platform packages to NPM
if: steps.check-version.outputs.exists == 'false'
run: |
set -e
cd apps/cli/dist
ls -la
for dir in */; do
if [ -f "$dir/package.json" ]; then
echo "Publishing $dir..."
(cd "$dir" && bun publish --access public) || exit 1
fi
done
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
🤖 Prompt for AI Agents
.github/workflows/release.yaml around lines 132 to 146: the publish loop
currently continues when a bun publish fails, risking partial releases; modify
the script to fail-fast by enabling strict shell error handling (e.g., set -euo
pipefail at the top of the run block) or check the exit status of each bun
publish and immediately exit with a non-zero status if it fails, ensuring the
workflow stops and surfaces the error instead of continuing to publish remaining
platform packages.


- name: Publish CLI main package to NPM
if: steps.check-version.outputs.exists == 'false'
run: cd apps/cli && bun publish --access public
env:
BTS_TELEMETRY: 1
CONVEX_INGEST_URL: ${{ secrets.CONVEX_INGEST_URL }}
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
Comment on lines +132 to +152

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Consider verifying platform package availability before publishing main package.

The main CLI package (lines 148-152) is published immediately after the platform packages (lines 132-146). Since the main package lists these as optionalDependencies, there's a potential race condition if NPM registry propagation hasn't completed. Users installing immediately after the release might not receive the platform-specific binaries until propagation finishes (typically a few minutes).

While optionalDependencies won't cause installation failures, consider adding a brief delay or verification step between publishing platform and main packages to ensure better user experience for early adopters.

💡 Example verification step
      - name: Verify platform packages are available
        if: steps.check-version.outputs.exists == 'false'
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          PACKAGES=(
            "@better-t-stack/cli-darwin-arm64"
            "@better-t-stack/cli-darwin-x64"
            "@better-t-stack/cli-linux-arm64"
            "@better-t-stack/cli-linux-x64"
            "@better-t-stack/cli-windows-x64"
          )
          
          for pkg in "${PACKAGES[@]}"; do
            echo "Checking $pkg@$VERSION..."
            for i in {1..30}; do
              if npm view "$pkg@$VERSION" version 2>/dev/null; then
                echo "✓ $pkg@$VERSION is available"
                break
              fi
              if [ $i -eq 30 ]; then
                echo "✗ $pkg@$VERSION not available after 5 minutes"
                exit 1
              fi
              echo "  Waiting... (attempt $i/30)"
              sleep 10
            done
          done
🤖 Prompt for AI Agents
.github/workflows/release.yaml lines 132-152: the workflow publishes platform
packages and then immediately publishes the main CLI package, risking a race
where optionalDependencies are not yet propagated; modify the workflow to insert
a verification step (or short delay) after the platform-package loop and before
publishing the main package that checks each platform package@${{
steps.version.outputs.version }} is visible in the npm registry (e.g., loop with
npm view or curl to registry, retrying with short sleeps and a timeout) and only
proceed to the main bun publish when all platform packages are confirmed
available (or fail after the timeout).


- name: Update create-bts alias package version
if: steps.check-version.outputs.exists == 'false'
Expand All @@ -128,21 +158,29 @@ jobs:
cd packages/create-bts
jq --arg v "$VERSION" --arg dep "^$VERSION" '.version = $v | .dependencies["create-better-t-stack"] = $dep' package.json > tmp.json && mv tmp.json package.json

- name: Publish CLI to NPM
- name: Publish create-bts alias to NPM
if: steps.check-version.outputs.exists == 'false'
run: cd apps/cli && bun publish --access public
run: cd packages/create-bts && bun publish --access public
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
BTS_TELEMETRY: 1
CONVEX_INGEST_URL: ${{ secrets.CONVEX_INGEST_URL }}

- name: Publish create-bts alias to NPM
- name: Upload binaries to GitHub Release
if: steps.check-version.outputs.exists == 'false'
run: cd packages/create-bts && bun publish --access public
run: |
VERSION="${{ steps.version.outputs.version }}"
cd apps/cli/dist
for dir in better-t-stack-cli-*/; do
name="${dir%/}"
if [[ "$name" == *"linux"* ]]; then
tar -czf "${name}.tar.gz" -C "$dir/bin" .
gh release upload "v$VERSION" "${name}.tar.gz" --clobber
else
zip -j "${name}.zip" "$dir/bin/"*
gh release upload "v$VERSION" "${name}.zip" --clobber
fi
done
env:
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
BTS_TELEMETRY: 1
CONVEX_INGEST_URL: ${{ secrets.CONVEX_INGEST_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Release Summary
if: steps.check-version.outputs.exists == 'false'
Expand All @@ -154,6 +192,11 @@ jobs:
echo "- [create-better-t-stack@$VERSION](https://www.npmjs.com/package/create-better-t-stack/v/$VERSION)" >> $GITHUB_STEP_SUMMARY
echo "- [create-bts@$VERSION](https://www.npmjs.com/package/create-bts/v/$VERSION)" >> $GITHUB_STEP_SUMMARY
echo "- [@better-t-stack/types@$VERSION](https://www.npmjs.com/package/@better-t-stack/types/v/$VERSION)" >> $GITHUB_STEP_SUMMARY
echo "- @better-t-stack/cli-darwin-arm64@$VERSION" >> $GITHUB_STEP_SUMMARY
echo "- @better-t-stack/cli-darwin-x64@$VERSION" >> $GITHUB_STEP_SUMMARY
echo "- @better-t-stack/cli-linux-arm64@$VERSION" >> $GITHUB_STEP_SUMMARY
echo "- @better-t-stack/cli-linux-x64@$VERSION" >> $GITHUB_STEP_SUMMARY
echo "- @better-t-stack/cli-windows-x64@$VERSION" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### GitHub Release" >> $GITHUB_STEP_SUMMARY
echo "[v$VERSION](https://github.com/${{ github.repository }}/releases/tag/v$VERSION)" >> $GITHUB_STEP_SUMMARY
98 changes: 98 additions & 0 deletions apps/cli/bin/create-better-t-stack
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env node

/**
* Bin stub for create-better-t-stack.
* Finds and runs the platform-specific compiled binary.
*
* The binary is installed as an optional dependency:
* @better-t-stack/cli-{platform}-{arch}
*
* This stub searches node_modules for the matching binary package.
*/

import { spawnSync } from "node:child_process";
import { existsSync, realpathSync } from "node:fs";
import { dirname, join } from "node:path";
import { platform as osPlatform, arch as osArch } from "node:os";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

function run(target) {
const result = spawnSync(target, process.argv.slice(2), {
stdio: "inherit",
});
if (result.error) {
console.error(result.error.message);
process.exit(1);
}
const code = typeof result.status === "number" ? result.status : 0;
process.exit(code);
}

// Allow override via environment variable
const envPath = process.env.CREATE_BETTER_T_STACK_BIN_PATH;
if (envPath) {
run(envPath);
}

const scriptPath = realpathSync(__filename);
const scriptDir = dirname(scriptPath);

const platformMap = {
darwin: "darwin",
linux: "linux",
win32: "windows",
};

const archMap = {
x64: "x64",
arm64: "arm64",
};

let platform = platformMap[osPlatform()];
if (!platform) {
platform = osPlatform();
}

let arch = archMap[osArch()];
if (!arch) {
arch = osArch();
}

// Scoped package name: @better-t-stack/cli-{platform}-{arch}
const scopedPackage = "@better-t-stack/cli-" + platform + "-" + arch;
const binary = platform === "windows" ? "create-better-t-stack.exe" : "create-better-t-stack";

function findBinary(startDir) {
let current = startDir;
for (; ;) {
const modules = join(current, "node_modules");
if (existsSync(modules)) {
// Check for scoped package: node_modules/@better-t-stack/cli-{platform}-{arch}
const scopedPath = join(modules, "@better-t-stack", "cli-" + platform + "-" + arch);
const candidate = join(scopedPath, "bin", binary);
if (existsSync(candidate)) {
return candidate;
}
}
const parent = dirname(current);
if (parent === current) {
return;
}
current = parent;
}
}

const resolved = findBinary(scriptDir);

if (!resolved) {
console.error(
'No binary found for your platform (' + platform + '-' + arch + ').\n' +
'You can try manually installing the "' + scopedPackage + '" package.',
);
process.exit(1);
}

run(resolved);
Loading
Loading