-
Notifications
You must be signed in to change notification settings - Fork 58
195 lines (162 loc) · 5.01 KB
/
ci.yml
File metadata and controls
195 lines (162 loc) · 5.01 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: CI
on:
pull_request:
branches: ["*"]
push:
branches: ["main"]
merge_group:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
migration_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
uses: ./tooling/github/setup
- name: Generate migrations
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
run: pnpm db:generate
- name: Verify migrations are committed
run: |
if [ -n "$(git status --porcelain -- packages/db/drizzle)" ]; then
echo "Detected uncommitted migration changes in packages/db/drizzle."
echo "Run 'pnpm db:generate' and commit the generated files."
git status --short -- packages/db/drizzle
exit 1
fi
migration_apply_fresh:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: forge
options: >-
--health-cmd="pg_isready -U postgres -d forge"
--health-interval=10s
--health-timeout=5s
--health-retries=5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Setup
uses: ./tooling/github/setup
- name: Apply migrations on a fresh database
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/forge
run: |
pnpm db:migrate
pnpm db:migrate
migration_upgrade_smoke:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && vars.ENABLE_DB_UPGRADE_SMOKE == 'true'
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: local
options: >-
--health-cmd="pg_isready -U postgres -d local"
--health-interval=10s
--health-timeout=5s
--health-retries=5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup
uses: ./tooling/github/setup
- name: Create base branch worktree
run: git worktree add /tmp/forge-base "${{ github.event.pull_request.base.sha }}"
- name: Install base branch dependencies
working-directory: /tmp/forge-base
run: pnpm install --ignore-scripts
- name: Materialize base branch schema
working-directory: /tmp/forge-base
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/local
run: |
if node -e "const pkg = require('./package.json'); process.exit(pkg.scripts['db:migrate'] ? 0 : 1)"; then
pnpm db:migrate
else
pnpm --filter=@forge/db push
fi
- name: Restore filtered prod-like data
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/local
MINIO_ENDPOINT: ${{ secrets.MINIO_ENDPOINT }}
MINIO_ACCESS_KEY: ${{ secrets.MINIO_ACCESS_KEY }}
MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY }}
run: pnpm db:pull --truncate
- name: Apply branch migrations on prod-like data
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/local
run: |
pnpm db:migrate
pnpm db:migrate
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
uses: ./tooling/github/setup
- name: Lint
run: pnpm lint && pnpm lint:ws
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
uses: ./tooling/github/setup
- name: Format
run: pnpm format
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
uses: ./tooling/github/setup
- name: Typecheck
run: pnpm typecheck
build:
runs-on: ubuntu-latest
needs: [migration_check, migration_apply_fresh, lint, format, typecheck]
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup
uses: ./tooling/github/setup
- name: Copy env
run: cp .env.example .env
- name: Build
run: pnpm build
migrate_prod:
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && vars.ENABLE_PROD_DB_MIGRATIONS == 'true'
runs-on: ubuntu-latest
needs: [build]
concurrency:
group: db-migrate-prod
cancel-in-progress: false
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup
uses: ./tooling/github/setup
- name: Apply database migrations
env:
DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }}
run: pnpm db:migrate