-
Notifications
You must be signed in to change notification settings - Fork 19
197 lines (182 loc) · 6.71 KB
/
prod-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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Promote staging to PROD
on:
pull_request:
paths:
- .github/workflows/prod-deploy.yml # For testing changes, won't deploy to prod
release:
types:
- released
workflow_dispatch:
inputs:
tag:
description: 'The release tag to promote (e.g. v1.2.3) do not append centrifuge-app to the tag'
required: true
type: string
concurrency:
group: production-deployment
cancel-in-progress: false
jobs:
get-release-artifacts:
name: download-${{ matrix.artifact.name }}
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'
strategy:
matrix:
artifact:
- name: webpack
path: centrifuge-app/build/
- name: pinning-api
path: pinning-api/dist/
- name: onboarding-api
path: onboarding-api/dist/
steps:
- name: Determine release version
id: version
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "version=${{ github.event.release.id }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "version=tags/centrifuge-app/${{ inputs.tag }}" >> $GITHUB_OUTPUT
else
# For PR events, get the latest release tag
LATEST_TAG=$(curl -s -H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/centrifuge/apps/releases/latest" | \
jq -r '.tag_name')
echo "version=tags/${LATEST_TAG}" >> $GITHUB_OUTPUT
fi
- uses: dsaltares/fetch-gh-release-asset@aa2ab1243d6e0d5b405b973c89fa4d06a2d0fff7 # v1.1.2
with:
repo: 'centrifuge/apps'
version: ${{ steps.version.outputs.version }}
file: "${{ matrix.artifact.name }}.zip"
target: "${{ matrix.artifact.name }}.zip"
- name: Unzip release files
env:
ZIPFILE: ${{ matrix.artifact.name }}
run: |
ls -la
unzip $ZIPFILE 1> /dev/null
ls -la
- name: Upload webpack files
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact.name }}
path: ${{ matrix.artifact.path }}
deploy-app:
name: app-prod-deploy
needs: get-release-artifacts
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
environment: production
if: ${{ github.event_name != 'pull_request' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: apps
sparse-checkout: |
.github/actions/deploy-gcs
- name: Deploy to GCS
uses: ./apps/.github/actions/deploy-gcs
with:
GWIP: ${{ secrets.GWIP }}
GSA: ${{ secrets.GSA }}
bucket_url: 'app.centrifuge.io'
artifact_name: webpack
deploy-functions:
name: ${{ matrix.function.name }}-prod-deploy
needs: get-release-artifacts
runs-on: ubuntu-latest
environment: production
permissions:
contents: 'read'
id-token: 'write'
strategy:
fail-fast: false
matrix:
function:
- name: pinning-api
handler: pinningApi
- name: onboarding-api
handler: onboarding
steps:
- name: Set service account
id: set-sa
run: |
if [ "${{ matrix.function.name }}" = "pinning-api" ]; then
echo "SERVICE_ACCOUNT=${{ vars.PINNING_API_FUNCT_SA }}" >> $GITHUB_ENV
elif [ "${{ matrix.function.name }}" = "onboarding-api" ]; then
echo "SERVICE_ACCOUNT=${{ vars.ONBOARDING_FUNCT_SA }}" >> $GITHUB_ENV
fi
- name: Checkout
uses: actions/checkout@v4
with:
path: apps
sparse-checkout: |
.github/actions/deploy-gfunction
- name: Debug deployment variables
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "App Name: ${{ matrix.function.name }}-production"
echo "Artifact Name: ${{ matrix.function.name }}"
echo "GWIP: ${{ secrets.GWIP }}"
echo "GSA: ${{ secrets.GSA }}"
echo "Target: ${{ matrix.function.handler }}"
echo "Gcloud Region: ${{ vars.GCLOUD_REGION }}"
echo "Service Account: ${{ env.SERVICE_ACCOUNT }}"
echo "Deploy Environment: production"
- name: Deploy Gfunction
id: functionsdeploy
uses: ./apps/.github/actions/deploy-gfunction
if: ${{ github.event_name != 'pull_request' }}
with:
app_name: "${{ matrix.function.name }}-production"
artifact_name: ${{ matrix.function.name }}
GWIP: ${{ secrets.GWIP }}
GSA: ${{ secrets.GSA }}
target: ${{ matrix.function.handler }}
gcloud_region: ${{ vars.GCLOUD_REGION }}
service_account: ${{ env.SERVICE_ACCOUNT }}
deploy_env: production
slack-notify-success:
needs: [deploy-app, deploy-functions]
if: success()
runs-on: ubuntu-latest
steps:
- name: Notify prod deploy success
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # v2.3.2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: |
✅ Production deployment successful!
app.staging.centrifuge.io has been promoted to app.centrifuge.io and is now LIVE!
Check out the new release -> https://github.com/centrifuge/apps/releases/
SLACK_USERNAME: 'Centrifuge GHA Bot'
SLACK_ICON: 'https://centrifuge.io/favicon.ico'
SLACK_TITLE: 'Centrifuge app has been promoted to prod.'
SLACK_FOOTER: 'Automatic message from centrifuge/apps repository Actions'
MSG_MINIMAL: true
SLACK_COLOR: 'good'
slack-notify-failure:
needs: [deploy-app, deploy-functions]
if: failure() && ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
steps:
- name: Notify prod deploy failure
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # v2.3.2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: |
❌ Production deployment failed!
One or more jobs failed during the promotion to production.
Please check the workflow run for details -> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SLACK_USERNAME: 'Centrifuge GHA Bot'
SLACK_ICON: 'https://centrifuge.io/favicon.ico'
SLACK_TITLE: '⚠️ Production Deployment Failed'
SLACK_FOOTER: 'Automatic message from centrifuge/apps repository Actions'
MSG_MINIMAL: true
SLACK_COLOR: 'danger'