Skip to content

Commit

Permalink
Add GitHub workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nathhuynh committed Sep 19, 2024
1 parent 7db1a35 commit 88f5172
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/github-actions-demo.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build-and-test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:14
env:
POSTGRES_USER: ${{ secrets.DB_USER }}
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
POSTGRES_DB: ${{ secrets.DB_NAME }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
push: false
load: true
tags: app:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Run Prisma migrations
run: |
docker run --network host -e DATABASE_URL="postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@localhost:5432/${{ secrets.DB_NAME }}?schema=public" app:latest npx prisma migrate deploy
# - name: Run tests
# run: |
# docker run --network host -e DATABASE_URL="postgresql://${{ secrets.DB_USER }}:${{ secrets.DB_PASSWORD }}@localhost:5432/${{ secrets.DB_NAME }}?schema=public" app:latest npm test

- name: Run linting
run: docker run app:latest npm run lint

- name: Run type checking
run: docker run app:latest npx tsc --noEmit

8 changes: 4 additions & 4 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
environment:
- NODE_ENV=development
- NEXT_WEBPACK_USEPOLLING=1
- DATABASE_URL=postgresql://user:password@db:5432/gym_tracker?schema=public
- DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@db:5432/${DB_NAME}?schema=public
ports:
- 3000:3000
volumes:
Expand All @@ -22,9 +22,9 @@ services:
db:
image: postgres:14
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=password
- POSTGRES_DB=gym_tracker
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
Expand Down

0 comments on commit 88f5172

Please sign in to comment.