/
main.js.yml.ejs
170 lines (155 loc) · 5.4 KB
/
main.js.yml.ejs
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
name: CI
on: [push]
jobs:
###############
# Lint & Test
###############
tests:
name: Tests
runs-on: ubuntu-latest
# needs: linters
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: myapp_test
NODE_ENV: test
services:
postgres:
image: postgres:11.5
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: myapp_test
ports: ['5432:5432']
# Make sure the database is ready before we use it
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v2
# Node
- name: Setup Node
uses: actions/setup-node@v2.1.2
with:
node-version: 14.6.0
# Yarn cache/install
- name: Find yarn cache location
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: JS package cache
uses: actions/cache@v2.1.0
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install packages
run: |
yarn install --frozen-lockfile
# Setup & configure database
- name: Setup test database
env:
NODE_ENV: test
DATABASE_URL: postgresql://postgres:postgres@localhost/myapp_test
run: |
yarn db:migrate
# Build app and generate types
- name: Build App
run: yarn build
# Lint Code
- name: ESLint
run: yarn lint
# Jest Tests (API/Frontend)
- name: Run Jest Tests (API & Frontend)
env:
NODE_ENV: test
DATABASE_URL: postgresql://postgres:postgres@localhost/myapp_test
run: yarn test:ci
# E2E Tests via Cypress
- name: Run Cypress E2E Tests
uses: cypress-io/github-action@v2
with:
# build: yarn build
start: yarn test:server
wait-on: 'http://localhost:3001'
env:
NODE_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DATABASE_URL: postgresql://postgres:postgres@localhost/myapp_test
- name: Upload Cypress Screenshots
uses: actions/upload-artifact@v1
# Only capture images on failure
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
- name: Upload Cypress Videos
uses: actions/upload-artifact@v1
# Test run video was always captured, so this action uses "always()" condition
if: always()
with:
name: cypress-videos
path: cypress/videos
###############
# Deploy!
###############
deployStaging:
name: Deploy to <%= host.name === 'vercel' ? 'Preview' : 'Staging' %>
runs-on: ubuntu-latest
<% if (host.name === 'heroku') { -%>
needs: tests
<% } else { -%>
# To speed up CI builds, we deploy this in parallel
# needs: tests
<% } -%>
## For a typical Jamstack flow, the ref below should be your default branch.
## For a traditional flow that auto-deploys staging and deploys prod is as needed, keep as is
<% if (host.name === 'heroku') { -%>
if: github.ref == 'refs/heads/<%= repo.stagingBranch %>'
<% } else { -%>
if: github.ref != 'refs/heads/<%= repo.productionBranch %>' # every branch EXCEPT production
<% } -%>
steps:
- uses: actions/checkout@v2
<% if (host.name === 'vercel') { -%>
- uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID}}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}}
# SET THIS OR YOU WILL DEPLOY TO YOUR PERSONAL VERCEL NAMESPACE
# scope: ${{ secrets.VERCEL_ORG_ID }}
<% } else if (host.name === 'heroku') { -%>
- uses: akhileshns/heroku-deploy@v3.4.6
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
heroku_app_name: <%= host.staging ? host.staging.name : '' %>
<% } -%>
deployProd:
name: Deploy to Production
runs-on: ubuntu-latest
# For production deploys, make sure tests pass first
needs: tests
## For a typical Jamstack flow, the ref below should be your default branch.
## For a traditional flow that auto-deploys staging and deploys prod is as needed, keep as is
if: github.ref == 'refs/heads/<%= repo.productionBranch %>'
steps:
- uses: actions/checkout@v2
<% if (host.name === 'vercel') { -%>
- uses: ngduc/vercel-deploy-action@master
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID}}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}}
# SET THIS👇 OR YOU WILL DEPLOY TO YOUR PERSONAL VERCEL NAMESPACE
# scope: ${{ secrets.VERCEL_TEAM_ID }}
vercel-args: '--prod'
<% } else if (host.name === 'heroku') { -%>
- uses: akhileshns/heroku-deploy@v3.4.6
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
heroku_app_name: <%= host.production ? host.production.name : '' %>
<% } -%>