88 lines
2.6 KiB
YAML
88 lines
2.6 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
|
|
# Run a temporary Postgres container next to your build container
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_USER: test_user
|
|
POSTGRES_PASSWORD: test_password
|
|
POSTGRES_DB: test_db
|
|
ports:
|
|
- 5433:5432
|
|
# Ensure Postgres is completely booted before running tests
|
|
options: >-
|
|
--health-cmd "pg_isready -U test_user -d test_db"
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-node-version: '20'
|
|
cache: 'npm'
|
|
|
|
- name: Install Dependencies
|
|
run: npm ci
|
|
|
|
- name: Download dbmate
|
|
run: |
|
|
sudo curl -fsSL -o /usr/local/bin/dbmate https://github.com
|
|
sudo chmod +x /usr/local/bin/dbmate
|
|
|
|
- name: Run Migrations against Test Database
|
|
working-directory: ./api
|
|
run: npx dbmate up
|
|
env:
|
|
DATABASE_URL: "postgres://test_user:test_password@saber.home.lan:5433/test_db?sslmode=disable"
|
|
|
|
# - name: Generate PgTyped Types
|
|
# run: npm run pgtyped:compile
|
|
# env:
|
|
# DATABASE_URL: "postgres://test_user:test_password@saber.home.lan:5433/test_db?sslmode=disable"
|
|
|
|
# - name: Run Application Tests
|
|
# run: npm test
|
|
# env:
|
|
# DATABASE_URL: "postgres://test_user:test_password@saber.home.lan:5433/test_db?sslmode=disable"
|
|
|
|
deploy-internal:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
# 1. Update the live internal database instance
|
|
- name: Apply DB Migrations to Live Internal DB
|
|
working-directory: ./api
|
|
run: |
|
|
sudo curl -fsSL -o /usr/local/bin/dbmate https://github.com && sudo chmod +x /usr/local/bin/dbmate
|
|
npx dbmate up
|
|
env:
|
|
DATABASE_URL: ${{ secrets.INTERNAL_PROD_DB_URL }}
|
|
|
|
# # 2. Deploy your application code (Example: Rebuilding a local container)
|
|
# - name: Deploy Container to Internal Server via SSH
|
|
# uses: appleboy/ssh-action@v1.0.3
|
|
# with:
|
|
# host: ${{ secrets.INTERNAL_SERVER_IP }}
|
|
# username: ${{ secrets.INTERNAL_SERVER_USER }}
|
|
# key: ${{ secrets.INTERNAL_SSH_PRIVATE_KEY }}
|
|
# script: |
|
|
# cd /opt/my-app
|
|
# git pull origin main
|
|
# docker compose up -d --build |