Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure schema files are styled consistently between versions #107

Open
annakrystalli opened this issue Oct 10, 2024 · 2 comments
Open

Ensure schema files are styled consistently between versions #107

annakrystalli opened this issue Oct 10, 2024 · 2 comments

Comments

@annakrystalli
Copy link
Member

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
Copy link
Member

zkamvar commented Oct 10, 2024

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
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants