-
Notifications
You must be signed in to change notification settings - Fork 5
156 lines (131 loc) · 4.49 KB
/
ci-and-deploy.yml
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: CI and Deploy workflow
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
on:
pull_request:
branches:
- "**"
- "!dependabot/**"
push:
branches:
- "prod"
- "dev"
workflow_dispatch:
env:
PR_URL: ${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.number }}
BRANCH_NAME: ${{ github.event.pull_request.head.ref || github.ref_name }}
jobs:
init:
name: Initial Common Steps
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: |
node_modules
~/.cache/Cypress
key: deps-node-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
lint:
name: Lint
runs-on: ubuntu-latest
needs: init
steps:
- name: Git checkout
uses: actions/checkout@v4
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: |
node_modules
~/.cache/Cypress
key: deps-node-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: lint
run: |
yarn lint
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git diff --cached --quiet || echo "changes=true" >> $GITHUB_ENV
- name: Commit lint Changes
if: env.changes == 'true'
run: |
git commit -m "chore: format code"
git push
build_and_deploy:
name: Build and Deploy to Cloudflare
runs-on: ubuntu-latest
environment: production
timeout-minutes: 30
needs: lint
steps:
- name: Git checkout
uses: actions/checkout@v4
- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: |
node_modules
~/.cache/Cypress
key: deps-node-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: Build
run: yarn pages:build
env:
NEXT_PUBLIC_API_URL: ${{ env.BRANCH_NAME == 'prod' && secrets.NEXT_PUBLIC_API_URL || secrets.NEXT_PUBLIC_API_URL_DEV }}
- name: Deploy to Cloudflare
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
command: pages deploy --branch=${{ env.BRANCH_NAME }}
outputs:
preview-url: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
deploy-env: ${{ steps.deploy.outputs.pages-environment }}
send_result:
name: Send Result
runs-on: ubuntu-latest
needs: [lint, build_and_deploy]
if: always()
steps:
- uses: actions/checkout@v4
- name: Send Lint Failed Notification
if: ${{ needs.lint.result == 'failure' }}
uses: ./.github/actions/notification
with:
TYPE: failure
TITLE: "❌ Lint Failed"
DESCRIPTION: "PR Link: [PR #${{ github.event.number }}](${{ env.PR_URL }})"
DISCORD_WEBHOOK_URL: ${{ secrets.SANDBOX_DISCORD_WEBHOOK_URL }}
- name: Send Build and Deploy Failed Notification
if: ${{ needs.build_and_deploy.result == 'failure' }}
uses: ./.github/actions/notification
with:
TYPE: failure
TITLE: "❌ Build and Deploy Failed"
DESCRIPTION: "PR Link: [PR #${{ github.event.number }}](${{ env.PR_URL }})"
DISCORD_WEBHOOK_URL: ${{ secrets.SANDBOX_DISCORD_WEBHOOK_URL }}
- name: Send Build Succeeded Notification
if: ${{ needs.build_and_deploy.result == 'success' }}
uses: ./.github/actions/notification
with:
TYPE: success
TITLE: "✅ Build Succeeded"
DESCRIPTION: "Preview URL: ${{ needs.build_and_deploy.outputs.preview-url }}\\nEnvironment: ${{ needs.build_and_deploy.outputs.deploy-env }}"
DISCORD_WEBHOOK_URL: ${{ secrets.SANDBOX_DISCORD_WEBHOOK_URL }}