Skip to content

Commit

Permalink
add job for automatically sorting the provided dictionary file
Browse files Browse the repository at this point in the history
  • Loading branch information
acoffman committed Dec 17, 2024
1 parent 540adba commit f3b4b20
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
58 changes: 55 additions & 3 deletions .github/workflows/report-maker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ on:
error_min:
default: 0
type: number
gh_pat:
type: string
required: true
sort_dictionary:
default: false
type: boolean
branch_name:
type: string
default: ${GITHUB_REF#refs/heads/}
secrets:
gh_pat:
required: true
jobs:
status-update:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -196,3 +199,52 @@ jobs:
No ${{ steps.setup2.outputs.error_name }}! :tada:
_Comment updated at ${{ steps.build-components2.outputs.time }} with changes from ${{ steps.build-components2.outputs.commit_id }}_
edit-mode: replace

sort-dictionary:
runs-on: ubuntu-latest
if: inputs.sort_dictionary && inputs.check_type == 'spelling'
steps:
- name: "Check out PR branch"
id: checkout-pr-branch
uses: actions/checkout@v4

- name: "Check write permissions"
id: check-write-permissions
run: |
sudo apt-get install -y jq
WRITE_PERMISSION=$(curl -s -H "Authorization: token ${{ secrets.gh_pat }}" https://api.github.com/repos/${{ github.repository }} | jq '.permissions.push')
if [ $WRITE_PERMISSION != "true" ]; then
echo "Do not have write permissions to the repo"
exit 1
fi
- name: "Sort dictionary file"
id: sort-dictionary
# Only run the sort if we're going to be able to commit the result back
if: steps.check-write-permissions.outcome == 'success'
run: |
dictionary_file="resources/dictionary.txt"
tmp_dictionary_file="resources/dictionary.txt.sorted"
pr_branch=${{ inputs.branch_name }}
git fetch origin
git checkout $pr_branch
if [ -e $dictionary_file ]; then
sort -f $dictionary_file > $tmp_dictionary_file
if ! diff $dictionary_file $tmp_dictionary_file ; then
#The files are different, we need to commit
rm $dictionary_file
mv $tmp_dictionary_file $dictionary_file
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add $dictionary_file
git commit -m 'Sort dictionary file'
git pull --rebase --set-upstream origin $pr_branch --allow-unrelated-histories --strategy-option=ours
git push origin $pr_branch
exit 0
else
echo "No changes in dictionary.txt"
exit 0
fi
else
echo "Dictionary not found at expected location"
exit 1
fi
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
description: "There are three types of reports that can be done and specified: 'spelling', 'urls', or 'quiz_format'."
required: true
type: string
sort_dictionary:
description: "Should this action automatically alphabetize your dictionary.txt"
default: false
type: boolean
error_min:
description: "What number of errors should make this check fail?"
default: 0
Expand Down

0 comments on commit f3b4b20

Please sign in to comment.