diff --git a/.github/compare_templates.sh b/.github/compare_templates.sh new file mode 100644 index 000000000..be7dcab39 --- /dev/null +++ b/.github/compare_templates.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Define variables for the directories +ASCIIDOC_DIR="share/mrdocs/addons/generator/asciidoc" +HTML_DIR="share/mrdocs/addons/generator/html" + +# Function to check for missing files +check_missing_files() { + local src_dir=$1 + local dest_dir=$2 + local src_ext=$3 + local dest_ext=$4 + local missing_files=() + + while IFS= read -r src_file; do + relative_path="${src_file#$src_dir/}" + dest_file="$dest_dir/${relative_path%$src_ext}$dest_ext" + if [[ ! -f "$dest_file" ]]; then + missing_files+=("${relative_path%$src_ext}$dest_ext") + fi + done < <(find "$src_dir" -type f -name "*$src_ext") + + printf "%s\n" "${missing_files[@]}" +} + +missing_in_html=$(check_missing_files "$ASCIIDOC_DIR" "$HTML_DIR" ".adoc.hbs" ".html.hbs") +missing_in_asciidoc=$(check_missing_files "$HTML_DIR" "$ASCIIDOC_DIR" ".html.hbs" ".adoc.hbs") + +if [ ${#missing_in_html[@]} -eq 0 ] && [ ${#missing_in_asciidoc[@]} -eq 0 ]; then + echo "All files match between the Asciidoc and HTML directories." +else + if [ -n "$missing_in_html" ]; then + html_message="The following files are missing from the HTML directory:\n$(printf "%s\n" "$missing_in_html" | sed 's/^/ - /')" + fi + + if [ -n "$missing_in_asciidoc" ]; then + asciidoc_message="The following files are missing from the Asciidoc directory:\n$(printf "%s\n" "$missing_in_asciidoc" | sed 's/^/ - /')" + fi + + if [ -z "$CI" ] || [ -z "$GITHUB_ACTION" ]; then + echo -e "HTML and Asciidoc templates do not match.\n$html_message\n$asciidoc_message" + else + final_message=$(echo -e "$html_message. $asciidoc_message" | tr -d '\n') + echo -e "::warning title=HTML and Asciidoc templates do not match::$final_message" + fi +fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ee5a5cb2..4aeec6d2c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -574,6 +574,12 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} limit: 150 + - name: Compare Markup Templates + run: | + set -x + chmod +x .github/compare_templates.sh + .github/compare_templates.sh + - name: Create GitHub Package Release if: ${{ github.event_name == 'push' && (contains(fromJSON('["master", "develop"]'), github.ref_name) || startsWith(github.ref, 'refs/tags/')) }} uses: softprops/action-gh-release@v1