2828 uses : actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v4.2.2
2929 with :
3030 persist-credentials : false
31+ fetch-depth : 0
32+
33+ - name : Get changed markdown files
34+ id : changed-files
35+ run : |
36+ if [ "${{ github.event_name }}" == "pull_request" ]; then
37+ CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- '*.md' | xargs)
38+ else
39+ CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT HEAD~1 HEAD -- '*.md' | xargs)
40+ fi
41+ echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
42+ if [ -z "$CHANGED_FILES" ]; then
43+ echo "has_changes=false" >> $GITHUB_OUTPUT
44+ else
45+ echo "has_changes=true" >> $GITHUB_OUTPUT
46+ echo "Changed markdown files: $CHANGED_FILES"
47+ fi
3148
3249 - name : Setup Node.js
3350 uses : actions/setup-node@b9b25d45f70a5d94d88496aa4896bf9ed8f49b67 # v4.1.0
@@ -36,22 +53,28 @@ jobs:
3653 cache : ' npm'
3754
3855 - name : Install dependencies
56+ if : steps.changed-files.outputs.has_changes == 'true'
3957 run : npm ci
4058
4159 - name : Run markdown lint
4260 id : markdown-lint
61+ if : steps.changed-files.outputs.has_changes == 'true'
4362 run : |
44- npm run lint:md > markdown-lint-output.txt 2>&1 || echo "MARKDOWN_LINT_FAILED=true" >> $GITHUB_ENV
63+ npm run lint:md -- ${{ steps.changed-files.outputs.files }} > markdown-lint-output.txt 2>&1 || echo "MARKDOWN_LINT_FAILED=true" >> $GITHUB_ENV
4564 cat markdown-lint-output.txt
4665 continue-on-error : true
4766
67+ - name : Skip notification
68+ if : steps.changed-files.outputs.has_changes != 'true'
69+ run : echo "No markdown files changed, skipping lint."
70+
4871 - name : Create annotations
4972 if : env.MARKDOWN_LINT_FAILED == 'true'
5073 run : |
5174 echo "::warning::Markdown lint found violations. Review markdown-lint-output.txt artifact for details."
5275
5376 - name : Upload markdown lint results
54- if : always()
77+ if : steps.changed-files.outputs.has_changes == 'true'
5578 uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v4.4.3
5679 with :
5780 name : markdown-lint-results
6285 if : always()
6386 run : |
6487 echo "## Markdown Lint Results" >> $GITHUB_STEP_SUMMARY
65- if [ "${{ env.MARKDOWN_LINT_FAILED }}" == "true" ]; then
88+ if [ "${{ steps.changed-files.outputs.has_changes }}" != "true" ]; then
89+ echo "⏭️ **Status**: Skipped" >> $GITHUB_STEP_SUMMARY
90+ echo "" >> $GITHUB_STEP_SUMMARY
91+ echo "No markdown files changed in this PR." >> $GITHUB_STEP_SUMMARY
92+ elif [ "${{ env.MARKDOWN_LINT_FAILED }}" == "true" ]; then
6693 echo "❌ **Status**: Failed" >> $GITHUB_STEP_SUMMARY
6794 echo "" >> $GITHUB_STEP_SUMMARY
6895 echo "Markdown linting violations detected. Please review the artifact for details." >> $GITHUB_STEP_SUMMARY
0 commit comments