-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (70 loc) · 2.21 KB
/
node-test-containerized.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
name: Test API against Postgres Service Container
on:
push:
branches:
- '*'
schedule:
- cron: '30 5 * * 2,4'
jobs:
install-test:
name: Node application tests
strategy:
fail-fast: false
matrix:
node: ['16', '18']
runs-on: 'ubuntu-20.04'
# These run alongside the job.
# See:
# - https://docs.github.com/en/actions/using-containerized-services/about-service-containers
# - https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers
services:
# label for service - since this job doesn't run in a container, this service is accessible at localhost
database:
image: postgres:14.2-alpine
ports:
- 5432:5432
env:
POSTGRES_USER: acronymapi
POSTGRES_PASSWORD: password
POSTGRES_DB: defaultdb
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# https://github.com/actions/checkout
- name: Checkout the commit triggering this job
uses: actions/checkout@v4
#
- name: Install Postgres Client
if: matrix.node == '16'
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends postgresql-client
#
- name: Initialize database with initdb
run: |
PGPASSWORD=password psql -h localhost -U acronymapi --dbname=defaultdb --file=initdb.sql
# https://github.com/actions/setup-node
# https://github.com/actions/cache is no longer needed with setup-node v2
- name: Setup Node with npm cache
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'npm'
#
- name: Install dependencies from package.json
run: npm install
- name: Run tests with mocks
run: npm run test
- name: Run tests against live Postgres server
if: matrix.node == '16'
run: npm --test_live_server=true run test
env:
PGUSER: acronymapi
PGPASSWORD: password
PGDATABASE: defaultdb
PGHOST: localhost
PGPORT: 5432