Update README.md - Grammar #1695
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Markdown Link Check | |
on: | |
pull_request_target: | |
paths: | |
- '**.md' | |
- '!.github/**' | |
workflow_dispatch: | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
link-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Action | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{github.event.pull_request.head.ref}} | |
repository: ${{github.event.pull_request.head.repo.full_name}} | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
- name: Install dependencies | |
run: npm install -g markdown-link-check@3.11.0 | |
- name: Changed Files Exporter | |
if: github.event_name == 'pull_request_target' | |
id: files | |
# This uses the SHA for 4.0.1 - https://github.com/umani/changed-files/releases/tag/v4.0.1 | |
uses: umani/changed-files@0239328a3a6268aad16af7c3e4efc78e32d6c0f0 | |
with: | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: PR link check | |
if: github.event_name == 'pull_request_target' | |
env: | |
FILES: '${{ steps.files.outputs.files_updated }} ${{ steps.files.outputs.files_created }}' | |
run: | | |
echo "The Following files were changed or created:" | |
echo $FILES | |
touch log err | |
for FILE in $FILES; do echo $FILE | grep -q .*\.md\$ && markdown-link-check -q -v -c .github/configs/markdown-link-check-config.json $FILE 1>> log 2>> err; done | |
if grep -q "ERROR:" err ; then exit 1 ; else echo -e "No broken links found."; fi | |
echo $(cat log) | |
echo $(cat err) | |
- name: Repository link check | |
if: github.event_name == 'workflow_dispatch' | |
run: | | |
touch log err | |
find . -name \*.md -exec markdown-link-check -q -v --config .github/configs/markdown-link-check-config.json {} 1>> log 2>> err \; | |
if grep -q "ERROR:" err ; then exit 1 ; else echo -e "No broken links found."; fi | |
echo $(cat log) | |
echo $(cat err) | |
- name: Show broken links | |
if: failure() | |
run: | | |
cat log | awk -v RS="FILE:" 'match($0, /(\S*\.md).*\[✖\].*([0-9]*\slinks\schecked\.)(.*)/, arr ) { print "FILE:"arr[1] arr[3] > "brokenlinks.txt"}' | |
cat brokenlinks.txt | |
rm -f err log | |
- name: Upload list of broken links | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: broken-links | |
path: brokenlinks.txt | |
- name: Comment Broken Links | |
if: ${{ failure() && github.event_name == 'pull_request_target' }} | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require("fs"); | |
const brokenLinksPath = `${process.env.GITHUB_WORKSPACE}/brokenlinks.txt`; | |
const brokenLinksString = fs.readFileSync(brokenLinksPath).toString().trimEnd(); | |
github.rest.issues.createComment({ | |
issue_number: ${{ github.event.number }}, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `**The following links are broken:** \n${brokenLinksString}` | |
}) |