@@ -3,26 +3,37 @@ name: PR Preview
33on :
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
717permissions :
818 contents : read
919 pull-requests : write
1020 id-token : write
1121
1222concurrency :
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
1626jobs :
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
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