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 Job to automatically sort the dictionary file if desired. #41

Merged
merged 1 commit into from
Jan 8, 2025
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So no need for the token argument then?


- name: "Check write permissions"
id: check-write-permissions
run: |
sudo apt-get install -y jq
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this is good. We should make this a function and use this elsewhere because permissions (or lack thereof) is a frequent issue for ottr users.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add this to the docker image so this can be used everywhere

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
Loading