Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite52d848

Browse files
authored
chore: validate queries using sqlc-vet in github actions (#11163)
1 parentdba0dfa commite52d848

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

‎.github/workflows/ci.yaml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
ts:${{ steps.filter.outputs.ts }}
3737
k8s:${{ steps.filter.outputs.k8s }}
3838
ci:${{ steps.filter.outputs.ci }}
39+
db:${{ steps.filter.outputs.db }}
3940
offlinedocs-only:${{ steps.filter.outputs.offlinedocs_count == steps.filter.outputs.all_count }}
4041
offlinedocs:${{ steps.filter.outputs.offlinedocs }}
4142
steps:
@@ -57,6 +58,12 @@ jobs:
5758
- "examples/web-server/**"
5859
- "examples/monitoring/**"
5960
- "examples/lima/**"
61+
db:
62+
- "**.sql"
63+
- "coderd/database/queries/**"
64+
- "coderd/database/migrations"
65+
- "coderd/database/sqlc.yaml"
66+
- "coderd/database/dump.sql"
6067
go:
6168
- "**.sql"
6269
- "**.go"
@@ -618,6 +625,7 @@ jobs:
618625
-test-js
619626
-test-e2e
620627
-offlinedocs
628+
-sqlc-vet
621629
# Allow this job to run even if the needed jobs fail, are skipped or
622630
# cancelled.
623631
if:always()
@@ -908,3 +916,26 @@ jobs:
908916
909917
echo "::endgroup::"
910918
done
919+
920+
# sqlc-vet runs a postgres docker container, runs Coder migrations, and then
921+
# runs sqlc-vet to ensure all queries are valid. This catches any mistakes
922+
# in migrations or sqlc queries that makes a query unable to be prepared.
923+
sqlc-vet:
924+
runs-on:${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
925+
needs:changes
926+
if:needs.changes.outputs.db == 'true' || github.ref == 'refs/heads/main'
927+
steps:
928+
-name:Checkout
929+
uses:actions/checkout@v4
930+
with:
931+
fetch-depth:1
932+
# We need golang to run the migration main.go
933+
-name:Setup Go
934+
uses:./.github/actions/setup-go
935+
936+
-name:Setup sqlc
937+
uses:./.github/actions/setup-sqlc
938+
939+
-name:Setup and run sqlc vet
940+
run:|
941+
make sqlc-vet

‎Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,11 @@ test:
708708
gotestsum --format standard-quiet -- -v -short -count=1 ./...
709709
.PHONY: test
710710

711+
sqlc-vet: test-postgres-docker
712+
echo"--- sqlc vet"
713+
SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)"\
714+
sqlc vet -f coderd/database/sqlc.yaml&&echo"Passed sqlc vet"
715+
711716
# When updating -timeout for this test, keep in sync with
712717
# test-go-postgres (.github/workflows/coder.yaml).
713718
# Do add coverage flags so that test caching works.

‎coderd/database/sqlc.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ sql:
8282
-schema:"./dump.sql"
8383
queries:"./queries"
8484
engine:"postgresql"
85+
# This only works if you are running a local postgres database with the
86+
# schema loaded and migrations run. Run `make sqlc-vet` to run the linter.
87+
database:
88+
uri:"${SQLC_DATABASE_URL}"
89+
rules:
90+
-sqlc/db-prepare
8591
gen:
8692
go:
8793
package:"database"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp