Skip to content

Commit

Permalink
initial attempt at automatically sorting 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 d48d872
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/report-maker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
error_min:
default: 0
type: number
sort_dictionary:
default: false
type: boolean
gh_pat:
type: string
required: true
Expand Down Expand Up @@ -196,3 +199,64 @@ 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
steps:
- name: "Check out PR branch"
id: checkout-pr-branch
uses: actions/checkout@v4

- name: "Check write permissions"
id: check-write-permissions
env:
GITHUB_TOKEN: ${{ inputs.gh_pat }}
run: |
pr_branch=$(git rev-parse --abbrev-ref HEAD)
# Attempt to push a dummy commit to test write permissions
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
# Try to create a temporary branch and push
branch_name="test-write-permissions-$(date +%s)"
git checkout -b "$branch_name"
git commit --allow-empty -m "Test write permissions"
if git push origin "$branch_name"; then
echo "Successfully pushed to branch - write permissions confirmed"
# Clean up test branch and check the PR branch back out
git push origin --delete "$branch_name"
git checkout "$pr_branch"
exit 0
else
echo "Failed to push - insufficient write permissions"
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-permissions.outcome == 'success'
env:
GITHUB_TOKEN: ${{ inputs.gh_pat }}
run: |
dictionary_file="resources/dictionary.txt"
tmp_dictionary_file="resources/dictionary.txt.sorted"
pr_branch=$(git rev-parse --abbrev-ref HEAD)
if [ -e dictionary_file ]; then
sort $dictionary_file > $tmp_dictionary_file
diff $dictionary_file $tmp_dictionary_file
if [ $? -ne 0 ]; then
#The files are different, we need to commit
rm $dictionary_file
mv $tmp_dictionary_file $dictionary_file
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
else
echo "No changes in dictionary.txt"
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 d48d872

Please sign in to comment.