Skip to content

Commit 37fc326

Browse files
ok
1 parent 04fb0e7 commit 37fc326

1 file changed

Lines changed: 131 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)