1
1
#! /bin/bash
2
2
3
- #
3
+ # This script compares the files in the Asciidoc and HTML directories and reports any discrepancies.
4
+
4
5
# Licensed under the Apache License v2.0 with LLVM Exceptions.
5
6
# See https://llvm.org/LICENSE.txt for license information.
6
7
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11
12
#
12
13
13
14
# Define variables for the directories
14
- ASCIIDOC_DIR=" share/mrdocs/addons/generator/asciidoc"
15
- HTML_DIR=" share/mrdocs/addons/generator/html"
15
+ ASCIIDOC_DIR=" share/mrdocs/addons/generator/asciidoc" # Asciidoc directory path
16
+ HTML_DIR=" share/mrdocs/addons/generator/html" # HTML directory path
16
17
17
18
# Function to check for missing files
19
+ # Arguments:
20
+ # src_dir: Source directory
21
+ # dest_dir: Destination directory
22
+ # src_ext: Source file extension
23
+ # dest_ext: Destination file extension
18
24
check_missing_files () {
19
25
local src_dir=$1
20
26
local dest_dir=$2
21
27
local src_ext=$3
22
28
local dest_ext=$4
23
29
local missing_files=()
24
30
31
+ # Loop over each file in the source directory
25
32
while IFS= read -r src_file; do
26
33
relative_path=" ${src_file# $src_dir / } "
27
34
dest_file=" $dest_dir /${relative_path% $src_ext } $dest_ext "
35
+ # If the file does not exist in the destination directory, add it to the missing_files array
28
36
if [[ ! -f " $dest_file " ]]; then
29
37
missing_files+=(" ${relative_path% $src_ext } $dest_ext " )
30
38
fi
31
39
done < <( find " $src_dir " -type f -name " *$src_ext " )
32
40
41
+ # Print the missing files
33
42
printf " %s\n" " ${missing_files[@]} "
34
43
}
35
44
36
- missing_in_html=$( check_missing_files " $ASCIIDOC_DIR " " $HTML_DIR " " .adoc.hbs" " .html.hbs" )
37
- missing_in_asciidoc=$( check_missing_files " $HTML_DIR " " $ASCIIDOC_DIR " " .html.hbs" " .adoc.hbs" )
45
+ # Check for missing files in both directions
46
+ readarray -t missing_in_html < <( check_missing_files " $ASCIIDOC_DIR " " $HTML_DIR " " .adoc.hbs" " .html.hbs" )
47
+ readarray -t missing_in_asciidoc < <( check_missing_files " $HTML_DIR " " $ASCIIDOC_DIR " " .html.hbs" " .adoc.hbs" )
38
48
49
+ # Normalize the arrays to remove any empty elements
50
+ mapfile -t missing_in_html < <( printf " %s\n" " ${missing_in_html[@]} " | sed ' /^$/d' )
51
+ mapfile -t missing_in_asciidoc < <( printf " %s\n" " ${missing_in_asciidoc[@]} " | sed ' /^$/d' )
52
+
53
+ # If there are no missing files, print a success message
39
54
if [ ${# missing_in_html[@]} -eq 0 ] && [ ${# missing_in_asciidoc[@]} -eq 0 ]; then
40
55
echo " All files match between the Asciidoc and HTML directories."
41
56
else
42
- if [ -n " $missing_in_html " ]; then
43
- html_message=" The following files are missing from the HTML directory:\n$( printf " %s\n" " $missing_in_html " | sed ' s/^/ - /' ) "
57
+ # If there are missing files, prepare error messages
58
+ html_message=" "
59
+ asciidoc_message=" "
60
+
61
+ if [ ${# missing_in_html[@]} -ne 0 ]; then
62
+ html_message=" The following files are missing from the HTML directory:\n$( printf " %s\n" " ${missing_in_html[@]} " | sed ' s/^/ - /' ) "
44
63
fi
45
64
46
- if [ -n " $ missing_in_asciidoc" ]; then
47
- asciidoc_message=" The following files are missing from the Asciidoc directory:\n$( printf " %s\n" " $missing_in_asciidoc " | sed ' s/^/ - /' ) "
65
+ if [ ${ # missing_in_asciidoc[@]} -ne 0 ]; then
66
+ asciidoc_message=" The following files are missing from the Asciidoc directory:\n$( printf " %s\n" " ${ missing_in_asciidoc[@]} " | sed ' s/^/ - /' ) "
48
67
fi
49
68
69
+ # If running in a CI environment, print a formatted warning message
50
70
if [ -z " $CI " ] || [ -z " $GITHUB_ACTION " ]; then
51
71
echo -e " HTML and Asciidoc templates do not match.\n$html_message \n$asciidoc_message "
52
72
else
53
73
final_message=$( echo -e " $html_message . $asciidoc_message " | tr -d ' \n' )
54
74
echo -e " ::warning title=HTML and Asciidoc templates do not match::$final_message "
55
75
fi
56
- fi
76
+ fi
0 commit comments