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

Add workflow to check sorting #30

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/check_sorting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

file="awesome-generator/awesome.toml"
exit_code=0

IFS=";"

# shellcheck disable=SC2207
# This just feels like the easiest to understand. I don't know how to split the
# file on multiple newlines any better way.
# Ref: https://stackoverflow.com/a/62608718/2274551
sections=($(awk -v RS= -v ORS=";" '{print}' "$file"))

for section in "${sections[@]}"; do
header=$(echo "$section" | head -n 1)
rows=$(echo "$section" | tail -n +2)
sorted=$(echo "$rows" | sort)

if [ "$rows" != "$sorted" ]; then
invalid_sections+=("$header")
exit_code=1
fi
done

if [ $exit_code -ne 0 ]; then
cat <<-EOF
Thanks for adding new resources to this project!

To help with consistency and easie maintenance, e.g. spot duplicates the items in each section is sorted alphanumerically

Your change doesn't conform to this so please ensure the section(s) you've edited are sorted!

These sections are currently not sorted:

EOF

for s in "${invalid_sections[@]}"; do
echo " - \\\`$s\\\`"
done
fi

exit $exit_code
57 changes: 57 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Validate `awesome.toml`

on:
workflow_dispatch:
push:
branches:
- main
pull_request:

jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Validate sections
id: validate
run: |
set +e # Allow the script to fail but capture its output
{
echo "output<<EOF"
bash .github/workflows/check_sorting.sh
exit_code="$?"
echo EOF
} >> "$GITHUB_OUTPUT"

echo "exit_code=$exit_code" >> "$GITHUB_OUTPUT"

exit "$exit_code"

- name: Post PR Comment
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
COMMENT_BODY="${{ steps.validate.outputs.output }}"
EXIT_CODE="${{ steps.validate.outputs.exit_code }}"
EXISTING_COMMENT=$(gh pr view "$PR_NUMBER" \
--json comments \
--jq '.comments[] | select(.author.login=="github-actions")')

if [ "$EXIT_CODE" -ne 0 ]; then
if [ -n "$EXISTING_COMMENT" ]; then
gh pr comment "$PR_NUMBER" --body "$COMMENT_BODY" --edit-last
else
gh pr comment "$PR_NUMBER" --body "$COMMENT_BODY"
fi
else
if [ -n "$EXISTING_COMMENT" ]; then
# Currently the gh cli and the API fail to delete comments so we
# just update any existing one for now.
gh pr comment "$PR_NUMBER" --body "Thanks for fixing the CI issues!" --edit-last
fi
fi
2 changes: 1 addition & 1 deletion awesome-generator/awesome.toml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@

[device_apps]
"https://github.com/333fred/fta-monitor-garmin-watchapp" = {}
"https://github.com/BleachDev/GarminQ" = {}
"https://github.com/BleachDev/Rainy" = {}
"https://github.com/CernovApps/rubik-watch-timer" = { description = "This is a timer for Rubik Cube, with features that makes it similar to the WCA rules." }
"https://github.com/Cybermite/GolfApp" = {}
Expand Down Expand Up @@ -563,7 +564,6 @@
"https://gitlab.com/ravenfeld/Connect-IQ-App-ChronoGym" = { name = "Chrono Gym", description = "Set count and rest timer" }
"https://gitlab.com/ravenfeld/Connect-IQ-App-Compass" = { name = "Compass App", description = "Compass" }
"https://gitlab.com/ravenfeld/Connect-IQ-App-Timer" = { name = "Timer", description = "Add several timer already registered" }
"https://github.com/BleachDev/GarminQ" = {}

[audio_content_providers]
"https://github.com/memen45/SubMusic" = {}
Expand Down