This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
171 lines (168 loc) · 6.38 KB
/
main.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
name: CI
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout code
- uses: actions/setup-node@v1
name: Setup node
with:
node-version: '10.x'
- uses: actions/cache@v1
name: Cache app dependencies
with:
path: node_modules
key: ${{ runner.os }}-app-v1.2-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-app-v1.2-
- run: yarn install --frozen-lockfile --prefer-offline
name: Install app dependencies
env:
CYPRESS_CACHE_FOLDER: node_modules/cypress_bin
- run: yarn lint
name: Lint app
- run: yarn build
name: Build app
- run: yarn test --watchAll=false --passWithNoTests
name: Test app
- uses: actions/cache@v1
name: Cache functions dependencies
with:
path: functions/node_modules
key: ${{ runner.os }}-functions-v1.0-${{ hashFiles('functions/yarn.lock') }}
restore-keys: |
${{ runner.os }}-functions-v1.0-
- run: yarn install --frozen-lockfile --prefer-offline
name: Install functions dependencies
working-directory: functions
- run: yarn lint
name: Lint functions
working-directory: functions
- run: yarn build
name: Build functions
working-directory: functions
- run: yarn test
name: Test functions
working-directory: functions
- name: E2E tests
run: |
yarn serve -p 3000 &
yarn wait-on "http://localhost:3000" -t 300000
yarn cypress run
env:
CYPRESS_CACHE_FOLDER: node_modules/cypress_bin
deploy:
needs: test
runs-on: ubuntu-latest
env:
SENTRY_ORG: inato
SENTRY_PROJECT: anticovid-backend
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/staging'
steps:
- uses: actions/checkout@v2
name: Checkout code
- uses: actions/setup-node@v1
name: Setup node
with:
node-version: '10.x'
- uses: actions/cache@v1
name: Cache app dependencies
with:
path: node_modules
key: ${{ runner.os }}-app-v1.2-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-app-v1.2-
- run: yarn install --frozen-lockfile --prefer-offline
name: Install app dependencies
- uses: actions/cache@v1
name: Cache functions dependencies
with:
path: functions/node_modules
key: ${{ runner.os }}-functions-v1.0-${{ hashFiles('functions/yarn.lock') }}
restore-keys: |
${{ runner.os }}-functions-v1.0-
- run: yarn install --frozen-lockfile --prefer-offline
name: Install functions dependencies
working-directory: functions
- if: github.ref == 'refs/heads/staging'
name: Set staging configuration
run: cp src/config/config.staging.json src/config/config.json
- if: github.ref == 'refs/heads/master'
name: Set production configuration
run: cp src/config/config.prod.json src/config/config.json
- run: yarn build
name: Build the app
- run: yarn --cwd ./functions build
name: Build the functions
- uses: w9jds/firebase-action@master
name: Use firebase production environment
if: github.ref == 'refs/heads/master'
with:
args: use production
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
- uses: w9jds/firebase-action@master
name: Use firebase staging environment
if: github.ref == 'refs/heads/staging'
with:
args: use staging
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
- name: Create new Sentry release
id: sentry
run: |
curl -sL https://sentry.io/get-cli/ | bash
# Create new Sentry release
export SENTRY_RELEASE=$(sentry-cli releases propose-version)
sentry-cli releases new -p $SENTRY_PROJECT $SENTRY_RELEASE
sentry-cli releases set-commits --auto $SENTRY_RELEASE
sentry-cli releases finalize $SENTRY_RELEASE
echo ::set-output name=release::$SENTRY_RELEASE
- name: Deploy staging sentry release
if: github.ref == 'refs/heads/staging'
run: sentry-cli releases deploys ${{ steps.sentry.outputs.release }} new -e staging
- name: Deploy production sentry release
if: github.ref == 'refs/heads/master'
run: sentry-cli releases deploys ${{ steps.sentry.outputs.release }} new -e production
- name: Set sentry release to firebase functions
uses: w9jds/firebase-action@master
with:
args: functions:config:set sentry.release=${{ steps.sentry.outputs.release }}
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
- uses: w9jds/firebase-action@master
name: Deploy to firebase
with:
args: deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
- name: Index trials in Algolia for staging
if: github.ref == 'refs/heads/staging'
run: curl -f https://us-central1-anticovid-staging.cloudfunctions.net/refreshAlgoliaTrialIndex
- name: Set Algolia settings for staging
if: github.ref == 'refs/heads/staging'
run: curl -f https://us-central1-anticovid-staging.cloudfunctions.net/setAlgoliaSettings
- name: Index trials in Algolia for production
if: github.ref == 'refs/heads/master'
run: curl -f https://us-central1-anticovid.cloudfunctions.net/refreshAlgoliaTrialIndex
- name: Set Algolia settings for production
if: github.ref == 'refs/heads/master'
run: curl -f https://us-central1-anticovid.cloudfunctions.net/setAlgoliaSettings
notify_slack_on_failure:
name: Notify slack on workflow failure
needs: deploy
runs-on: ubuntu-latest
if: always() && github.event_name == 'push'
steps:
- uses: technote-space/workflow-conclusion-action@v1
- uses: 8398a7/action-slack@v3
with:
status: ${{ env.WORKFLOW_CONCLUSION }}
fields: commit,author,job
if: env.WORKFLOW_CONCLUSION == 'failure'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}