-
-
Notifications
You must be signed in to change notification settings - Fork 287
86 lines (75 loc) · 2.86 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
name: CI
on:
push:
branches: [ master ]
# Triggers the workflow on pull request events in the context of the fork
# trying to sidestep limitations here: https://github.com/wearerequired/lint-action/issues/13
pull_request:
jobs:
build-test:
runs-on: ubuntu-latest
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:12.3
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: bookbrainz_test
# Since we run npm tests on the host machine (not in a docker container)
# we need to bind the Postgres port from Docker container to host machine
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Install PostgreSQL client
run: |
sudo apt-get update
sudo apt-get install --yes postgresql-client
#Set up ElasticSearch
- name: Run Elasticsearch
# Replace this with official elastic-github-actions/elasticsearch once they are ready for prod
uses: getong/elasticsearch-action@v1.2
with:
elasticsearch version: '5.6.8'
host port: 9200
container port: 9200
host node port: 9300
node port: 9300
discovery type: 'single-node'
- name: Checkout code
uses: actions/checkout@v2
# Set up the test dabatase
- name: Set up test database in PostgreSQL
run: ./scripts/create-test-db.sh
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: bookbrainz_test
POSTGRES_HOST: localhost
- name: Set up node
uses: actions/setup-node@v1
with:
# We could also test on multiple Node versions if needed: https://github.com/actions/setup-node#matrix-testing
node-version: '18'
# Enables caching NPM dependencies (uses https://github.com/actions/cache under the hood)
cache: 'yarn'
# 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: yarn install --frozen-lockfile
- name: Run tests
run: yarn run test-ci # run tests (configured to use mocha's json reporter)
- name: Export test results
uses: actions/upload-artifact@v4 # upload test results
if: success() || failure() # run this step even if previous step failed
with:
name: test-results
path: test-results.json