Skip to content

Commit 9c0711e

Browse files
committed
Split into 'docs' and 'test' job
1 parent 7a79d0a commit 9c0711e

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

.github/workflows/main.yml

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ permissions:
1717
id-token: write
1818

1919
jobs:
20-
build:
20+
docs:
2121
runs-on: ubuntu-latest
22-
timeout-minutes: 3
22+
timeout-minutes: 1
23+
steps:
24+
- name: Docs
25+
run: npx typedoc
26+
- uses: actions/upload-pages-artifact@v2
27+
with:
28+
path: ./docs
29+
test:
2330
services:
2431
postgres:
2532
image: postgres
@@ -35,7 +42,12 @@ jobs:
3542
--health-retries 5
3643
strategy:
3744
matrix:
38-
node-version: ['18.x', '20.x']
45+
environment:
46+
- type: node
47+
version: 18.x
48+
- type: node
49+
runs-on: ubuntu-latest
50+
timeout-minutes: 3
3951
steps:
4052
- run: |
4153
function set() {
@@ -49,46 +61,62 @@ jobs:
4961
set synchronous_commit off
5062
docker kill --signal=SIGHUP ${{ job.services.postgres.id }}
5163
- uses: actions/checkout@v4
64+
- name: Use Node.js ${{ matrix.environment.version }}
65+
if: matrix.environment.type == 'node'
66+
uses: actions/setup-node@v3
67+
with:
68+
node-version: ${{ matrix.environment.version }}
5269
- name: Install dependencies
70+
if: matrix.environment.type == 'node'
5371
run: npm ci
5472
- name: Run tests
55-
run: npm run test:prod
73+
run: |
74+
case $ENVIRONMENT in
75+
node)
76+
npm run test:prod
77+
;;
78+
esac
5679
env:
80+
ENVIRONMENT: ${{ matrix.environment.type }}
5781
PGSSLMODE: disable
5882
PGPORT: ${{ job.services.postgres.ports[5432] }}
5983
PGUSER: postgres
6084
PGPASSWORD: postgres
6185
- name: Run tests (SSL)
6286
run: |
6387
docker cp ${{ job.services.postgres.id }}:/etc/ssl/certs/ssl-cert-snakeoil.pem ./
64-
npm run test:prod || exit 1
65-
npm run build
66-
cat <<- EOF > test.mjs
67-
import { Client } from './dist/src/index.js';
68-
const client = new Client();
69-
const secured = await client.connect();
70-
console.log(secured);
71-
await client.end();
88+
gen_code() {
89+
cat <<- EOF
90+
import { Client } from '$1';
91+
const client = new Client();
92+
const secured = await client.connect();
93+
console.log(secured);
94+
await client.end();
7295
EOF
96+
}
7397
set -o pipefail
74-
node test.mjs | tee /dev/stderr | grep -q true
98+
case $ENVIRONMENT in
99+
node)
100+
npm run test:prod || exit 1
101+
npm run build
102+
gen_code ./dist/src/index.js > test.mjs
103+
node test.mjs | tee /dev/stderr | grep -q true
104+
;;
105+
esac
75106
env:
107+
ENVIRONMENT: ${{ matrix.environment.type }}
76108
NODE_EXTRA_CA_CERTS: ssl-cert-snakeoil.pem
77109
PGSSLMODE: require
78110
PGPORT: ${{ job.services.postgres.ports[5432] }}
79111
PGUSER: postgres
80112
PGPASSWORD: postgres
81-
- name: Docs
82-
run: npx typedoc
83-
- uses: actions/upload-pages-artifact@v2
84-
with:
85-
path: ./docs
86113
deploy:
114+
if: github.ref_name == 'master'
87115
runs-on: ubuntu-latest
88116
environment:
89117
name: github-pages
90118
url: ${{ steps.deployment.outputs.page_url }}
91-
needs: build
119+
needs: [test, docs]
92120
steps:
93121
- name: Deploy to GitHub Pages
94122
id: deployment

0 commit comments

Comments
 (0)