Skip to content

Conversation

@mfori
Copy link
Member

@mfori mfori commented Sep 19, 2025

follow-up to #538

We need to ensure that for schemas that have .ts file used to generate .json file:

  • users modify the .ts file not the .json file.
  • users run npm run build to generate the .json file and commits this generated file.
  • that means -> .ts and .json files are always in sync

This adds CI workflow that runs whenever this .ts or .json file changed, runs the build and check if .json file changes or not.

@mfori mfori self-assigned this Sep 19, 2025
@github-actions github-actions bot added this to the 123rd sprint - Console team milestone Sep 19, 2025
@github-actions github-actions bot added t-console Issues with this label are in the ownership of the console team. tested Temporary label used only programatically for some analytics. labels Sep 19, 2025
@mfori mfori changed the base branch from master to feat/json-schemas-package September 19, 2025 10:11
@B4nan B4nan changed the title feat(json_schemas): ci check ci: ensure JSON schemas are in sync Sep 19, 2025
Base automatically changed from feat/json-schemas-package to master September 19, 2025 10:40
@mfori mfori requested review from B4nan and valekjo September 19, 2025 10:43
@mfori mfori added the adhoc Ad-hoc unplanned task added during the sprint. label Sep 19, 2025
@mfori mfori marked this pull request as ready for review September 19, 2025 10:43
Comment on lines 38 to 58
files_to_check=(
"packages/json_schemas/src/actor.schema.ts|packages/json_schemas/schemas/actor.schema.json"
# add more ts|json pairs here
)

failed=0

for pair in "${files_to_check[@]}"; do
ts_file="${pair%%|*}"
json_file="${pair##*|}"

if ! git diff --exit-code "$json_file" >/dev/null; then
echo "ERROR: $json_file is out of sync with $ts_file."
echo "Please put the schema changes to .ts file ($ts_file) and update the .json file ($json_file) by running the build script (npm run build)."
failed=1
fi
done

if [ $failed -eq 1 ]; then
exit 1
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit overcomplicated, any reason you just don't diff the whole project? It will be fast enough, surely faster than running npm ci, building things or checking out the repo itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would literally just call git diff --exit-code, it will make the job fail if there are changes.

npm ci --no-audit
npm run build
git diff --exit-code

And this could be part of the regular test workflow, since there you need to build the project anyway, so why do it again separately. Project build should never produce any git changes, so it's a nice safeguard in general, not just for the JSON schema files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this helps with DX. If someone who never saw this repository comes to update actor.json schema he would need to dig deeper to debug the failing workflow. With this he would just see exact instructions:

ERROR: packages/json_schemas/schemas/actor.schema.json is out of sync with packages/json_schemas/src/actor.schema.ts.
Please put the schema changes to .ts file (packages/json_schemas/src/actor.schema.ts) and update the .json file (packages/json_schemas/schemas/actor.schema.json) by running the build script (npm run build).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could do what @B4nan suggests, and just write out the message with exact instructions? It's pretty likely this is not going to change, and if it was supposed to change, we'd need to update the workflow anyway.

@mfori mfori requested a review from B4nan September 19, 2025 12:25
@mfori
Copy link
Member Author

mfori commented Sep 22, 2025

@B4nan @valekjo ok, I used your suggestion. I didn't realize that git diff would output the exact place, so it shows you the changed file and that's enough.

Screenshot 2025-09-22 at 13 27 57

@valekjo
Copy link
Member

valekjo commented Sep 23, 2025

Nit: Maybe git diff --name-only --exit-code would be nicer (but idk :D)

@mfori mfori merged commit b69d2f7 into master Sep 23, 2025
9 checks passed
@mfori mfori deleted the feat/json-schemas-package-ci branch September 23, 2025 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-console Issues with this label are in the ownership of the console team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants