hubverse-org / schemas

JSON schemas for modeling hubs
Creative Commons Zero v1.0 Universal
4 stars 3 forks source link

Ensure schema files are styled consistently between versions #107

Open annakrystalli opened 1 month ago

annakrystalli commented 1 month ago

In #106 I used the following commands to un-collapse any arrays in the schema files:

jq -c --indent 4 . v3.0.1/tasks-schema.json | sponge v3.0.1/tasks-schema.json
jq -c --indent 4 . v3.0.1/admin-schema.json | sponge v3.0.1/admin-schema.json

This does not change any of the content of the files, just the formatting but will allow diffs in #103 to be show up correctly.

Going forward, it would be good to stick to such standard formatting as it will make pin-pointing changes between versiions much clearer.

I can see to needs for folks updating the schema:

  1. An easy way to deploy the styling (a la R styler package). For example, it would be good not to manually have to update version numbers in the snippet above. Also the above uses sponge which is something chatgpt suggested when I asked it not to not to create temp files when re-writing the styled files, which it was initially. Perhaps we don't want to add more dependencies on top of jq.
  2. An easy way to remind whoever is modifying the schema to perform the styling (a la linter). I think a git pre-commit hook could be be useful here?

@zkamvar would be interested in your thoughts about how best to ensure all our schemas undergo this transformation prior to making a PR but suggestions welcome by anyone!

zkamvar commented 1 month ago

Going forward, it would be good to stick to such standard formatting as it will make pin-pointing changes between versiions much clearer.

THIS SO MUCH THIS.

I think it would be good to include this as a small shell script in the repo so that people don't have to think about the exact jq incantation (below).

We could have a GitHub workflow that does this via a PR command a la /diff that would do the transformation and automatically push to the PR (see https://github.com/r-lib/actions/blob/v2-branch/examples/pr-commands.yaml) (NOTE: for people to be able to run this, their membership in this organization needs to be public).

Regarding sponge... I don't think we need it. We are not so constrained for space that we can't do this with a temp file:

tmp=$(mktemp) && jq -c --indent 4 . v3.0.1/tasks-schema.json > $tmp && cp $tmp v3.0.1/tasks-schema.json && rm $tmp

Written as a BASH script, we could have it transform both at once.

#!/usr/bin/env bash

version="${1:-v3.0.1}"
tasks="${version}/tasks-schema.json"
admin="${version}/admin-schema.json"

tmp="$(mktemp)"
# clean up the tasks schema
jq -c --indent 4 . "${tasks}" > "${tmp}"
cp "${tmp}" "${tasks}"
# clean up the admin schema
jq -c --indent 4 . "${admin}" > "${tmp}"
cp "${tmp}" "${admin}"
rm "${tmp}"
annakrystalli commented 1 month ago

Cool! I think it would be cool if we did not have to specify the latest version number but for the script to auto-detect it.

The one thing I am not at all a fan of is PR actions that modify the contents of the remote branch. The unsynching of local and remote can cause annoying merge conflicts. It would be preferable for me if we had a way to remind folks to do this before they commit/push etc.