Skip to content

Commit e8be092

Browse files
authored
chore: add sqlc push action on releases (coder#11171)
* add sqlc push action on releases * Make sqlc push optional
1 parent c1451ca commit e8be092

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

.github/workflows/release.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,29 @@ jobs:
479479
# For gh CLI. We need a real token since we're commenting on a PR in a
480480
# different repo.
481481
GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
482+
483+
# publish-sqlc pushes the latest schema to sqlc cloud.
484+
# At present these pushes cannot be tagged, so the last push is always the latest.
485+
publish-sqlc:
486+
name: "Publish to schema sqlc cloud"
487+
runs-on: "ubuntu-latest"
488+
needs: release
489+
if: ${{ !inputs.dry_run }}
490+
steps:
491+
- name: Checkout
492+
uses: actions/checkout@v4
493+
with:
494+
fetch-depth: 1
495+
496+
# We need golang to run the migration main.go
497+
- name: Setup Go
498+
uses: ./.github/actions/setup-go
499+
500+
- name: Setup sqlc
501+
uses: ./.github/actions/setup-sqlc
502+
503+
- name: Push schema to sqlc cloud
504+
# Don't block a release on this
505+
continue-on-error: true
506+
run: |
507+
make sqlc-push

Makefile

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

711+
# sqlc-cloud-is-setup will fail if no SQLc auth token is set. Use this as a
712+
# dependency for any sqlc-cloud related targets.
713+
sqlc-cloud-is-setup:
714+
if [[ "$(SQLC_AUTH_TOKEN)" == "" ]]; then
715+
echo "ERROR: 'SQLC_AUTH_TOKEN' must be set to auth with sqlc cloud before running verify." 1>&2
716+
exit 1
717+
fi
718+
.PHONY: sqlc-cloud-is-setup
719+
720+
sqlc-push: sqlc-cloud-is-setup test-postgres-docker
721+
echo "--- sqlc push"
722+
SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \
723+
sqlc push -f coderd/database/sqlc.yaml && echo "Passed sqlc push"
724+
.PHONY: sqlc-push
725+
726+
sqlc-verify: sqlc-cloud-is-setup test-postgres-docker
727+
echo "--- sqlc verify"
728+
SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \
729+
sqlc verify -f coderd/database/sqlc.yaml && echo "Passed sqlc verify"
730+
.PHONY: sqlc-verify
731+
711732
sqlc-vet: test-postgres-docker
712733
echo "--- sqlc vet"
713734
SQLC_DATABASE_URL="postgresql://postgres:postgres@localhost:5432/$(shell go run scripts/migrate-ci/main.go)" \

coderd/database/sqlc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# It was chosen to ensure type-safety when interacting with
33
# the database.
44
version: "2"
5+
cloud:
6+
# This is the static ID for the coder project.
7+
project: "01HEP08N3WKWRFZT3ZZ9Q37J8X"
58
# Ideally renames & overrides would go under the sql section, but there is a
69
# bug in sqlc that only global renames & overrides are currently being applied.
710
overrides:

0 commit comments

Comments
 (0)