Skip to content

fix: revert test script to use --detectOpenHandles for better handlin… #15

fix: revert test script to use --detectOpenHandles for better handlin…

fix: revert test script to use --detectOpenHandles for better handlin… #15

Workflow file for this run

name: Express Server CI/CD Workflow
on:
push:
branches: ["@dilshan"]
jobs:
build-and-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: rest-api-db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
node-version: [22.x, 24.x]
steps:
- name: Checkout code to runner
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "${{ matrix.node-version }}"
- name: Install dependencies
run: npm install
# Up and running db is required for prisma migration commands
- name: Setup Database and run Tests
env:
DATABASE_URL: postgres://postgres:password@localhost:5432/rest-api-db
run: |
# Wait for postgres to be ready (prevents connection errors)
until pg_isready -h localhost -p 5432; do
echo "Waiting for Postgres..."
sleep 2
done
npx prisma generate
npx prisma migrate deploy
npm test
- name: Create short SHA for tagging
uses: benjlevesque/short-sha@v3.0
id: short-sha
with:
length: 7
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Docker Image to @Docker Hub
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/express-server:${{ steps.short-sha.outputs.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max