-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (126 loc) · 5.94 KB
/
ci.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
name: CI
on: push
jobs:
build:
# You must use a Linux environment when using service containers or container jobs
runs-on: ubuntu-latest
env:
ADMIN_CLIENT_ID: shortvaluefullofnumbersandlettersinlowercase
AIRBRAKE_HOST: https://my-errbit-instance.com
AIRBRAKE_KEY: longvaluefullofnumbersandlettersinlowercase
PORT: 3000
# External services - they don't exist here but we have code that depends on these values being present
EA_ADDRESS_FACADE_URL: http://localhost:8009
CHARGING_MODULE_URL: http://localhost:8020
SERVICE_FOREGROUND_URL: http://localhost:8001
SERVICE_BACKGROUND_URL: http://localhost:8012
REPORTING_URL: http://localhost:8011
IMPORT_URL: http://localhost:8007
TACTICAL_CRM_URL: http://localhost:8002
EXTERNAL_UI_URL: http://localhost:8000
INTERNAL_UI_URL: http://localhost:8008
TACTICAL_IDM_URL: http://localhost:8003
PERMIT_REPOSITORY_URL: http://localhost:8004
RETURNS_URL: http://localhost:8006
# JWT Auth token shared by all legacy external services
LEGACY_AUTH_TOKEN: longvalueofnumbersandletters.inbothcases.splitin3by2periods
# External Charging Module JWT (AWS Cognito) service
CHARGING_MODULE_TOKEN_URL: https://myinstance.amazoncognito.com
CHARGING_MODULE_TOKEN_USERNAME: valuefullofnumbersandlettersinlowercase
CHARGING_MODULE_TOKEN_PASSWORD: longvaluefullofnumbersandlettersinlowercase
# These need to be duplicated in services section for postgres. Unfortunately, there is not a way to reuse them
POSTGRES_USER: water_user
POSTGRES_PASSWORD: password
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_DB: wabs_system_test
POSTGRES_DB_TEST: wabs_system_test
ENVIRONMENT: dev
COOKIE_SECRET: 1a1028df-a2af-468a-929b-e3a274be1208
DEFAULT_USER_PASSWORD: P@55word
# Service containers to run with `runner-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:12-alpine
# Provide the password for postgres
env:
POSTGRES_USER: water_user
POSTGRES_PASSWORD: password
POSTGRES_DB: wabs_system_test
# Maps tcp port 5432 on service container to the host
ports:
- 5432:5432
# Set health checks to wait until postgres has started. You must have this so the runner knows to wait till
# postgres is up and running before proceeding
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
# Downloads a copy of the code in your repository before running CI tests
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of sonarcloud analysis
# Before we do anything, check we haven't accidentally left any `describe.only()` or `it.only(` statements in the
# tests
#
# Reworking of https://stackoverflow.com/a/21788642/6117745
- name: Temporary tag check
run: |
! grep -R 'describe.only(\|it.only(' test
# Alongside this, check we haven't accidentally left any `console.log()` while checking results in app and tests
- name: Temporary log check
run: |
if grep -R 'console.log(' ./app/ ./test/; then
echo "console.log statement found. Please remove it."
exit 1
fi
- name: Install Node
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
# Speeds up workflows by reading the node modules from cache. Obviously you need to run it at least once, and the
# cache will be updated should the package-lock.json file change
- name: Cache Node modules
uses: actions/cache@v4
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
# Performs a clean installation of all dependencies in the `package.json` file
# For more information, see https://docs.npmjs.com/cli/ci.html
- name: Install dependencies
run: npm ci
# Run editorconfig check first. No point running the tests if there are issues with the format of the files
- name: Run editorconfig check
uses: editorconfig-checker/action-editorconfig-checker@main
- run: editorconfig-checker
# Next run linting. No point running the tests if there is a linting issue
- name: Run lint check
run: |
npm run lint
# Next generate docs. This checks any JSDoc changes are valid
- name: Run docs check
run: |
npm run docs
- name: Database migrations
run: |
npm run migrate:test
# This includes an extra run step. The sonarcloud analysis will be run in a docker container with the current
# folder mounted as `/github/workspace`. The problem is when the lcov.info file is generated it will reference the
# code in the current folder. So to enable sonarcloud to matchup code coverage with the files we use sed to update
# the references in lcov.info
# https://community.sonarsource.com/t/code-coverage-doesnt-work-with-github-action/16747/6
- name: Run unit tests
run: |
npm test
sed -i 's/\/home\/runner\/work\/water-abstraction-system\/water-abstraction-system\//\/github\/workspace\//g' coverage/lcov.info
- name: Analyze with SonarCloud
if: github.actor != 'dependabot[bot]'
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This is provided automatically by GitHub
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # This needs to be set in your repo; settings -> secrets