forked from Devops-ohtuprojekti/DevOpsCSAOS
-
Notifications
You must be signed in to change notification settings - Fork 1
150 lines (138 loc) · 4.75 KB
/
workflow.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
name: Deploy
on:
push:
branches:
- "**"
# ignore the event if the only changed file is found in documentation path
paths-ignore:
- "documentation/**"
jobs:
build:
if: github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: test_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v2
- name: Run backend lint
working-directory: ./backend
run: npm install && npm run lint
- name: Run frontend lint
working-directory: ./frontend
run: npm install && npm run lint
- name: Run backend tests
working-directory: ./backend
# install dependencies and create the necessary databases before running tests
run: npm install && createdb -h localhost -p 5432 -U postgres dev_db && createdb -h localhost -p 5432 -U postgres prod_db && npm test
env:
DB_HOST: localhost
DB_PASS: postgres
DB_USER: postgres
SECRET_FOR_TOKEN: ${{secrets.SECRET_FOR_TOKEN}}
# createdb requires a password that has to be supplied as environment variable
PGPASSWORD: postgres
NODE_ENV: test
HUBSPOT_API_KEY: ${{secrets.HUBSPOT_API_KEY}}
- name: Run frontend tests
working-directory: ./frontend
run: npm install && npm test
end-to-end-tests:
if: github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Build the application stack
working-directory: ./end-to-end-tests
run: docker-compose up -d
- name: Wait for 10 seconds so that server is running and db initialized
uses: jakejarvis/wait-action@master
with:
time: '10s'
- name: Install python dependencies
working-directory: ./end-to-end-tests
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Check running containers
run: docker ps -a
- name: Run robot tests
working-directory: ./end-to-end-tests
run: robot --variable DB_CONFIG_FILE:resources/compose.cfg --variable BROWSER:headlessfirefox --include local tests
deploy_to_staging:
if: github.ref == 'refs/heads/staging'
runs-on: ubuntu-latest
needs: [build, end-to-end-tests]
steps:
- uses: actions/checkout@v2
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.STAGING_HEROKU_APP_NAME}}
heroku_email: ${{secrets.PROJECT_EMAIL}}
usedocker: true
docker_build_args: |
API_URL
env:
API_URL: ${{secrets.STAGING_API_URL}}
lighthouse:
if: github.ref == 'refs/heads/staging'
runs-on: ubuntu-latest
needs: deploy_to_staging
steps:
- uses: actions/checkout@v2
- name: Audit URLs using Lighthouse
uses: treosh/lighthouse-ci-action@v8
with:
urls: |
https://${{secrets.STAGING_URL}}
https://${{secrets.STAGING_URL}}/survey/questions/?id=1/
https://${{secrets.STAGING_URL}}/survey/questions/summary/
end-to-end-staging-tests:
if: github.ref == 'refs/heads/staging'
runs-on: ubuntu-latest
needs: deploy_to_staging
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install python dependencies
working-directory: ./end-to-end-tests
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Check running containers
run: docker ps -a
- name: Run robot tests
working-directory: ./end-to-end-tests
run: robot --variable SERVER:${{secrets.STAGING_URL}} --variable BROWSER:headlessfirefox --include staging tests
# accessibility test
deploy_to_production:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.PRODUCTION_HEROKU_APP_NAME}}
heroku_email: ${{secrets.PROJECT_EMAIL}}
usedocker: true
env:
SECRET_FOR_TOKEN: ${{secrets.SECRET_FOR_TOKEN}}
HUBSPOT_API_KEY: ${{secrets.HUBSPOT_API_KEY}}