Skip to content

Commit 0a7087d

Browse files
authored
feat: add CI check for sqlc-generated files to prevent stale code (#4554)
<!-- Thanks for sending a pull request! Here are some tips for you: --> #### What type of PR is this? Enhancement #### What this PR does / why we need it Adds a CI job that validates sqlc-generated Go files are up-to-date, preventing stale generated code from being merged. #### Which issue(s) this PR fixes <!-- *Automatically closes linked issue when PR is merged. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_* --> Fixes # #### Special notes for your reviewer Signed-off-by: Dejan Zele Pejchev <[email protected]>
1 parent 4441d67 commit 0a7087d

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

.github/workflows/test.yml

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ jobs:
4848

4949
go-unit-tests:
5050
name: Golang Unit Tests
51-
needs: go-mod-up-to-date
51+
needs:
52+
- go-mod-up-to-date
53+
- sqlc-up-to-date
5254
runs-on: ubuntu-22.04
5355

5456
steps:
@@ -84,7 +86,9 @@ jobs:
8486

8587
go-integration-tests:
8688
name: Golang Integration Tests
87-
needs: go-mod-up-to-date
89+
needs:
90+
- go-mod-up-to-date
91+
- sqlc-up-to-date
8892
runs-on: ubuntu-22.04
8993

9094
env:
@@ -235,3 +239,40 @@ jobs:
235239
fi
236240
237241
exit $changed
242+
243+
sqlc-up-to-date:
244+
name: SQLC Generated Files Up To Date
245+
runs-on: ubuntu-22.04
246+
247+
steps:
248+
- name: Checkout
249+
uses: actions/checkout@v4
250+
251+
- name: Setup Go
252+
uses: ./.github/actions/setup-go-cache
253+
with:
254+
cache-prefix: sqlc-up-to-date
255+
cache-tools: true
256+
257+
- name: Validate no changes in generated SQL files
258+
run: |
259+
go run github.com/magefile/[email protected] -v sql
260+
261+
changed=$(git status -s -uno | wc -l)
262+
263+
echo -e "### Git status" >> $GITHUB_STEP_SUMMARY
264+
if [[ "$changed" -gt 0 ]]; then
265+
echo -e "Generated SQL files are out of date. Please run 'mage sql' and commit the changes." >> $GITHUB_STEP_SUMMARY
266+
267+
git status -s -uno >> $GITHUB_STEP_SUMMARY
268+
269+
echo -e >> $GITHUB_STEP_SUMMARY
270+
echo -e "### Git diff" >> $GITHUB_STEP_SUMMARY
271+
272+
git --no-pager diff >> $GITHUB_STEP_SUMMARY
273+
else
274+
echo -e "Generated SQL files are up to date." >> $GITHUB_STEP_SUMMARY
275+
echo -e >> $GITHUB_STEP_SUMMARY
276+
fi
277+
278+
exit $changed

0 commit comments

Comments
 (0)