From 7ca2d5d6039fa362464a1f5a5d6a74c9601c427d Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Wed, 10 Jan 2024 13:23:15 +0000 Subject: [PATCH] Add a CI job to ensure generated types are updated Ensure that type generation from `schema.json` is up-to-date. * Check out the repo * Run `make generate` * Ensure that there is no diff --- .github/workflows/build.yml | 17 ++++++++++++++++- Makefile | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bda86b15d..ac2f95317 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,6 +57,21 @@ jobs: fi done + type-generation: + name: type generation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Ensure generated types are up-to-date + run: | + make generate > /dev/null 2>&1 + if ! git diff --quiet; then + echo "generated types are out of date!" + echo "run `make generate` to regenerate type definitions from `schema.json`" + exit 1 + fi + license-check: name: License check runs-on: ubuntu-latest @@ -106,7 +121,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/Makefile b/Makefile index c1c2c0d5b..737b8a464 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ .PHONY: generate generate: # Generate the types from the JSON schema - docker run -v $$PWD/schema.json:/mnt/schema.json omissis/go-jsonschema:0.14.1 --only-models -p migrations --tags json /mnt/schema.json > pkg/migrations/types.go + @docker run -v $$PWD/schema.json:/mnt/schema.json omissis/go-jsonschema:0.14.1 --only-models -p migrations --tags json /mnt/schema.json > pkg/migrations/types.go # Add the license header - echo "// SPDX-License-Identifier: Apache-2.0" | cat - pkg/migrations/types.go > pkg/migrations/types.go.tmp - mv pkg/migrations/types.go.tmp pkg/migrations/types.go + @echo "// SPDX-License-Identifier: Apache-2.0" | cat - pkg/migrations/types.go > pkg/migrations/types.go.tmp + @mv pkg/migrations/types.go.tmp pkg/migrations/types.go