Skip to content

Commit 2dba669

Browse files
committed
Create a github action to check line length in changed markdown files
1 parent a579a45 commit 2dba669

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Check markdown line limits
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.md'
7+
8+
jobs:
9+
check-markdown-lines:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Check long lines in diff
18+
run: make test-line-limits

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ update-deps:
88
tools/update-deps --cpanfile cpanfile
99

1010
.PHONY: test
11-
test: test-tidy test-critic test-yaml test-author test-t
11+
test: test-tidy test-critic test-line-limits test-yaml test-author test-t
1212

1313
.PHONY: test-tidy
1414
test-tidy:
@@ -18,6 +18,10 @@ test-tidy:
1818
test-critic:
1919
tools/perlcritic --quiet .
2020

21+
.PHONY: test-line-limits
22+
test-line-limits:
23+
tools/check_line_limits
24+
2125
.PHONY: test-yaml
2226
test-yaml:
2327
yamllint --strict ./

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ To use it in your repository, you would usually do something like this:
1717
% cd your-repo
1818
% git subrepo clone [email protected]:os-autoinst/os-autoinst-common.git ext/os-autoinst-common
1919

20-
This will automatically create a commit with information on what command
21-
was used.
22-
23-
And then, if necessary, link files via symlinks to the places where you need
20+
This will automatically create a commit with information on what command was used. And then, if necessary, link files via symlinks to the places where you need
2421
them.
2522

26-
The cloned repository files will be part of your actual repository, so anyone
27-
cloning this repo will have the files automatically without needing to use
28-
`git-subrepo` themselves.
23+
The cloned repository files will be part of your actual repository, so anyone cloning this repo will have the files automatically without needing to use `git-subrepo` themselves.
2924

3025
`ext` is just a convention, you can clone it into any directory.
3126

@@ -34,8 +29,7 @@ It's also possible to clone a branch (or a specific tag or sha):
3429
% git subrepo clone [email protected]:os-autoinst/os-autoinst-common.git \
3530
-b branchname ext/os-autoinst-common
3631

37-
After cloning, you should see a file `ext/os-autoinst-common/.gitrepo` with
38-
information about the cloned commit.
32+
After cloning, you should see a file `ext/os-autoinst-common/.gitrepo` with information about the cloned commit.
3933

4034
### Pull
4135

@@ -48,7 +42,7 @@ that:
4842

4943
% git subrepo clone --force [email protected]:os-autoinst/os-autoinst-common.git ext/os-autoinst-common
5044

51-
### Making changes
45+
### Making changes test test test testtest test test testest test test testt test test test test
5246

5347
If you make changes in the subrepo inside of your top repo, you can simply commit
5448
them and then do:
@@ -59,8 +53,7 @@ them and then do:
5953

6054
You can find more information here:
6155
* [Repository and usage](https://github.com/ingydotnet/git-subrepo)
62-
* [A good comparison between subrepo, submodule and
63-
subtree](https://github.com/ingydotnet/git-subrepo/blob/master/Intro.pod)
56+
* [A good comparison between subrepo, submodule and subtree](https://github.com/ingydotnet/git-subrepo/blob/master/Intro.pod)
6457

6558

6659
## License

tools/check_line_limits

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/bash
2+
3+
set -euo pipefail
4+
5+
BASE_SHA=$(git merge-base origin/${{ github.base_ref }} HEAD)
6+
md_files=$(git diff --name-only "$BASE_SHA" -- '*.md')
7+
8+
[ -z "$md_files" ] && echo "no markdown changed" && exit 0
9+
10+
fail=0
11+
for file in $md_files; do
12+
diff_lines=$(git diff "$BASE_SHA" -- "$file" | grep '^+' | grep -v '^+++' | cut -c2-)
13+
while IFS= read -r line; do
14+
if [[ $line =~ https?:// ]]; then
15+
continue
16+
fi
17+
18+
if [[ $line =~ ^#+[[:space:]] ]]; then
19+
continue
20+
fi
21+
22+
if [ "${#line}" -gt 80 ]; then
23+
echo "[ERROR][$file] line exceeds 80 characters: $line"
24+
fail=1
25+
fi
26+
done <<< "$diff_lines"
27+
done
28+
29+
exit $fail

0 commit comments

Comments
 (0)