Skip to content

XS✔ ◾ [⚠️Don't merge] Testing new markdown action #17

XS✔ ◾ [⚠️Don't merge] Testing new markdown action

XS✔ ◾ [⚠️Don't merge] Testing new markdown action #17

name: Validate-Markdown
on:
pull_request:
branches: [ main ]
paths:
- '**.md' # Only run workflow for Markdown file changes
workflow_dispatch:
jobs:
validate-markdown:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
repository-projects: read
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install markdownlint-cli
run: npm install -g markdownlint-cli
- name: Get changed files
id: files
uses: lots0logs/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Filter and format Markdown files
id: markdown_files
run: |
MARKDOWN_FILES=$(echo '${{ steps.files.outputs.all }}' | jq -r '.[] | select(endswith(".md"))')
echo "::set-output name=list::$MARKDOWN_FILES"
- name: Lint Markdown files
id: lint_markdown
continue-on-error: true
run: |
OUTPUT=$(markdownlint ${{ steps.markdown_files.outputs.list }} --config .markdownlint/config.json 2>&1)
echo "::set-output name=markdownlint_output::${OUTPUT}"
echo "${OUTPUT}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create comment body with error links
id: create_comment_body
if: steps.lint_markdown.outcome == 'failure'
run: |
COMMENT_BODY="There are markdown linting issues:\n"
while read -r line; do
if [[ "$line" =~ rules/(.+\.md):([0-9]+):([0-9]+) ]]; then
FILENAME=${BASH_REMATCH[1]}
LINENUMBER=${BASH_REMATCH[2]}
MESSAGE=${line/*MD/MD}
URL="https://github.com/${{ github.repository }}/blob/${{ github.sha }}/${FILENAME}#L${LINENUMBER}"
COMMENT_BODY+="[$FILENAME line $LINENUMBER]($URL): $MESSAGE\n"
fi
done <<< "${{ steps.lint_markdown.outputs.markdownlint_output }}"
echo "::set-output name=comment_body::${COMMENT_BODY}"
- name: Add Job Summary
if: steps.lint_markdown.outcome == 'failure'
run: |
echo "${{ steps.create_comment_body.outputs.comment_body }}" >> $GITHUB_STEP_SUMMARY
- name: Comment on PR
if: steps.lint_markdown.outcome == 'failure' && github.event.pull_request.head.repo.fork == false
uses: mshick/add-pr-comment@v2
with:
message: "${{ steps.create_comment_body.outputs.comment_body }}"
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: "github-actions[bot]"
allow-repeats: true