forked from OpenVoxProject/openvox-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (76 loc) · 2.9 KB
/
markdownlint.yml
File metadata and controls
86 lines (76 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
name: Markdown Lint
on:
pull_request: {}
push:
branches:
- master
workflow_dispatch: {}
permissions:
contents: read
jobs:
markdown-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # required to resolve base.sha for PR diff comparison
- name: Find changed Markdown files
id: changed-markdown
shell: bash
run: |
case "${GITHUB_EVENT_NAME}" in
pull_request)
base_sha="${{ github.event.pull_request.base.sha }}"
head_sha="${GITHUB_SHA}"
;;
push)
base_sha="${{ github.event.before }}"
head_sha="${GITHUB_SHA}"
;;
*)
# workflow_dispatch: lints only files changed in the most recent commit, not the full branch
# || true handles initial commits with no parent
base_sha="$(git rev-parse "${GITHUB_SHA}^" 2>/dev/null || true)"
head_sha="${GITHUB_SHA}"
;;
esac
if [[ -z "${base_sha}" || "${base_sha}" =~ ^0+$ ]]; then
base_sha="$(git rev-list --max-parents=0 "${head_sha}")"
fi
git diff --name-only --diff-filter=A "${base_sha}" "${head_sha}" -- '*.md' '*.markdown' > added-markdown-files.txt
git diff --name-only --diff-filter=CMRT "${base_sha}" "${head_sha}" -- '*.md' '*.markdown' > modified-markdown-files.txt
if [[ -s added-markdown-files.txt ]]; then
echo "has_added=true" >> "${GITHUB_OUTPUT}"
{
echo 'added_files<<EOF'
cat added-markdown-files.txt
echo 'EOF'
} >> "${GITHUB_OUTPUT}"
else
echo "has_added=false" >> "${GITHUB_OUTPUT}"
fi
if [[ -s modified-markdown-files.txt ]]; then
echo "has_modified=true" >> "${GITHUB_OUTPUT}"
{
echo 'modified_files<<EOF'
cat modified-markdown-files.txt
echo 'EOF'
} >> "${GITHUB_OUTPUT}"
else
echo "has_modified=false" >> "${GITHUB_OUTPUT}"
fi
- name: No changed Markdown files
if: steps.changed-markdown.outputs.has_added != 'true' && steps.changed-markdown.outputs.has_modified != 'true'
run: echo "No changed Markdown files to lint."
- name: Lint new Markdown files (enforced)
uses: DavidAnson/markdownlint-cli2-action@v23
if: steps.changed-markdown.outputs.has_added == 'true'
with:
globs: ${{ steps.changed-markdown.outputs.added_files }}
- name: Lint modified Markdown files (advisory)
uses: DavidAnson/markdownlint-cli2-action@v23
if: steps.changed-markdown.outputs.has_modified == 'true'
continue-on-error: true
with:
globs: ${{ steps.changed-markdown.outputs.modified_files }}