Skip to content

Commit 5d13f39

Browse files
lsiepelJonathan Gilbert
authored andcommitted
Add markdown action (openhab#19010)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
1 parent cc07d55 commit 5d13f39

6 files changed

Lines changed: 136 additions & 12 deletions

File tree

.github/markdownlint.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# From: https://github.com/openhab/openhab-docs/blob/main/.github/.markdownlint.yaml
2+
3+
default: true
4+
5+
# Expect dash usage for unordered lists
6+
MD004:
7+
style: dash
8+
9+
# Allow long line lengths
10+
MD013: false
11+
12+
# Allow duplicate headers for different nesting
13+
MD024:
14+
siblings_only: true
15+
16+
# Allow Multiple top level headers in the same document
17+
MD025: false
18+
19+
# Allow trailing punctuation in headers
20+
MD026: false
21+
MD029:
22+
style: one
23+
24+
# Allow inline HTML
25+
MD033: false
26+
27+
# Code block style
28+
MD046:
29+
style: fenced
30+
31+
# Emphasis in underscore
32+
MD049:
33+
style: underscore
34+
35+
# Strong in asterisk
36+
MD050:
37+
style: asterisk
38+
39+
MD060: false

.github/scripts/maven-build

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,58 @@ function print_reactor_summary() {
1414
cat "$BUILD_LOG" | sed -n "${start},${end}p" | sed 's/\[INFO\] //'
1515
}
1616

17+
gha_escape() {
18+
sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/\n/%0A/g'
19+
}
20+
21+
emit_markdownlint_annotations() {
22+
[[ -f "$BUILD_LOG" ]] || return 0
23+
24+
while IFS= read -r l; do
25+
file=$(echo "$l" | sed -E 's/^([^:]+\.md):.*/\1/')
26+
line=$(echo "$l" | sed -E 's/^[^:]+\.md:([0-9]+).*/\1/')
27+
28+
# Repair path so GitHub can link it (repo-root relative)
29+
if [[ ! -f "$file" ]]; then
30+
if [[ -f "bundles/$file" ]]; then
31+
file="bundles/$file"
32+
elif [[ -f "itests/$file" ]]; then
33+
file="itests/$file"
34+
fi
35+
fi
36+
37+
if echo "$l" | grep -qE '^[^:]+\.md:[0-9]+:[0-9]+ error MD'; then
38+
col=$(echo "$l" | sed -E 's/^[^:]+\.md:[0-9]+:([0-9]+) error .*/\1/')
39+
rule=$(echo "$l" | sed -E 's/^[^:]+\.md:[0-9]+:[0-9]+ error (MD[^ ]+) .*/\1/')
40+
rest=$(echo "$l" | sed -E 's/^[^:]+\.md:[0-9]+:[0-9]+ error MD[^ ]+ (.*)$/\1/')
41+
rest_esc=$(printf '%s' "$rest" | gha_escape)
42+
echo "::error file=$file,line=$line,col=$col,title=$rule::$rest_esc"
43+
else
44+
rule=$(echo "$l" | sed -E 's/^[^:]+\.md:[0-9]+ error (MD[^ ]+) .*/\1/')
45+
rest=$(echo "$l" | sed -E 's/^[^:]+\.md:[0-9]+ error MD[^ ]+ (.*)$/\1/')
46+
rest_esc=$(printf '%s' "$rest" | gha_escape)
47+
echo "::error file=$file,line=$line,title=$rule::$rest_esc"
48+
fi
49+
done < <(
50+
grep -aE '\[INFO\] .*\.md:[0-9]+(:[0-9]+)? error MD' "$BUILD_LOG" \
51+
| sed -E 's/^.*\[INFO\] //'
52+
)
53+
}
54+
1755
function mvnp() {
18-
set -o pipefail # exit build with error when pipes fail
19-
local reactor_size=$(find -name "pom.xml" | grep -vE '/src/|/target/' | wc -l)
20-
local padding=$(bc -l <<< "scale=0;2*(l($reactor_size)/l(10)+1)")
21-
local command=(./mvnw $@)
22-
exec "${command[@]}" 2>&1 | # execute, redirect stderr to stdout
23-
tee "$BUILD_LOG" | # write output to log
24-
stdbuf -oL grep -aE '^\[INFO\] Building .+ \[.+\]$' | # filter progress
25-
stdbuf -o0 sed -uE 's/^\[INFO\] Building (.*[^ ])[ ]+\[([0-9]+\/[0-9]+)\]$/\2| \1/' | # prefix project name with progress
26-
stdbuf -o0 sed -e :a -e "s/^.\{1,${padding}\}|/ &/;ta" # right align progress with padding
56+
set -o pipefail # exit build with error when pipes fail
57+
local reactor_size=$(find -name "pom.xml" | grep -vE '/src/|/target/' | wc -l)
58+
local padding=$(bc -l <<< "scale=0;2*(l($reactor_size)/l(10)+1)")
59+
local command=(bash ./mvnw "$@")
60+
61+
"${command[@]}" 2>&1 | \ # execute, redirect stderr to stdout
62+
tee "$BUILD_LOG" | \ # write output to log
63+
stdbuf -oL grep -aE '^\[INFO\] Building .+ \[.+\]$' | \ # filter progress
64+
stdbuf -o0 sed -uE 's/^\[INFO\] Building (.*[^ ])[ ]+\[([0-9]+\/[0-9]+)\]$/\2| \1/' | \ # prefix project name with progress
65+
stdbuf -o0 sed -e :a -e "s/^.\{1,${padding}\}|/ &/;ta" # right align progress with padding
66+
67+
# Exit code of Maven is the first command in the pipeline
68+
return "${PIPESTATUS[0]}"
2769
}
2870

2971
function build_all() {
@@ -38,6 +80,8 @@ function build_all() {
3880
status=$?
3981
echo
4082

83+
emit_markdownlint_annotations
84+
4185
if [ $status -eq 0 ]; then
4286
print_reactor_summary
4387
else
@@ -104,5 +148,5 @@ function build_based_on_changes() {
104148
fi
105149
}
106150

107-
./mvnw -v
151+
bash ./mvnw -v
108152
build_based_on_changes

.github/workflows/ci-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767

6868
- name: Build
6969
id: build
70-
run: './.github/scripts/maven-build'
70+
run: bash './.github/scripts/maven-build'
7171
env:
7272
CHANGED_FILES: ${{ steps.files.outputs.all }}
7373
MAVEN_OPTS: >-

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ mvn clean install karaf:kar -pl :org.openhab.binding.astro
8585
To improve build times you can add the following options to the command:
8686

8787
| Option | Description |
88-
| ----------------------------- | --------------------------------------------------- |
88+
|-------------------------------|-----------------------------------------------------|
8989
| `-DskipChecks` | Skip the static analysis (Checkstyle, FindBugs) |
9090
| `-DskipTests` | Skip the execution of tests |
9191
| `-Dmaven.test.skip=true` | Skip the compilation and execution of tests |
9292
| `-Dfeatures.verify.skip=true` | Skip the Karaf feature verification |
93+
| `-Dmarkdownlint.skip=true` | Skip the Markdown linting |
9394
| `-Dspotless.check.skip=true` | Skip the Spotless code style checks |
9495
| `-o` | Work offline so Maven does not download any updates |
9596
| `-T 1C` | Build in parallel, using 1 thread per core |

bundles/org.openhab.automation.jsscripting/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<artifactId>frontend-maven-plugin</artifactId>
4848
<version>2.0.0</version>
4949
<configuration>
50+
<installDirectory>target/js</installDirectory>
5051
<nodeVersion>${node.version}</nodeVersion>
5152
<workingDirectory>target/js</workingDirectory>
5253
</configuration>

bundles/pom.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@
526526
<properties>
527527
<m2e.jdt.annotationpath>target/dependency</m2e.jdt.annotationpath>
528528
<dep.noembedding/>
529+
<markdownlint.skip>false</markdownlint.skip>
529530
</properties>
530531

531532
<dependencies>
@@ -784,6 +785,44 @@
784785
</execution>
785786
</executions>
786787
</plugin>
788+
<plugin>
789+
<groupId>com.github.eirslett</groupId>
790+
<artifactId>frontend-maven-plugin</artifactId>
791+
<version>2.0.0</version>
792+
793+
<configuration>
794+
<skip>${markdownlint.skip}</skip>
795+
796+
<!-- Central toolchain for markdownlint (Node 24) -->
797+
<installDirectory>${maven.multiModuleProjectDirectory}/target/.mvn/node-markdownlint</installDirectory>
798+
<nodeVersion>v24.12.0</nodeVersion>
799+
800+
<!-- Recommended: pin npm too for reproducibility -->
801+
<npmVersion>11.6.2</npmVersion>
802+
</configuration>
803+
804+
<executions>
805+
<execution>
806+
<id>install-node-and-npm</id>
807+
<goals>
808+
<goal>install-node-and-npm</goal>
809+
</goals>
810+
<phase>validate</phase>
811+
</execution>
812+
813+
<execution>
814+
<id>markdownlint</id>
815+
<goals>
816+
<goal>npm</goal>
817+
</goals>
818+
<phase>validate</phase>
819+
<configuration>
820+
<workingDirectory>${project.basedir}</workingDirectory>
821+
<arguments>exec --yes markdownlint-cli2 -- **/*.md !**/target/** !**/node_modules/** --config ${maven.multiModuleProjectDirectory}/.github/markdownlint.yaml</arguments>
822+
</configuration>
823+
</execution>
824+
</executions>
825+
</plugin>
787826
</plugins>
788827
</build>
789828

0 commit comments

Comments
 (0)