-
-
Notifications
You must be signed in to change notification settings - Fork 24
Sort practice exercises by difficulty then slug. #309
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
Conversation
IsaacG
commented
May 27, 2025
config.json
Outdated
"slug": "raindrops", | ||
"name": "Raindrops", | ||
"uuid": "7aedb0b6-a4c6-4985-a85c-9b641f4ae047", | ||
"slug": "two-fer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two-fer is usually a good 2nd exercise.
Let's make isogram difficulty 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse
was also 1, bumping to 2.
This got me thinking about how we could automate it, so no one has to remember to run it manually in the future. We could integrate this directly into our repository workflow. My main idea is to use a GitHub Action. We can create a workflow that automatically runs your jq command every time the config.json file is changed on the main branch. The action would then commit the sorted file back to the repository if it was updated. It's a "set it and forget it" solution. Here’s what the workflow file would look like: # .github/workflows/sort-exercises.yml
name: Sort Practice Exercises
on:
push:
branches:
- main
paths:
- 'config.json'
jobs:
sort-json-file:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Sort practice exercises
run: |
jq '.exercises.practice |= sort_by(.difficulty, .slug)' config.json > temp.json && mv temp.json config.json
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if ! git diff --quiet config.json; then
git add config.json
git commit -m "chore: Sort practice exercises in config.json"
git push
else
echo "No changes to commit."
fi The big advantage here is that it's all handled server-side, so contributors don't need to do any special setup on their machines. Just to mention another option, we could also use a pre-commit hook. This would run the script on a developer's machine before they commit. It gives instant feedback, but it requires everyone to install the pre-commit framework locally, which might be a small hurdle for contributors. For our project, I think the GitHub Action is the better approach. What do you think of this idea? If you agree, we can add this workflow as part of this PR or in a follow-up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge conflicts...
I'm not opposed to an automatic check. I'm not a huge fan of automatic commits, though. I definitely think that's worth discussion separately from this change, though. I think sorting the exercises is worth doing and ought to be a stand alone PR. |
``` jq '.exercises.practice = (.exercises.practice|sort_by(.difficulty, .slug))' config.json > t && mv t config.json ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGFM
Regarding automatic commits, I don't think it's worth the added complexity. We're not adding that many new exercises, and we can put the new exercise in the right place. Or not, in which case, we collectively spend a few minutes once a year to PR it. |
``` jq '.exercises.practice = (.exercises.practice|sort_by(.difficulty, .slug))' config.json > t && mv t config.json ```