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