-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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
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 |