|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +# See https://llvm.org/LICENSE.txt for license information. |
| 5 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +# |
| 7 | +# Copyright (c) 2026 Alan de Freitas (alandefreitas@gmail.com) |
| 8 | +# |
| 9 | +# Official repository: https://github.com/cppalliance/mrdocs |
| 10 | +# |
| 11 | + |
| 12 | +# Compare current demos against previous develop demos. |
| 13 | +# Expected env vars: GITHUB_OUTPUT |
| 14 | +set -x |
| 15 | + |
| 16 | +LOCAL_DEMOS_DIR="./demos/" |
| 17 | +PREV_DEMOS_DIR="./demos-previous/" |
| 18 | +DIFF_DIR="./demos-diff/" |
| 19 | + |
| 20 | +if [[ ! -d $PREV_DEMOS_DIR || -z $(ls -A $PREV_DEMOS_DIR) ]]; then |
| 21 | + echo "No previous demos found." |
| 22 | + echo "diff=false" >> "$GITHUB_OUTPUT" |
| 23 | + exit 0 |
| 24 | +fi |
| 25 | + |
| 26 | +mkdir -p $PREV_DEMOS_DIR $DIFF_DIR |
| 27 | + |
| 28 | +find $PREV_DEMOS_DIR -type f | while read previous_file; do |
| 29 | + local_file="${LOCAL_DEMOS_DIR}${previous_file#$PREV_DEMOS_DIR}" |
| 30 | + diff_output="$DIFF_DIR${previous_file#$PREV_DEMOS_DIR}" |
| 31 | + if [[ -f $local_file ]]; then |
| 32 | + mkdir -p "$(dirname "$diff_output")" |
| 33 | + diff "$previous_file" "$local_file" > "$diff_output" |
| 34 | + if [[ ! -s $diff_output ]]; then |
| 35 | + rm "$diff_output" |
| 36 | + fi |
| 37 | + else |
| 38 | + echo "LOCAL FILE $local_file DOES NOT EXITS." > "$diff_output" |
| 39 | + echo "PREVIOUS CONTENT OF THE FILE WAS:" >> "$diff_output" |
| 40 | + cat "$previous_file" >> "$diff_output" |
| 41 | + fi |
| 42 | +done |
| 43 | + |
| 44 | +find $LOCAL_DEMOS_DIR -type f | while read local_file; do |
| 45 | + previous_file="${PREV_DEMOS_DIR}${local_file#$LOCAL_DEMOS_DIR}" |
| 46 | + diff_output="$DIFF_DIR${local_file#$LOCAL_DEMOS_DIR}" |
| 47 | + if [[ ! -f $previous_file ]]; then |
| 48 | + echo "PREVIOUS $previous_file DOES NOT EXIST." > "$diff_output" |
| 49 | + echo "IT HAS BEEN INCLUDED IN THIS VERSION." >> "$diff_output" |
| 50 | + echo "NEW CONTENT OF THE FILE IS:" >> "$diff_output" |
| 51 | + fi |
| 52 | +done |
| 53 | + |
| 54 | +if [[ -z $(ls -A $DIFF_DIR) ]]; then |
| 55 | + echo "No differences found." |
| 56 | + echo "diff=false" >> "$GITHUB_OUTPUT" |
| 57 | +else |
| 58 | + N_FILES=$(find $DIFF_DIR -type f | wc -l) |
| 59 | + echo "Differences found in $N_FILES output files." |
| 60 | + echo "diff=true" >> "$GITHUB_OUTPUT" |
| 61 | +fi |
0 commit comments