-
Notifications
You must be signed in to change notification settings - Fork 1
133 lines (110 loc) Β· 5.03 KB
/
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
name: π Deployments
env:
SERVICE_NAME_SERVER: "college-ecosystem-server"
on:
push:
branches:
- main
- staging
workflow_dispatch:
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
lint:
uses: ./.github/workflows/lint-project.yml
deploy-frontend-to-vercel:
needs: lint
runs-on: ubuntu-latest
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: π Detect changed projects
id: changed
run: |
git diff --quiet HEAD^ HEAD ./apps/platform || echo "platform_changed=true" >> $GITHUB_OUTPUT
git diff --quiet HEAD^ HEAD ./apps/website || echo "website_changed=true" >> $GITHUB_OUTPUT
git diff --quiet HEAD^ HEAD ./apps/mail-server || echo "mail_server_changed=true" >> $GITHUB_OUTPUT
- uses: pnpm/action-setup@v2
with:
version: 9
- name: π οΈ Setup Node.js
uses: actions/setup-node@v4
if: steps.changed.outputs.platform_changed == 'true' || steps.changed.outputs.website_changed == 'true'
with:
node-version: 20.x
cache: "pnpm"
- name: πΎ Cache Vercel CLI
uses: actions/cache@v4
if: steps.changed.outputs.platform_changed == 'true' || steps.changed.outputs.website_changed == 'true' || steps.changed.outputs.mail_server_changed == 'true'
with:
path: ~/.vercel
key: ${{ runner.os }}-vercel-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-vercel-
- name: π¦ Install Vercel CLI
if: steps.changed.outputs.platform_changed == 'true' || steps.changed.outputs.website_changed == 'true'
run: pnpm install -g vercel
- name: π― Deploy Platform to Staging
if: github.ref == 'refs/heads/staging' && steps.changed.outputs.platform_changed == 'true'
run: vercel --token ${{ secrets.VERCEL_TOKEN }} ./apps/platform
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PLATFORM_PROJECT_ID }}
- name: π Deploy Platform to Production
if: github.ref == 'refs/heads/main' && steps.changed.outputs.platform_changed == 'true'
run: vercel --token ${{ secrets.VERCEL_TOKEN }} --prod ./apps/platform
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PLATFORM_PROJECT_ID }}
- name: π Deploy Website to Production
if: github.ref == 'refs/heads/main' && steps.changed.outputs.website_changed == 'true'
run: vercel --token ${{ secrets.VERCEL_TOKEN }} --prod ./apps/website
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_WEBSITE_PROJECT_ID }}
- name: π Deploy MAIl Server to Production
if: github.ref == 'refs/heads/main' && steps.changed.outputs.mail_server_changed == 'true'
run: vercel --token ${{ secrets.VERCEL_TOKEN }} --prod ./apps/mail-server
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_MAIL_SERVER_PROJECT_ID }}
dockerize-and-deploy-server:
needs: lint
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging' || github.event_name == 'workflow_dispatch'
steps:
- name: π₯ Checkout repository
uses: actions/checkout@v4
- name: π Check changes in Server Directory
id: server-changed
run: |
git diff --quiet HEAD^ HEAD ./apps/server || echo "server_changed=true" >> $GITHUB_OUTPUT
git diff --quiet HEAD^ HEAD ./apps/server/Dockerfile || echo "dockerfile_changed=true" >> $GITHUB_OUTPUT
- name: π Set up Google Cloud Auth SDK
if: steps.server-changed.outputs.server_changed == 'true'
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.CREDENTIALS_JSON }}
- name: βοΈ Log in Docker to GCR
if: steps.server-changed.outputs.server_changed == 'true'
uses: docker/login-action@v2
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.CREDENTIALS_JSON }}
- name: π³ Build and Push Docker Image
if: steps.server-changed.outputs.server_changed == 'true'
run: |
IMAGE_NAME="gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ env.SERVICE_NAME_SERVER }}:latest"
docker build --pull --rm -f "apps/server/Dockerfile" -t "${IMAGE_NAME}" "apps/server"
docker push "${IMAGE_NAME}"
- name: π Deploy to Cloud Run
if: success()
run: |
IMAGE_NAME="gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ env.SERVICE_NAME_SERVER }}:latest"
gcloud run deploy ${{ env.SERVICE_NAME_SERVER }} \
--image "${IMAGE_NAME}" \
--platform managed \
--region ${{ secrets.GCP_PROJECT_REGION }} \
--allow-unauthenticated