Skip to content

Commit da155c5

Browse files
authored
Merge pull request #92 from miharp/feat/markdownlint-diff-only
feat: lint only changed markdown files in CI
2 parents 1209544 + 0bf3280 commit da155c5

1 file changed

Lines changed: 44 additions & 5 deletions

File tree

.github/workflows/markdownlint.yml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
2-
# Managed by modulesync - DO NOT EDIT
3-
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/
4-
52
name: Markdown Lint
63

74
on:
@@ -19,7 +16,49 @@ jobs:
1916
runs-on: ubuntu-latest
2017
steps:
2118
- uses: actions/checkout@v6
19+
with:
20+
fetch-depth: 0 # required to resolve base.sha for PR diff comparison
21+
- name: Find changed Markdown files
22+
id: changed-markdown
23+
shell: bash
24+
run: |
25+
case "${GITHUB_EVENT_NAME}" in
26+
pull_request)
27+
base_sha="${{ github.event.pull_request.base.sha }}"
28+
head_sha="${GITHUB_SHA}"
29+
;;
30+
push)
31+
base_sha="${{ github.event.before }}"
32+
head_sha="${GITHUB_SHA}"
33+
;;
34+
*)
35+
# workflow_dispatch: lints only files changed in the most recent commit, not the full branch
36+
# || true handles initial commits with no parent
37+
base_sha="$(git rev-parse "${GITHUB_SHA}^" 2>/dev/null || true)"
38+
head_sha="${GITHUB_SHA}"
39+
;;
40+
esac
41+
42+
if [[ -z "${base_sha}" || "${base_sha}" =~ ^0+$ ]]; then
43+
base_sha="$(git rev-list --max-parents=0 "${head_sha}")"
44+
fi
45+
46+
git diff --name-only --diff-filter=ACMRT "${base_sha}" "${head_sha}" -- '*.md' '*.markdown' > changed-markdown-files.txt
47+
48+
if [[ -s changed-markdown-files.txt ]]; then
49+
echo "has_files=true" >> "${GITHUB_OUTPUT}"
50+
{
51+
echo 'files<<EOF'
52+
cat changed-markdown-files.txt
53+
echo 'EOF'
54+
} >> "${GITHUB_OUTPUT}"
55+
else
56+
echo "has_files=false" >> "${GITHUB_OUTPUT}"
57+
fi
58+
- name: No changed Markdown files
59+
if: steps.changed-markdown.outputs.has_files != 'true'
60+
run: echo "No changed Markdown files to lint."
2261
- uses: DavidAnson/markdownlint-cli2-action@v22
62+
if: steps.changed-markdown.outputs.has_files == 'true'
2363
with:
24-
globs: '**/*.{md,markdown}'
25-
continue-on-error: true # Allow this job to fail for now
64+
globs: ${{ steps.changed-markdown.outputs.files }}

0 commit comments

Comments
 (0)