Skip to content

Commit 95642d1

Browse files
committed
2 parents 3f5898f + e20d1cf commit 95642d1

2 files changed

Lines changed: 217 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches: ['develop', 'main']
6+
7+
permissions:
8+
contents: write
9+
10+
concurrency:
11+
group: prod-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
promote-and-deploy:
16+
if: ${{ github.ref == 'refs/heads/develop' }}
17+
runs-on: ubuntu-latest
18+
outputs:
19+
changed: ${{ steps.promote.outputs.changed }}
20+
new_sha: ${{ steps.promote.outputs.new_sha }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Promote develop → main (fast-forward only)
27+
id: promote
28+
run: |
29+
set -euo pipefail
30+
git config user.name "github-actions[bot]"
31+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
32+
git fetch origin main develop
33+
BEFORE="$(git rev-parse origin/main)"
34+
git checkout -B main origin/main
35+
git merge --ff-only origin/develop
36+
AFTER="$(git rev-parse HEAD)"
37+
if [ "$BEFORE" = "$AFTER" ]; then
38+
echo "changed=false" >> "$GITHUB_OUTPUT"
39+
echo "new_sha=$AFTER" >> "$GITHUB_OUTPUT"
40+
exit 0
41+
fi
42+
git push origin main
43+
echo "changed=true" >> "$GITHUB_OUTPUT"
44+
echo "new_sha=$AFTER" >> "$GITHUB_OUTPUT"
45+
46+
- uses: actions/setup-node@v4
47+
if: ${{ steps.promote.outputs.changed == 'true' }}
48+
with:
49+
node-version: 20
50+
registry-url: 'https://registry.npmjs.org'
51+
cache: 'npm'
52+
cache-dependency-path: 'package-lock.json'
53+
54+
- name: Force npmjs registry
55+
if: ${{ steps.promote.outputs.changed == 'true' }}
56+
run: |
57+
npm config set registry https://registry.npmjs.org/
58+
echo "registry=https://registry.npmjs.org/" > ~/.npmrc
59+
60+
- name: Install dependencies
61+
if: ${{ steps.promote.outputs.changed == 'true' }}
62+
run: npm ci
63+
64+
- name: Install Vercel CLI
65+
if: ${{ steps.promote.outputs.changed == 'true' }}
66+
run: npm i -g vercel@latest
67+
68+
- name: Pull Vercel Env (production)
69+
if: ${{ steps.promote.outputs.changed == 'true' }}
70+
env:
71+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
72+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
73+
run: vercel pull --yes --environment=production --token='${{ secrets.VERCEL_TOKEN }}'
74+
75+
- name: Build (prebuilt, prod)
76+
if: ${{ steps.promote.outputs.changed == 'true' }}
77+
run: vercel build --prod --token='${{ secrets.VERCEL_TOKEN }}'
78+
79+
- name: Deploy (prod)
80+
if: ${{ steps.promote.outputs.changed == 'true' }}
81+
id: deploy
82+
run: |
83+
url="$(vercel deploy --prebuilt --prod --token='${{ secrets.VERCEL_TOKEN }}')"
84+
echo "::notice::Deployed $url"
85+
86+
deploy-on-main:
87+
if: ${{ github.ref == 'refs/heads/main' }}
88+
runs-on: ubuntu-latest
89+
steps:
90+
- uses: actions/checkout@v4
91+
92+
- uses: actions/setup-node@v4
93+
with:
94+
node-version: 20
95+
registry-url: 'https://registry.npmjs.org'
96+
cache: 'npm'
97+
cache-dependency-path: 'package-lock.json'
98+
99+
- name: Force npmjs registry
100+
run: |
101+
npm config set registry https://registry.npmjs.org/
102+
echo "registry=https://registry.npmjs.org/" > ~/.npmrc
103+
104+
- name: Install dependencies
105+
run: npm ci
106+
107+
- run: npm i -g vercel@latest
108+
109+
- name: Pull Vercel Env (production)
110+
env:
111+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
112+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
113+
run: vercel pull --yes --environment=production --token='${{ secrets.VERCEL_TOKEN }}'
114+
115+
- name: Build (prebuilt, prod)
116+
run: vercel build --prod --token='${{ secrets.VERCEL_TOKEN }}'
117+
118+
- name: Deploy (prod)
119+
run: vercel deploy --prebuilt --prod --token='${{ secrets.VERCEL_TOKEN }}'

.github/workflows/preview.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Preview
2+
3+
on:
4+
pull_request:
5+
branches: ['develop']
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
11+
concurrency:
12+
group: preview-${{ github.event.pull_request.number }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
checks:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
# Setup Node with npm cache (package-lock.json)
22+
- name: Setup Node (npm cache)
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
cache: 'npm'
27+
cache-dependency-path: 'package-lock.json'
28+
29+
- name: Show versions
30+
run: |
31+
node -v
32+
npm -v
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Lint (if present)
38+
run: npm run --if-present lint
39+
40+
- name: Typecheck (if present)
41+
run: npm run --if-present typecheck
42+
43+
- name: Test (if present)
44+
run: npm run --if-present test -- --passWithNoTests
45+
46+
- name: Build
47+
run: npm run build
48+
49+
vercel-preview:
50+
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.draft }}
51+
needs: checks
52+
runs-on: ubuntu-latest
53+
54+
env:
55+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
56+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
57+
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- name: Setup Node (npm cache)
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version: 20
65+
cache: 'npm'
66+
cache-dependency-path: 'package-lock.json'
67+
68+
- name: Show versions
69+
run: |
70+
node -v
71+
npm -v
72+
73+
- name: Install Vercel CLI
74+
run: npm install --global vercel@latest
75+
76+
- name: Pull Vercel Env (preview)
77+
env:
78+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
79+
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
80+
81+
- name: Build Project Artifacts (prebuilt)
82+
env:
83+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
84+
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
85+
86+
- name: Deploy Preview
87+
id: deploy
88+
env:
89+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
90+
run: |
91+
url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})
92+
echo "preview_url=$url" >> $GITHUB_OUTPUT
93+
94+
- name: Comment PR with Preview URL
95+
uses: thollander/actions-comment-pull-request@v2
96+
with:
97+
message: |
98+
✅ PREVIEW: ${{ steps.deploy.outputs.preview_url }}

0 commit comments

Comments
 (0)