From e58dd4abf52afe809666e6aaae9b8aea41aeaecf Mon Sep 17 00:00:00 2001 From: "Jack Pettit [SSW]" <57518417+JackDevAU@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:55:17 +1000 Subject: [PATCH] Fix permissions in validate-markdown workflow --- .github/workflows/validate-markdown.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/validate-markdown.yml b/.github/workflows/validate-markdown.yml index ab1a48eed42..31d12f10579 100644 --- a/.github/workflows/validate-markdown.yml +++ b/.github/workflows/validate-markdown.yml @@ -12,7 +12,7 @@ jobs: validate-markdown: runs-on: ubuntu-latest permissions: - contents: read + contents: write issues: write repository-projects: read pull-requests: write @@ -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