22# Copyright (c) HashiCorp, Inc.
33# SPDX-License-Identifier: BUSL-1.1
44
5+ set -euo pipefail
56
67# Get the list of changed files
7- files_to_check=$( git diff --name-only origin/$GITHUB_BASE_REF )
8+ # Using `git merge-base` ensures that we're always comparing against the correct branch point.
9+ # For example, given the commits:
10+ #
11+ # A---B---C---D---W---X---Y---Z # origin/main
12+ # \---E---F # our feature branch
13+ #
14+ # ... `git merge-base origin/$SKIP_CHECK_BRANCH HEAD` would return commit `D`
15+ # `...HEAD` specifies from the common ancestor to the latest commit on the current branch (HEAD)..
16+ files_to_check=$( git diff --name-only " $( git merge-base origin/$SKIP_CHECK_BRANCH HEAD~) " ...HEAD)
817
918# Define the directories to check
1019skipped_directories=(" docs/" " ui/" " website/" " grafana/" )
1120
12- # Initialize a variable to track directories outside the skipped ones
13- other_directories=" "
14- trigger_ci=true
21+ # Loop through the changed files and find directories/files outside the skipped ones
22+ for file_to_check in $files_to_check ; do
23+ file_is_skipped=false
24+ for dir in " ${skipped_directories[@]} " ; do
25+ if [[ " $file_to_check " == " $dir " * ]] || [[ " $file_to_check " == * .md && " $dir " == * " /" ]]; then
26+ file_is_skipped=true
27+ break
28+ fi
29+ done
30+ if [ " $file_is_skipped " != " true" ]; then
31+ echo -e $file_to_check
32+ SKIP_CI=false # Set the SKIP_CI variable to false by default
33+ echo " Changes detected in non-documentation files - skip-ci: $SKIP_CI "
34+ export $SKIP_CI
35+ exit 0 # # if file is outside of the skipped_directory exit script
36+ fi
37+ done
1538
16- # # Loop through the changed files and find directories/files outside the skipped ones
17- # for file_to_check in $files_to_check; do
18- # file_is_skipped=false
19- # for dir in "${skipped_directories[@]}"; do
20- # if [[ "$file_to_check" == "$dir"* ]] || [[ "$file_to_check" == *.md && "$dir" == *"/" ]]; then
21- # file_is_skipped=true
22- # break
23- # fi
24- # done
25- # if [ "$file_is_skipped" = "false" ]; then
26- # other_directories+="$(dirname "$file_to_check")\n"
27- # trigger_ci=true
28- # echo "Non doc file(s) changed - triggered ci: $trigger_ci"
29- # echo -e $other_directories
30- # echo "trigger-ci=$trigger_ci" >>"$GITHUB_OUTPUT"
31- # exit 0 ## if file is outside of the skipped_directory exit script
32- # fi
33- # done
34-
35- # echo "Only doc file(s) changed - triggered ci: $trigger_ci"
36- echo " Doc file(s) change detection is currently disabled - triggering ci"
37- echo " trigger-ci=$trigger_ci " >> " $GITHUB_OUTPUT "
39+ echo -e " $files_to_check "
40+ SKIP_CI=true
41+ echo " Changes detected in only documentation files - skip-ci: $SKIP_CI "
42+ export $SKIP_CI
0 commit comments