2023-08-23 19:26:05 +00:00
|
|
|
#!/bin/bash
|
2023-09-08 23:28:55 +00:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
2023-09-20 21:33:30 +00:00
|
|
|
set -euo pipefail
|
2023-08-23 19:26:05 +00:00
|
|
|
|
|
|
|
# Get the list of changed files
|
2024-06-18 19:38:35 +00:00
|
|
|
# Using `git merge-base` ensures that we're always comparing against the correct branch point.
|
2023-09-20 21:33:30 +00:00
|
|
|
#For example, given the commits:
|
|
|
|
#
|
|
|
|
# A---B---C---D---W---X---Y---Z # origin/main
|
|
|
|
# \---E---F # feature/branch
|
|
|
|
#
|
|
|
|
# ... `git merge-base origin/$SKIP_CHECK_BRANCH HEAD` would return commit `D`
|
|
|
|
# `...HEAD` specifies from the common ancestor to the latest commit on the current branch (HEAD)..
|
|
|
|
files_to_check=$(git diff --name-only "$(git merge-base origin/$SKIP_CHECK_BRANCH HEAD~)"...HEAD)
|
2023-08-23 19:26:05 +00:00
|
|
|
|
|
|
|
# Define the directories to check
|
2024-06-18 19:38:35 +00:00
|
|
|
skipped_directories=("docs/" "ui/" "website/" "grafana/" ".changelog/")
|
2023-08-23 19:26:05 +00:00
|
|
|
|
2023-09-20 21:33:30 +00:00
|
|
|
# Loop through the changed files and find directories/files outside the skipped ones
|
2024-06-18 19:38:35 +00:00
|
|
|
files_to_check_array=($files_to_check)
|
|
|
|
for file_to_check in "${files_to_check_array[@]}"; do
|
2023-09-20 21:33:30 +00:00
|
|
|
file_is_skipped=false
|
2024-06-18 19:38:35 +00:00
|
|
|
echo "checking file: $file_to_check"
|
|
|
|
|
|
|
|
# Allow changes to:
|
|
|
|
# - This script
|
|
|
|
# - Files in the skipped directories
|
|
|
|
# - Markdown files
|
2023-09-20 21:33:30 +00:00
|
|
|
for dir in "${skipped_directories[@]}"; do
|
2024-06-18 19:38:35 +00:00
|
|
|
if [[ "$file_to_check" == */check_skip_ci.sh ]] ||
|
|
|
|
[[ "$file_to_check" == "$dir"* ]] ||
|
|
|
|
[[ "$file_to_check" == *.md ]]; then
|
2023-09-20 21:33:30 +00:00
|
|
|
file_is_skipped=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2024-06-18 19:38:35 +00:00
|
|
|
|
2023-09-20 21:33:30 +00:00
|
|
|
if [ "$file_is_skipped" != "true" ]; then
|
2024-06-18 19:38:35 +00:00
|
|
|
echo -e "non-skippable file changed: $file_to_check"
|
|
|
|
echo "Changes detected in non-documentation files - will not skip tests and build"
|
|
|
|
echo "skip-ci=false" >> "$GITHUB_OUTPUT"
|
2023-09-20 21:33:30 +00:00
|
|
|
exit 0 ## if file is outside of the skipped_directory exit script
|
|
|
|
fi
|
|
|
|
done
|
2023-08-23 19:26:05 +00:00
|
|
|
|
2024-06-18 19:38:35 +00:00
|
|
|
echo "Changes detected in only documentation files - skipping tests and build"
|
|
|
|
echo "skip-ci=true" >> "$GITHUB_OUTPUT"
|