This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: NodeJS CI with PostgreSQL
on: push: branches: [ master ] pull_request: branches: [ master ]
jobs: build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: <your_database_user>
POSTGRES_PASSWORD: <your_password>
POSTGRES_DB: <your_database_name>
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:
- uses: actions/checkout@v3
- name: Install dependencies
run: npm install
- name: create postgresql tables
run: PGPASSWORD=<your_databse_password> psql -h localhost -U <your_databse_user> -d <your_databse_name> -a -f <path_to_sql_script eg - ./table.sql >
- name: run tests with postgresql
run:
npm test
env:
DATABASE_URL: <your_databse_connection_string>
NB - use pg: "^8.7.1" or above