From f1757f31a270c593e45b67ea79cd38af5c16cc21 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Wed, 10 Jan 2024 15:35:42 +0000 Subject: [PATCH] Add CI check for up-to-date type generation (#225) Add a CI check to ensure that the `types.go` file generated from `schema.json` is up-to-date. Types are generated from the `schema.json` file but there was no check in place to ensure that the two were consistent. This PR runs `make generate` to correct an inconsistency between the definitions and the generated types and adds the check so that we can't repeat this mistake. An example failed run where the types are out of date is [here](https://github.com/xataio/pgroll/actions/runs/7475710605/job/20344427261). --- .github/workflows/build.yml | 22 ++++++++++++++++++++-- pkg/migrations/types.go | 6 +++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bda86b1..57b1562 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,8 +57,26 @@ jobs: fi done + type-generation: + name: type generation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Generate types + run: | + make generate + + - name: Ensure generated types are up-to-date + run: | + if ! git diff --quiet; then + echo "generated types are out of date!" + echo "run 'make generate' to regenerate type definitions" + exit 1 + fi + license-check: - name: License check + name: license check runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -106,7 +124,7 @@ jobs: release: runs-on: ubuntu-latest - needs: [test, lint, examples, license-check] + needs: [test, lint, examples, license-check, type-generation] if: startsWith(github.ref, 'refs/tags/') env: DOCKER_CLI_EXPERIMENTAL: "enabled" diff --git a/pkg/migrations/types.go b/pkg/migrations/types.go index 106d45a..4d4214e 100644 --- a/pkg/migrations/types.go +++ b/pkg/migrations/types.go @@ -192,9 +192,13 @@ type PgRollMigration struct { Name string `json:"name"` // Operations corresponds to the JSON schema field "operations". - Operations []interface{} `json:"operations"` + Operations PgRollOperations `json:"operations"` } +type PgRollOperation interface{} + +type PgRollOperations []interface{} + // Replica identity definition type ReplicaIdentity struct { // Name of the index to use as replica identity