2023-08-15 01:13:01 +00:00
|
|
|
name: MarkdownLint on PR
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
paths-ignore:
|
|
|
|
- '**/changelog/**'
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
lint:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
with:
|
|
|
|
fetch-depth: 2
|
|
|
|
|
2024-01-09 14:09:59 +00:00
|
|
|
- name: Get repo changed files
|
|
|
|
id: repo-changed-files
|
2023-08-15 01:13:01 +00:00
|
|
|
uses: tj-actions/changed-files@v37
|
|
|
|
with:
|
|
|
|
files: |
|
|
|
|
**/*.md
|
2023-11-07 21:46:27 +00:00
|
|
|
files_ignore: |
|
2024-01-09 14:09:59 +00:00
|
|
|
docs/**/*.md
|
2023-08-15 01:13:01 +00:00
|
|
|
|
2024-01-09 14:09:59 +00:00
|
|
|
- name: Get docs changed files
|
|
|
|
id: docs-changed-files
|
|
|
|
uses: tj-actions/changed-files@v37
|
|
|
|
with:
|
|
|
|
files: |
|
|
|
|
docs/**/*.md
|
|
|
|
|
2023-08-15 01:13:01 +00:00
|
|
|
- name: Setup PNPM
|
|
|
|
uses: pnpm/action-setup@c3b53f6a16e57305370b4ae5a540c2077a1d50dd
|
|
|
|
with:
|
|
|
|
version: '8.6.7'
|
|
|
|
|
|
|
|
- name: Setup Node
|
|
|
|
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
|
|
|
|
with:
|
|
|
|
node-version-file: .nvmrc
|
|
|
|
cache: pnpm
|
|
|
|
registry-url: 'https://registry.npmjs.org'
|
|
|
|
|
|
|
|
- name: Install prerequisites
|
|
|
|
run: |
|
|
|
|
pnpm i -g markdownlint-cli
|
|
|
|
|
2024-01-09 14:09:59 +00:00
|
|
|
- name: Lint repo changed markdown files
|
2023-08-15 01:13:01 +00:00
|
|
|
run: |
|
|
|
|
RED="\e[1;31m"
|
|
|
|
GREEN="\e[1;32m"
|
|
|
|
NC="\e[0m"
|
|
|
|
set -e
|
|
|
|
rc=0
|
2024-01-09 14:09:59 +00:00
|
|
|
changed_files="${{ steps.repo-changed-files.outputs.all_changed_files }}"
|
2023-08-15 01:13:01 +00:00
|
|
|
if [ -n "$changed_files" ]; then
|
|
|
|
lint_results=""
|
|
|
|
for file in $changed_files; do
|
|
|
|
lint_result=$( { cat "$file" | markdownlint --stdin ; } 2>&1 ) || rc="$?"
|
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
lint_results="$lint_results\n>>>Linting failed for file: $file <<<\n$lint_result\n--------"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
echo -e "${RED}Linting failed for one or more files${NC}"
|
|
|
|
echo -e "$lint_results"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo -e "${GREEN}Linting successful for all files.${NC}"
|
|
|
|
fi
|
|
|
|
else
|
2024-01-09 14:09:59 +00:00
|
|
|
echo "No repo markdown files changed."
|
|
|
|
fi
|
|
|
|
|
|
|
|
- name: Lint docs changed markdown files
|
|
|
|
run: |
|
|
|
|
RED="\e[1;31m"
|
|
|
|
GREEN="\e[1;32m"
|
|
|
|
NC="\e[0m"
|
|
|
|
set -e
|
|
|
|
rc=0
|
|
|
|
changed_files="${{ steps.docs-changed-files.outputs.all_changed_files }}"
|
|
|
|
if [ -n "$changed_files" ]; then
|
|
|
|
lint_results=""
|
|
|
|
for file in $changed_files; do
|
|
|
|
lint_result=$( { cat "$file" | markdownlint --stdin -c docs/.markdownlint.json ; } 2>&1 ) || rc="$?"
|
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
lint_results="$lint_results\n>>>Linting failed for file: $file <<<\n$lint_result\n--------"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
echo -e "${RED}Linting failed for one or more files${NC}"
|
|
|
|
echo -e "$lint_results"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo -e "${GREEN}Linting successful for all files.${NC}"
|
2023-08-15 01:13:01 +00:00
|
|
|
fi
|
2024-01-09 14:09:59 +00:00
|
|
|
else
|
|
|
|
echo "No docs markdown files changed."
|
|
|
|
fi
|