-
Notifications
You must be signed in to change notification settings - Fork 100
251 lines (215 loc) · 8.44 KB
/
Copy pathauto-format.yml
File metadata and controls
251 lines (215 loc) · 8.44 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
name: Auto-format
on:
pull_request:
types: [opened, synchronize]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
detect-changes:
name: Detect changes
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
mobile: ${{ steps.filter.outputs.mobile }}
models: ${{ steps.filter.outputs.models }}
migrations: ${{ steps.filter.outputs.migrations }}
templates: ${{ steps.filter.outputs.templates }}
any: ${{ steps.filter.outputs.changes != '[]' }}
steps:
- uses: dorny/paths-filter@v4
id: filter
with:
filters: |
backend:
- 'app/backend/**'
frontend:
- 'app/web/**'
mobile:
- 'app/mobile/**'
models:
- 'app/backend/src/couchers/models/**'
migrations:
- 'app/backend/src/couchers/migrations/versions/**'
templates:
- 'app/backend/templates/v2/**'
# Formatting work should happen in a single job so that we push all commits at once,
# because pushing a commit will cause the currently running workflow to abort.
autoformat:
name: Auto-format
needs: detect-changes
if: needs.detect-changes.outputs.any == 'true'
runs-on: ubuntu-latest
steps:
# Log in as the bot and checkout the PR branch
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Configure git for GitHub App
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ steps.app-token.outputs.token }}
# Format backend
- name: Install uv
if: needs.detect-changes.outputs.backend == 'true'
uses: astral-sh/setup-uv@v4
with:
version: "0.9.6"
- name: Format backend
if: needs.detect-changes.outputs.backend == 'true'
continue-on-error: true
working-directory: app/backend
run: make format
- name: Commit frontend formatting changes
if: needs.detect-changes.outputs.backend == 'true'
run: |
git add "app/backend/**/*.py"
git diff --staged --quiet || git commit -m "Format backend"
# Format frontend
- name: Setup Node.js
if: needs.detect-changes.outputs.frontend == 'true'
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Install frontend dependencies
if: needs.detect-changes.outputs.frontend == 'true'
working-directory: app/web
run: yarn install --frozen-lockfile
- name: Format frontend
if: needs.detect-changes.outputs.frontend == 'true'
continue-on-error: true
working-directory: app/web
run: yarn format
- name: Commit frontend formatting changes
if: needs.detect-changes.outputs.frontend == 'true'
run: |
git add app/web/
git diff --staged --quiet || git commit -m "Format frontend"
# Format mobile
- name: Setup Node.js
if: needs.detect-changes.outputs.mobile == 'true'
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Install mobile dependencies
if: needs.detect-changes.outputs.mobile == 'true'
continue-on-error: true
working-directory: app/mobile
run: npm ci
- name: Format mobile
if: needs.detect-changes.outputs.mobile == 'true'
working-directory: app/mobile
run: npm run format
- name: Commit mobile formatting changes
if: needs.detect-changes.outputs.mobile == 'true'
run: |
git add app/mobile/
git diff --staged --quiet || git commit -m "Format mobile"
# Generate email HTML templates
- name: Regenerate HTML from MJML templates
if: needs.detect-changes.outputs.templates == 'true'
continue-on-error: true
working-directory: app/backend/templates/v2
run: bash _build.sh
- name: Commit and push HTML template changes
if: needs.detect-changes.outputs.templates == 'true'
run: |
git add "app/backend/templates/v2/generated_html/*.html"
git diff --staged --quiet || git commit -m "Regenerate HTML templates"
# Push any commits at once, so we only invalidate the workflow once
- name: Push changes
run: git push
generate-migration:
needs: detect-changes
if: needs.detect-changes.outputs.models == 'true' && needs.detect-changes.outputs.migrations == 'false' && github.actor != 'dependabot[bot]'
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:18-3.6
env:
POSTGRES_PASSWORD: testpassword
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Configure git for GitHub App
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ steps.app-token.outputs.token }}
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Generate protobuf files
working-directory: app/backend
run: make protos
- name: Create PostGIS extensions
env:
PGPASSWORD: testpassword
run: |
psql -h localhost -U postgres -d postgres -c "CREATE EXTENSION IF NOT EXISTS postgis;"
psql -h localhost -U postgres -d postgres -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
psql -h localhost -U postgres -d postgres -c "CREATE EXTENSION IF NOT EXISTS btree_gist;"
- name: Load backend.dev.env
run: grep -v '^#' app/backend.dev.env | grep '=' >> "$GITHUB_ENV"
- name: Override database connection string
run: echo "DATABASE_CONNECTION_STRING=postgresql://postgres:testpassword@localhost:5432/postgres" >> "$GITHUB_ENV"
- name: Run all existing migrations
working-directory: app/backend
run: uv run alembic upgrade head
- name: Check if migration is needed
id: check-migration
working-directory: app/backend
run: |
if uv run alembic check; then
echo "needed=false" >> "$GITHUB_OUTPUT"
else
echo "needed=true" >> "$GITHUB_OUTPUT"
fi
- name: Generate migration
if: steps.check-migration.outputs.needed == 'true'
working-directory: app/backend
run: |
uv run alembic revision --autogenerate -m "${{ github.event.pull_request.title }}"
# Remove Alembic auto-generated comment lines
sed -i '/###.*Alembic/d' src/couchers/migrations/versions/*.py
- name: Format backend
working-directory: app/backend
run: make format
- name: Commit and push migration if created
run: |
git add "app/backend/src/couchers/migrations/versions/*.py"
git diff --staged --quiet || (git commit -m "Generate migrations" && git push)