-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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?