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
|
|
|
|
|
2024-01-24 16:39:22 +00:00
|
|
|
- name: Get docs manifest
|
|
|
|
id: docs-manifest
|
|
|
|
uses: tj-actions/changed-files@v37
|
|
|
|
with:
|
|
|
|
files: |
|
|
|
|
docs/docs-manifest.json
|
|
|
|
|
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-24 16:39:22 +00:00
|
|
|
npm --prefix .github/workflows/scripts install @actions/core
|
2023-08-15 01:13:01 +00:00
|
|
|
|
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
|
|
|
|
|
2024-01-24 16:39:22 +00:00
|
|
|
- name: Check if docs manifest is valid JSON
|
|
|
|
id: is-valid-json
|
|
|
|
run: node .github/workflows/scripts/is-valid-json.js docs/docs-manifest.json
|
|
|
|
|
2024-01-09 14:09:59 +00:00
|
|
|
- name: Lint docs changed markdown files
|
|
|
|
run: |
|
|
|
|
RED="\e[1;31m"
|
|
|
|
GREEN="\e[1;32m"
|
|
|
|
NC="\e[0m"
|
|
|
|
set -e
|
|
|
|
rc=0
|
2024-01-24 16:39:22 +00:00
|
|
|
changed_files="${{ steps.docs-changed-files.outputs.all_changed_files }}"
|
|
|
|
changed_manifest="${{ steps.docs-manifest.outputs.all_changed_files }}"
|
|
|
|
is_valid_json="${{ steps.is-valid-json.outputs.is-valid-json }}"
|
|
|
|
storybook="no"
|
|
|
|
for L in ${{github.event.pull_request.labels.*.name}}
|
|
|
|
do
|
|
|
|
if [ $L == "type: storybook" ]; then
|
|
|
|
storybook="yes"
|
|
|
|
fi
|
|
|
|
done
|
2024-01-09 14:09:59 +00:00
|
|
|
if [ -n "$changed_files" ]; then
|
|
|
|
lint_results=""
|
2024-01-24 16:39:22 +00:00
|
|
|
failed_check=""
|
2024-01-09 14:09:59 +00:00
|
|
|
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
|
2024-01-24 16:39:22 +00:00
|
|
|
|
2024-01-09 14:09:59 +00:00
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
echo -e "${RED}Linting failed for one or more files${NC}"
|
|
|
|
echo -e "$lint_results"
|
2024-01-24 16:39:22 +00:00
|
|
|
failed_check="lint"
|
2024-01-09 14:09:59 +00:00
|
|
|
else
|
|
|
|
echo -e "${GREEN}Linting successful for all files.${NC}"
|
2023-08-15 01:13:01 +00:00
|
|
|
fi
|
2024-01-24 16:39:22 +00:00
|
|
|
|
|
|
|
if [ "$storybook" == "no" ]; then
|
|
|
|
if [ -z "$changed_manifest" ]; then
|
|
|
|
echo -e "${RED}Changes in the docs folder require updating the manifest${NC}"
|
|
|
|
failed_check="manifest"
|
|
|
|
fi
|
|
|
|
if [ "$is_valid_json" == "no" ]; then
|
|
|
|
echo -e "${RED}'docs/docs-manifest.json' is not valid JSON${NC}"
|
|
|
|
failed_check="manifest"
|
|
|
|
fi
|
|
|
|
if [ "$failed_check" == "manifest" ]; then
|
|
|
|
echo -e "Generate a manifest with 'pnpm utils md-docs create docs woocommerce -o docs/docs-manifest.json'"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$failed_check" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-01-09 14:09:59 +00:00
|
|
|
else
|
|
|
|
echo "No docs markdown files changed."
|
|
|
|
fi
|