Files
dotnet__skills/.github/workflows/markdownlint.yml
T

57 lines
1.7 KiB
YAML

name: markdownlint
on:
pull_request:
paths:
- "**/*.md"
- ".markdownlint-cli2.jsonc"
- ".github/workflows/markdownlint.yml"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 'lts/*'
- name: Detect lint scope
id: scope
run: |
# If config or workflow changed, lint all .md files; otherwise lint only changed .md files
CONFIG_CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- '.markdownlint-cli2.jsonc' '.github/workflows/markdownlint.yml')
if [ -n "$CONFIG_CHANGED" ]; then
echo "mode=all" >> "$GITHUB_OUTPUT"
else
FILES=$(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }}...HEAD -- '*.md' | tr '\n' ' ')
echo "files=$FILES" >> "$GITHUB_OUTPUT"
if [ -n "$FILES" ]; then
echo "mode=changed" >> "$GITHUB_OUTPUT"
else
echo "mode=none" >> "$GITHUB_OUTPUT"
fi
fi
- name: Run markdownlint
if: steps.scope.outputs.mode != 'none'
run: |
if [ "${{ steps.scope.outputs.mode }}" = "all" ]; then
npx markdownlint-cli2 "**/*.md"
else
npx markdownlint-cli2 ${{ steps.scope.outputs.files }}
fi