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).
This commit is contained in:
Andrew Farries 2024-01-10 15:35:42 +00:00 committed by GitHub
parent 72cc1552a3
commit f1757f31a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -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"

View File

@ -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