Skip to content

Commit

Permalink
Fix permissions in validate-markdown workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDevAU committed Nov 8, 2023
1 parent 7c9b1e6 commit e58dd4a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/validate-markdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
validate-markdown:
runs-on: ubuntu-latest
permissions:
contents: read
contents: write
issues: write
repository-projects: read
pull-requests: write
Expand Down Expand Up @@ -67,23 +67,26 @@ jobs:
if: failure() && github.event.pull_request.head.repo.fork == false
run: |
RULES_DOCS_URL="https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md"
PR_BASE_URI="https://github.com/${{ github.event.pull_request.head.repo.full_name }}/pull/${{ github.event.pull_request.number }}/files"
PR_NUMBER="${{ github.event.pull_request.number }}"
REPO_FULL_NAME="${{ github.repository }}"
PR_COMMENT="Hi @JackDevAU,\n\nThere were some Markdown Linting Errors in your pull request:\n\n"
PR_COMMENT+="| File | Error | Rule |\n"
PR_COMMENT+="| ---- | ----- | ---- |\n"
while IFS= read -r line; do
FILE_PATH=$(echo "$line" | awk -F: '{print $1}')
LINE_NUM=$(echo "$line" | awk -F: '{print $2}')
ERROR=$(echo "$line" | awk -F: 'sub(/MD[0-9]+.*/, "", $0)' | xargs)
ERROR_DESC=$(echo "$line" | cut -d' ' -f 4- | sed 's/\[.*\]//') # Remove the markdown link from the description
RULE_ID=$(echo "$line" | grep -o 'MD[0-9]\+')
FILE_LINK="${PR_BASE_URI}#diff-$(echo "$FILE_PATH" | md5sum | awk '{print $1}')"
PR_COMMENT+="| [$FILE_PATH]($FILE_LINK) | $ERROR | [Rule $RULE_ID]($RULES_DOCS_URL#$RULE_ID) |\n"
FILE_NAME=$(basename "$FILE_PATH")
FILE_ANCHOR=$(echo "$FILE_NAME" | sed 's/\./-/g')
PR_COMMENT+="| [$FILE_PATH](https://github.com/$REPO_FULL_NAME/pull/$PR_NUMBER/files#$FILE_ANCHOR) | Line $LINE_NUM: $ERROR_DESC | [Rule $RULE_ID]($RULES_DOCS_URL#$RULE_ID) |\n"
done < lint-results.txt
PR_COMMENT+="\nPlease review the errors and update your Markdown files accordingly.\n"
echo -e "$PR_COMMENT" > pr_comment.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


- name: Upload PR Comment
if: failure() && github.event.pull_request.head.repo.fork == false
uses: mshick/add-pr-comment@v2
Expand Down

0 comments on commit e58dd4a

Please sign in to comment.