-
-
Notifications
You must be signed in to change notification settings - Fork 1
102 lines (94 loc) · 3.44 KB
/
test-pg.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
name: Node Tests with Postgres
on:
workflow_call:
inputs:
os:
description: 'A comma separated list of operating systems to test on.'
required: false
default: 'ubuntu-latest'
type: string
node-versions:
description: 'A comma separated list of Node versions to test with.'
required: false
default: '14,16,18'
type: string
pg-versions:
description: 'A comma separated list of Postgres versions to test with.'
required: false
default: '13, 12'
type: string
lockfile:
description: 'Whether to expect a lockfile or not'
required: false
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read
jobs:
resolve_inputs:
name: Resolving inputs
runs-on: ubuntu-latest
outputs:
os: ${{ steps.split-os.outputs.splitted }}
nodeVersions: ${{ steps.split-node-versions.outputs.splitted }}
pgVersions: ${{ steps.split-pg-versions.outputs.splitted }}
steps:
- id: split-os
run: echo "splitted=$(echo '${{ inputs.os }}' | jq -R -c 'split(",")')" >> $GITHUB_OUTPUT
- id: split-node-versions
run: echo "splitted=$(echo '${{ inputs.node-versions }}' | jq -R -c 'split(",")')" >> $GITHUB_OUTPUT
- id: split-pg-versions
run: echo "splitted=$(echo '${{ inputs.pg-versions }}' | jq -R -c 'split(",")')" >> $GITHUB_OUTPUT
test:
name: Node ${{ matrix.node_version }} + Postgres ${{ matrix.postgres_version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs:
- resolve_inputs
strategy:
fail-fast: false
matrix:
node_version: ${{ fromJson(needs.resolve_inputs.outputs.nodeVersions) }}
os: ${{ fromJson(needs.resolve_inputs.outputs.os) }}
postgres_version: ${{ fromJson(needs.resolve_inputs.outputs.pgVersions) }}
services:
postgres:
image: postgres:${{ matrix.postgres_version }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
# will assign a random free host port
- 5432/tcp
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
show-progress: false
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
registry-url: 'https://registry.npmjs.org'
- if: inputs.lockfile == false
run: npm install --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- if: inputs.lockfile == true
run: npm ci --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm rebuild && npm run prepare --if-present
- run: npm run test-ci
env:
DATABASE_URL: "postgres://postgres:postgres@localhost:${{ job.services.postgres.ports['5432'] }}/postgres"
DATABASE_TEST_URL: "postgres://postgres:postgres@localhost:${{ job.services.postgres.ports['5432'] }}/postgres"
PGUSER: postgres
PGPASSWORD: postgres
PGDATABASE: postgres
PGPORT: ${{ job.services.postgres.ports['5432'] }}