ci: reorder versions.json #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: reorder-versions | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| jobs: | |
| reorder-versions: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: gh-pages | |
| - name: Show existing versions.json | |
| run: | | |
| cat versions.json | |
| shell: bash | |
| - name: Reorder versions.json | |
| run: | | |
| DEFAULT_BRANCH="${{ github.event.repository.default_branch }}" | |
| jq --arg DEFAULT_BRANCH "$DEFAULT_BRANCH" ' | |
| . as $all | | |
| [ | |
| # 1. Default branch | |
| ($all | map(select(.version == $DEFAULT_BRANCH))[]), | |
| # 2. numeric versions like 1.4 | |
| ($all | |
| | map(select(.version | test("^[0-9]+\\.[0-9]+$"))) | |
| | sort_by(.version | split(".") | map(tonumber)) | |
| | reverse | |
| | .[] | |
| ), | |
| # 3. PR versions: pr-123 | |
| ($all | |
| | map(select(.version | test("^pr-[0-9]+$"))) | |
| | sort_by(.version | ltrimstr("pr-") | tonumber) | |
| | .[] | |
| ), | |
| # 4. everything else (other branches) | |
| ($all | |
| | map(select(.version | test("^(main|[0-9]+\\.[0-9]+|pr-[0-9]+)$") | not)) | |
| | sort_by(.version) | |
| | .[] | |
| ) | |
| ] | |
| ' versions.json > versions.sorted.json | |
| shell: bash | |
| - name: Show sorted versions.json | |
| run: | | |
| cat versions.sorted.json | |
| shell: bash | |
| - name: Show the diff | |
| run: | | |
| git diff versions.json versions.sorted.json || true | |
| shell: bash | |
| - name: Replace versions.json | |
| run: | | |
| mv versions.sorted.json versions.json | |
| shell: bash | |
| - name: Commit and push changes | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| # Commit only if changed | |
| if git diff --quiet; then | |
| echo "No changes to commit." | |
| exit 0 | |
| fi | |
| git add versions.json | |
| git commit -m "Reorder versions.json" | |
| git push | |
| shell: bash |