Skip to content

Commit 380eb00

Browse files
committed
ci: template consistency checks
1 parent 2637ae4 commit 380eb00

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

.github/compare_templates.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# Define variables for the directories
4+
ASCIIDOC_DIR="share/mrdocs/addons/generator/asciidoc"
5+
HTML_DIR="share/mrdocs/addons/generator/html"
6+
7+
# Function to check for missing files
8+
check_missing_files() {
9+
local src_dir=$1
10+
local dest_dir=$2
11+
local src_ext=$3
12+
local dest_ext=$4
13+
local missing_files=()
14+
15+
while IFS= read -r src_file; do
16+
relative_path="${src_file#$src_dir/}"
17+
dest_file="$dest_dir/${relative_path%$src_ext}$dest_ext"
18+
if [[ ! -f "$dest_file" ]]; then
19+
missing_files+=("${relative_path%$src_ext}$dest_ext")
20+
fi
21+
done < <(find "$src_dir" -type f -name "*$src_ext")
22+
23+
printf "%s\n" "${missing_files[@]}"
24+
}
25+
26+
missing_in_html=$(check_missing_files "$ASCIIDOC_DIR" "$HTML_DIR" ".adoc.hbs" ".html.hbs")
27+
missing_in_asciidoc=$(check_missing_files "$HTML_DIR" "$ASCIIDOC_DIR" ".html.hbs" ".adoc.hbs")
28+
29+
if [ ${#missing_in_html[@]} -eq 0 ] && [ ${#missing_in_asciidoc[@]} -eq 0 ]; then
30+
echo "All files match between the Asciidoc and HTML directories."
31+
else
32+
if [ -n "$missing_in_html" ]; then
33+
html_message="The following files are missing from the HTML directory:\n$(printf "%s\n" "$missing_in_html" | sed 's/^/ - /')"
34+
fi
35+
36+
if [ -n "$missing_in_asciidoc" ]; then
37+
asciidoc_message="The following files are missing from the Asciidoc directory:\n$(printf "%s\n" "$missing_in_asciidoc" | sed 's/^/ - /')"
38+
fi
39+
40+
if [ -z "$CI" ] || [ -z "$GITHUB_ACTION" ]; then
41+
echo -e "HTML and Asciidoc templates do not match.\n$html_message\n$asciidoc_message"
42+
else
43+
final_message=$(echo -e "$html_message. $asciidoc_message" | tr -d '\n')
44+
echo -e "::warning title=HTML and Asciidoc templates do not match::$final_message"
45+
fi
46+
fi

.github/workflows/ci.yml

+6
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,12 @@ jobs:
574574
github-token: ${{ secrets.GITHUB_TOKEN }}
575575
limit: 150
576576

577+
- name: Compare Markup Templates
578+
run: |
579+
set -x
580+
chmod +x .github/compare_templates.sh
581+
.github/compare_templates.sh
582+
577583
- name: Create GitHub Package Release
578584
if: ${{ github.event_name == 'push' && (contains(fromJSON('["master", "develop"]'), github.ref_name) || startsWith(github.ref, 'refs/tags/')) }}
579585
uses: softprops/action-gh-release@v1

0 commit comments

Comments
 (0)