Skip to content

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

IsaacG
Copy link
Member

@IsaacG IsaacG commented May 27, 2025

jq '.exercises.practice = (.exercises.practice|sort_by(.difficulty, .slug))' config.json > t && mv t config.json

@IsaacG IsaacG requested review from glennj and rabestro May 27, 2025 05:50
config.json Outdated
"slug": "raindrops",
"name": "Raindrops",
"uuid": "7aedb0b6-a4c6-4985-a85c-9b641f4ae047",
"slug": "two-fer",
Copy link
Contributor

@glennj glennj May 27, 2025

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.

Copy link
Member Author

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.

@rabestro
Copy link
Member

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.

Copy link
Member

@rabestro rabestro left a comment

Choose a reason for hiding this comment

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

Merge conflicts...

@IsaacG
Copy link
Member Author

IsaacG commented May 27, 2025

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

@rabestro rabestro left a comment

Choose a reason for hiding this comment

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

LGFM

@glennj
Copy link
Contributor

glennj commented May 28, 2025

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.

@glennj glennj closed this May 28, 2025
@glennj glennj reopened this May 28, 2025
@glennj glennj merged commit 16983b8 into exercism:main May 28, 2025
4 checks passed
glennj pushed a commit to glennj/exercism-awk that referenced this pull request Jun 26, 2025
```
jq '.exercises.practice = (.exercises.practice|sort_by(.difficulty, .slug))' config.json > t && mv t config.json
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants