Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ jobs:
fi
done

type-generation:
name: type generation
format:
name: format
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
Expand All @@ -111,16 +111,40 @@ jobs:
run: |
go install mvdan.cc/gofumpt@latest

- name: Generate types
- name: Run make format
run: |
chmod 666 pkg/state/init.sql
make format

- name: Ensure code is formatted
run: |
if ! git diff --quiet; then
echo "code formatting is out-of-date!"
echo "run 'make format' to reformat"
exit 1
fi

code-generation:
name: code generation
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Generate code
run: |
chmod 666 pkg/state/init.sql
make generate

- name: Ensure generated types are up-to-date
- name: Ensure generated code is up-to-date
run: |
if ! git diff --quiet; then
echo "generated types are out of date!"
echo "run 'make generate' to regenerate type definitions"
echo "generated code is out of date!"
echo "run 'make generate' to regenerate"
exit 1
fi

Expand Down Expand Up @@ -232,7 +256,7 @@ jobs:
runs-on: ubuntu-24.04
container:
image: goreleaser/goreleaser-cross:v1.24
needs: [test, lint, examples-schema-validation, examples, license-check, type-generation, dead-code-check, check-ledger, cross-build]
needs: [test, lint, examples-schema-validation, examples, license-check, format, code-generation, dead-code-check, check-ledger, cross-build]
if: startsWith(github.ref, 'refs/tags/')
env:
DOCKER_CLI_EXPERIMENTAL: "enabled"
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ format:
docker run --rm -v $$PWD/schema.json:/mnt/schema.json node:alpine npx prettier /mnt/schema.json --parser json --tab-width 2 --single-quote --trailing-comma all --no-semi --arrow-parens always --print-width 120 --write
# Format embedded SQL
docker run --rm -v $$PWD/pkg/state/init.sql:/data/init.sql backplane/pgformatter --inplace /data/init.sql
# Run gofumpt
gofumpt -w .

generate: format
generate:
# Generate the types from the JSON schema
docker run --rm -v $$PWD/schema.json:/mnt/schema.json omissis/go-jsonschema:0.17.0 --only-models -p migrations --tags json /mnt/schema.json > pkg/migrations/types.go

# Add the license header
# Add the license header to the generated type file
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

# Generate the cli-definition.json file
go run tools/build-cli-definition.go

Expand Down