Merge pull request #119 from malthe/issue-118-ssl-configuration #267
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: [master] | |
pull_request: | |
branches: [master] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
env: | |
PGDATADIR: /var/lib/postgresql/data | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
jobs: | |
style: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
- name: Prettier | |
run: | | |
npm i -D | |
set +e | |
npx prettier --experimental-ternaries --check | |
code=$? | |
npx prettier --experimental-ternaries --log-level warn --write | |
git diff | |
exit "$code" | |
build: | |
runs-on: ubuntu-latest | |
timeout-minutes: 1 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: NPM | |
run: | | |
set -ex | |
npm i | |
npm run prebuild | |
npm run build:cjs | |
npm run build:esm | |
echo '{"type": "commonjs"}' > dist/commonjs/package.json | |
echo '{"type": "module"}' > dist/module/package.json | |
npm i --no-save dts-bundle-generator | |
npx dts-bundle-generator -o dist/index.d.ts src/index.ts | |
mkdir dest | |
npm pack --pack-destination=dest | |
- name: Typedoc | |
run: npx typedoc | |
- name: Redirects | |
run: | | |
ref=${GITHUB_BASE_REF:-master} | |
url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/$ref | |
set +H | |
find examples -mindepth 1 -maxdepth 1 -exec sh -c " | |
mkdir -p docs/{} | |
cat << EOF > docs/{}/index.html | |
<!DOCTYPE html> | |
<meta charset='utf-8'> | |
<title>Redirecting to $url/{}</title> | |
<meta http-equiv='refresh' content='0; URL=$url/{}'> | |
<link rel='canonical' href='$url/{}'> | |
EOF | |
" \; | |
- uses: actions/upload-pages-artifact@v2 | |
with: | |
path: ./docs | |
- name: Package artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pkg | |
path: dest | |
test: | |
services: | |
postgres: | |
image: postgres | |
ports: | |
- 5432/tcp | |
env: | |
POSTGRES_PASSWORD: postgres | |
options: >- | |
--mount type=tmpfs,destination=/var/lib/postgresql/data | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
strategy: | |
matrix: | |
version: | |
- 18 | |
- 20 | |
runs-on: ubuntu-latest | |
needs: [build] | |
timeout-minutes: 3 | |
steps: | |
- run: | | |
function set() { | |
docker exec ${{ job.services.postgres.id }} sh -c "echo $1=\'$2\' >> $PGDATADIR/postgresql.conf" | |
} | |
set ssl on | |
set ssl_cert_file /etc/ssl/certs/ssl-cert-snakeoil.pem | |
set ssl_key_file /etc/ssl/private/ssl-cert-snakeoil.key | |
set fsync off | |
set full_page_writes off | |
set synchronous_commit off | |
docker kill --signal=SIGHUP ${{ job.services.postgres.id }} | |
- name: Use Node.js ${{ matrix.version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.version }} | |
- uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: npm i | |
- name: Run tests | |
run: npm run test:prod | |
env: | |
PGSSLMODE: disable | |
PGPORT: ${{ job.services.postgres.ports[5432] }} | |
PGUSER: postgres | |
PGPASSWORD: postgres | |
- name: Extract SSL cert | |
run: docker cp ${{ job.services.postgres.id }}:/etc/ssl/certs/ssl-cert-snakeoil.pem ./ | |
- name: Run tests (SSL) | |
run: npm run test:prod | |
env: | |
NODE_EXTRA_CA_CERTS: ${{ github.workspace }}/ssl-cert-snakeoil.pem | |
PGPORT: ${{ job.services.postgres.ports[5432] }} | |
PGUSER: postgres | |
PGPASSWORD: postgres | |
- uses: actions/download-artifact@v4 | |
- name: 'Example: Connect' | |
run: | | |
pkg_path=`ls $PWD/pkg/ts-postgres-*.tgz` | |
cd examples/connect | |
npm i . "$pkg_path" | |
set -o pipefail | |
PGSSLMODE=disable node main.cjs | tee /dev/stderr | grep -q false | |
PGSSLMODE=require node main.cjs | tee /dev/stderr | grep -q true | |
[[ -d v$NODE_VERSION ]] && cd v$NODE_VERSION | |
npx tsc | |
PGSSLMODE=disable node main.mjs | tee /dev/stderr | grep -q false | |
PGSSLMODE=require node main.mjs | tee /dev/stderr | grep -q true | |
env: | |
NODE_VERSION: ${{ matrix.version }} | |
NODE_EXTRA_CA_CERTS: ${{ github.workspace }}/ssl-cert-snakeoil.pem | |
PGPORT: ${{ job.services.postgres.ports[5432] }} | |
PGUSER: postgres | |
PGPASSWORD: postgres | |
- name: 'Example: Generic Pool' | |
run: | | |
pkg_path=`ls $PWD/pkg/ts-postgres-*.tgz` | |
cd examples/generic-pool | |
npm i . "$pkg_path" | |
set -o pipefail | |
npx tsc | |
PGSSLMODE=disable node main.mjs | tee /dev/stderr | grep -q false | |
PGSSLMODE=require node main.mjs | tee /dev/stderr | grep -q true | |
env: | |
NODE_EXTRA_CA_CERTS: ${{ github.workspace }}/ssl-cert-snakeoil.pem | |
PGPORT: ${{ job.services.postgres.ports[5432] }} | |
PGUSER: postgres | |
PGPASSWORD: postgres | |
deploy: | |
if: github.ref_name == 'master' | |
runs-on: ubuntu-latest | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
needs: [style, build, test] | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v2 |