Skip to content

Commit e6a4b28

Browse files
fix(build): lint only changed markdown files in PRs
- add changed-files detection step to markdown-lint workflow - add changed-files detection step to markdown-link-check workflow - skip lint/link-check when no markdown files changed 📦 - Generated by Copilot
1 parent 08ca896 commit e6a4b28

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

.github/workflows/markdown-link-check.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ jobs:
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+
shell: bash
36+
run: |
37+
if [ "${{ github.event_name }}" == "pull_request" ]; then
38+
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- '*.md' | tr '\n' ' ')
39+
else
40+
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT HEAD~1 HEAD -- '*.md' | tr '\n' ' ')
41+
fi
42+
echo "files=$CHANGED_FILES" >> $GITHUB_OUTPUT
43+
if [ -z "$CHANGED_FILES" ]; then
44+
echo "has_changes=false" >> $GITHUB_OUTPUT
45+
else
46+
echo "has_changes=true" >> $GITHUB_OUTPUT
47+
echo "Changed markdown files: $CHANGED_FILES"
48+
fi
3149
3250
- name: Setup Node.js
3351
uses: actions/setup-node@b9b25d45f70a5d94d88496aa4896bf9ed8f49b67 # v4.1.0
@@ -36,30 +54,38 @@ jobs:
3654
cache: 'npm'
3755

3856
- name: Install dependencies
57+
if: steps.changed-files.outputs.has_changes == 'true'
3958
run: npm ci
4059

4160
- name: Create logs directory
61+
if: steps.changed-files.outputs.has_changes == 'true'
4262
shell: pwsh
4363
run: |
4464
New-Item -ItemType Directory -Force -Path logs | Out-Null
4565
4666
- name: Run markdown link check
4767
id: link-check
68+
if: steps.changed-files.outputs.has_changes == 'true'
4869
shell: pwsh
4970
run: |
50-
& scripts/linting/Markdown-Link-Check.ps1
71+
$changedFiles = "${{ steps.changed-files.outputs.files }}" -split '\s+' | Where-Object { $_ }
72+
& scripts/linting/Markdown-Link-Check.ps1 -Path $changedFiles
5173
continue-on-error: ${{ inputs.soft-fail }}
5274

75+
- name: Skip notification
76+
if: steps.changed-files.outputs.has_changes != 'true'
77+
run: echo "No markdown files changed, skipping link check."
78+
5379
- name: Upload markdown link check results
54-
if: always()
80+
if: steps.changed-files.outputs.has_changes == 'true'
5581
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v4.4.3
5682
with:
5783
name: markdown-link-check-results
5884
path: logs/markdown-link-check-results.json
5985
retention-days: 30
6086

6187
- name: Check results and fail if needed
62-
if: ${{ !inputs.soft-fail && steps.link-check.outcome == 'failure' }}
88+
if: steps.changed-files.outputs.has_changes == 'true' && !inputs.soft-fail && steps.link-check.outcome == 'failure'
6389
shell: pwsh
6490
run: |
6591
Write-Host "Markdown link check failed and soft-fail is false. Failing the job."

.github/workflows/markdown-lint.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ jobs:
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
@@ -62,7 +85,11 @@ jobs:
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

Comments
 (0)