Repository navigation
136 lines (130 loc) · 4.06 KB
/
Copy pathci.yml
File metadata and controls
136 lines (130 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: ci
on:
push:
branches: [main]
pull_request:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
api:
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/api
services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_USER: hackproof
POSTGRES_PASSWORD: hackproof
POSTGRES_DB: hackproof
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U hackproof"
--health-interval 5s
--health-timeout 5s
--health-retries 10
env:
DATABASE_URL: postgresql://hackproof:hackproof@localhost:5432/hackproof
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: apps/api/uv.lock
- run: uv sync --frozen
- run: uv run ruff check .
- run: uv run ruff format --check .
- run: uv run sqlfluff lint db/schema src/hackproof/sql
- name: A schema change needs a migration file
if: github.event_name == 'pull_request'
working-directory: .
run: |
base="origin/${{ github.base_ref }}"
changed=$(git diff --name-only "$base...HEAD" -- apps/api/db/schema ':!apps/api/db/schema/manifest.sql')
added=$(git diff --name-only --diff-filter=A "$base...HEAD" -- apps/api/db/migrations)
if [ -n "$changed" ] && [ -z "$added" ]; then
echo "::error::The schema files changed but no migration file was added. Run 'hackproof schema plan' and commit the file it writes."
exit 1
fi
- name: Build the schema on an empty database
run: uv run hackproof schema apply
- name: The schema files and the database agree
run: uv run hackproof schema verify
- run: uv run pytest
web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm lint
- run: pnpm format:check
- run: pnpm build
migrate:
needs: api
if: github.event_name == 'push'
runs-on: ubuntu-latest
environment: production
concurrency:
group: migrate-production
cancel-in-progress: false
defaults:
run:
working-directory: apps/api
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: apps/api/uv.lock
- run: uv sync --frozen
- name: Apply the schema to production
env:
DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}
run: |
if [ -z "$DATABASE_URL" ]; then
echo "::error::Add the PRODUCTION_DATABASE_URL secret. The schema must be migrated before the API deploys."
exit 1
fi
mkdir -p "$RUNNER_TEMP/plan"
uv run hackproof schema apply --remote --out-dir "$RUNNER_TEMP/plan"
- name: Keep the plan that ran
if: always()
uses: actions/upload-artifact@v4
with:
name: production-plan
path: ${{ runner.temp }}/plan
if-no-files-found: ignore
deploy-api:
needs: [api, migrate]
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
api:
- 'apps/api/**'
- 'data/*.yaml'
- 'railway.json'
- if: steps.changes.outputs.api == 'true'
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
run: |
if [ -z "$RAILWAY_TOKEN" ]; then
echo "::warning::RAILWAY_TOKEN is not set, skipping the deploy"
exit 0
fi
npm install --global @railway/cli
railway up --service api --ci