Skip to content

Commit 2583611

Browse files
phase-1
1 parent 7d09793 commit 2583611

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3398
-3342
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: PR Preview (Push)
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
paths:
8+
- "apps/cli/**"
9+
- "packages/types/**"
10+
- ".github/workflows/pr-preview-push.yaml"
11+
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
id-token: write
16+
17+
concurrency:
18+
group: pr-preview-push-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
publish-preview:
23+
name: Publish Preview
24+
runs-on: ubuntu-latest
25+
if: github.ref != 'refs/heads/main'
26+
timeout-minutes: 30
27+
steps:
28+
- name: Checkout Code
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Setup Bun
34+
uses: oven-sh/setup-bun@v2
35+
with:
36+
bun-version: latest
37+
38+
- name: Install Dependencies
39+
run: bun install --frozen-lockfile
40+
env:
41+
BTS_TELEMETRY: 0
42+
43+
- name: Generate Preview Version
44+
id: version
45+
run: |
46+
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
47+
SAFE_BRANCH=$(echo "$BRANCH_NAME" | tr '/' '-' | tr '_' '-' | cut -c1-20)
48+
COMMIT_SHA=$(echo "$GITHUB_SHA" | cut -c1-7)
49+
BASE_VERSION=$(jq -r '.version' apps/cli/package.json | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
50+
PREVIEW_VERSION="${BASE_VERSION}-${SAFE_BRANCH}.${COMMIT_SHA}"
51+
NPM_TAG="dev"
52+
53+
echo "version=$PREVIEW_VERSION" >> $GITHUB_OUTPUT
54+
echo "tag=$NPM_TAG" >> $GITHUB_OUTPUT
55+
echo "commit=$COMMIT_SHA" >> $GITHUB_OUTPUT
56+
57+
echo "Preview version: $PREVIEW_VERSION"
58+
echo "NPM tag: $NPM_TAG"
59+
60+
- name: Update types package version
61+
run: |
62+
cd packages/types
63+
jq --arg v "${{ steps.version.outputs.version }}" '.version = $v' package.json > tmp.json && mv tmp.json package.json
64+
65+
- name: Build types package
66+
run: cd packages/types && bun run build
67+
68+
- name: Publish types to NPM
69+
run: cd packages/types && bun publish --access public --tag ${{ steps.version.outputs.tag }}
70+
env:
71+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
72+
73+
- name: Update CLI package version and dependencies
74+
run: |
75+
cd apps/cli
76+
VERSION="${{ steps.version.outputs.version }}"
77+
jq --arg v "$VERSION" '
78+
.version = $v |
79+
.dependencies["@better-t-stack/types"] = $v |
80+
.optionalDependencies["@better-t-stack/cli-darwin-arm64"] = $v |
81+
.optionalDependencies["@better-t-stack/cli-darwin-x64"] = $v |
82+
.optionalDependencies["@better-t-stack/cli-linux-arm64"] = $v |
83+
.optionalDependencies["@better-t-stack/cli-linux-x64"] = $v |
84+
.optionalDependencies["@better-t-stack/cli-windows-x64"] = $v
85+
' package.json > tmp.json && mv tmp.json package.json
86+
87+
- name: Update create-bts alias package version
88+
run: |
89+
cd packages/create-bts
90+
jq --arg v "${{ steps.version.outputs.version }}" '.version = $v | .dependencies["create-better-t-stack"] = $v' package.json > tmp.json && mv tmp.json package.json
91+
92+
- name: Build CLI binaries
93+
run: cd apps/cli && bun run build
94+
env:
95+
BTS_TELEMETRY: 0
96+
97+
- name: Publish CLI platform packages to NPM
98+
run: |
99+
cd apps/cli/dist
100+
ls -la
101+
for dir in */; do
102+
if [ -f "$dir/package.json" ]; then
103+
echo "Publishing $dir..."
104+
cd "$dir"
105+
bun publish --access public --tag ${{ steps.version.outputs.tag }}
106+
cd ..
107+
fi
108+
done
109+
env:
110+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
111+
112+
- name: Publish CLI to NPM
113+
run: cd apps/cli && bun publish --access public --tag ${{ steps.version.outputs.tag }}
114+
env:
115+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
116+
117+
- name: Publish create-bts to NPM
118+
run: cd packages/create-bts && bun publish --access public --tag ${{ steps.version.outputs.tag }}
119+
env:
120+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
121+
122+
- name: Summary
123+
run: |
124+
echo "## Preview Release Published!" >> $GITHUB_STEP_SUMMARY
125+
echo "" >> $GITHUB_STEP_SUMMARY
126+
echo "**Version:** \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
127+
echo "" >> $GITHUB_STEP_SUMMARY
128+
echo "### Install" >> $GITHUB_STEP_SUMMARY
129+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
130+
echo "npx create-better-t-stack@${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
131+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

.github/workflows/pr-preview.yaml

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,37 @@ name: PR Preview
33
on:
44
pull_request_target:
55
types: [labeled]
6+
workflow_dispatch:
7+
inputs:
8+
pr_number:
9+
description: "PR number to build preview for"
10+
required: true
11+
type: string
12+
ref:
13+
description: "Git ref to checkout (commit SHA or branch)"
14+
required: true
15+
type: string
616

717
permissions:
818
contents: read
919
pull-requests: write
1020
id-token: write
1121

1222
concurrency:
13-
group: pr-preview-${{ github.event.pull_request.number }}
23+
group: pr-preview-${{ github.event.pull_request.number || inputs.pr_number }}
1424
cancel-in-progress: true
1525

1626
jobs:
1727
publish-preview:
1828
name: Publish Preview
1929
runs-on: ubuntu-latest
20-
if: github.event.label.name == 'preview'
30+
if: github.event.label.name == 'preview' || github.event_name == 'workflow_dispatch'
31+
timeout-minutes: 30
2132
steps:
2233
- name: Checkout PR Code
2334
uses: actions/checkout@v4
2435
with:
25-
ref: ${{ github.event.pull_request.head.sha }}
36+
ref: ${{ github.event.pull_request.head.sha || inputs.ref }}
2637
fetch-depth: 0
2738

2839
- name: Setup Bun
@@ -38,8 +49,9 @@ jobs:
3849
- name: Generate Preview Version
3950
id: version
4051
run: |
41-
PR_NUMBER=${{ github.event.pull_request.number }}
42-
COMMIT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)
52+
PR_NUMBER=${{ github.event.pull_request.number || inputs.pr_number }}
53+
REF="${{ github.event.pull_request.head.sha || inputs.ref }}"
54+
COMMIT_SHA=$(echo "$REF" | cut -c1-7)
4355
BASE_VERSION=$(jq -r '.version' apps/cli/package.json | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
4456
PREVIEW_VERSION="${BASE_VERSION}-pr${PR_NUMBER}.${COMMIT_SHA}"
4557
NPM_TAG="pr${PR_NUMBER}"
@@ -64,48 +76,69 @@ jobs:
6476
run: cd packages/types && bun publish --access public --tag ${{ steps.version.outputs.tag }}
6577
env:
6678
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
67-
BTS_TELEMETRY: 0
6879

69-
- name: Update CLI package version and types dependency
80+
- name: Update CLI package version and dependencies
7081
run: |
7182
cd apps/cli
72-
jq --arg v "${{ steps.version.outputs.version }}" '.version = $v | .dependencies["@better-t-stack/types"] = $v' package.json > tmp.json && mv tmp.json package.json
83+
VERSION="${{ steps.version.outputs.version }}"
84+
jq --arg v "$VERSION" '
85+
.version = $v |
86+
.dependencies["@better-t-stack/types"] = $v |
87+
.optionalDependencies["@better-t-stack/cli-darwin-arm64"] = $v |
88+
.optionalDependencies["@better-t-stack/cli-darwin-x64"] = $v |
89+
.optionalDependencies["@better-t-stack/cli-linux-arm64"] = $v |
90+
.optionalDependencies["@better-t-stack/cli-linux-x64"] = $v |
91+
.optionalDependencies["@better-t-stack/cli-windows-x64"] = $v
92+
' package.json > tmp.json && mv tmp.json package.json
7393
7494
- name: Update create-bts alias package version
7595
run: |
7696
cd packages/create-bts
7797
jq --arg v "${{ steps.version.outputs.version }}" '.version = $v | .dependencies["create-better-t-stack"] = $v' package.json > tmp.json && mv tmp.json package.json
7898
79-
- name: Build CLI
99+
- name: Build CLI binaries
80100
run: cd apps/cli && bun run build
81101
env:
82102
BTS_TELEMETRY: 0
83103

104+
- name: Publish CLI platform packages to NPM
105+
run: |
106+
cd apps/cli/dist
107+
ls -la
108+
for dir in */; do
109+
if [ -f "$dir/package.json" ]; then
110+
echo "Publishing $dir..."
111+
cd "$dir"
112+
bun publish --access public --tag ${{ steps.version.outputs.tag }}
113+
cd ..
114+
fi
115+
done
116+
env:
117+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
118+
84119
- name: Publish CLI to NPM
85120
run: cd apps/cli && bun publish --access public --tag ${{ steps.version.outputs.tag }}
86121
env:
87122
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
88-
BTS_TELEMETRY: 0
89123

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

96129
- name: Find existing preview comment
97130
uses: peter-evans/find-comment@v3
98131
id: find-comment
99132
with:
100-
issue-number: ${{ github.event.pull_request.number }}
133+
issue-number: ${{ github.event.pull_request.number || inputs.pr_number }}
101134
comment-author: "github-actions[bot]"
102135
body-includes: "PR Preview Release"
103136

104137
- name: Create or update PR comment
105138
uses: peter-evans/create-or-update-comment@v4
106139
with:
107140
comment-id: ${{ steps.find-comment.outputs.comment-id }}
108-
issue-number: ${{ github.event.pull_request.number }}
141+
issue-number: ${{ github.event.pull_request.number || inputs.pr_number }}
109142
edit-mode: replace
110143
body: |
111144
## PR Preview Release
@@ -117,22 +150,24 @@ jobs:
117150
| `create-better-t-stack` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
118151
| `create-bts` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
119152
| `@better-t-stack/types` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
153+
| `@better-t-stack/cli-darwin-arm64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
154+
| `@better-t-stack/cli-darwin-x64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
155+
| `@better-t-stack/cli-linux-arm64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
156+
| `@better-t-stack/cli-linux-x64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
157+
| `@better-t-stack/cli-windows-x64` | `${{ steps.version.outputs.version }}` | `pr${{ steps.version.outputs.pr }}` |
120158
121159
**Commit:** `${{ steps.version.outputs.commit }}`
122160
123161
### Install
124162
125163
```bash
126164
# Using the PR tag (always gets latest for this PR)
127-
bunx create-better-t-stack@pr${{ steps.version.outputs.pr }}
128165
npx create-better-t-stack@pr${{ steps.version.outputs.pr }}
129166
130167
# Using exact version
131-
bunx create-better-t-stack@${{ steps.version.outputs.version }}
132168
npx create-better-t-stack@${{ steps.version.outputs.version }}
133169
134170
# Using the alias
135-
bunx create-bts@pr${{ steps.version.outputs.pr }}
136171
npx create-bts@pr${{ steps.version.outputs.pr }}
137172
```
138173

0 commit comments

Comments
 (0)