ci: fix file parsing in conditional-skip script (#21343)

Ensure files are split rather than compared as a single list for
accuracy and easier debugging.

Also adopt minor changes and file name from introduction of similar
check `consul-dataplane` and `consul-k8s` for clarity.
This commit is contained in:
Michael Zalimeni 2024-06-18 15:38:35 -04:00 committed by GitHub
parent a16bfc6a3c
commit 830d1bf77f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 16 deletions

View File

@ -16,27 +16,34 @@ set -euo pipefail
files_to_check=$(git diff --name-only "$(git merge-base origin/$SKIP_CHECK_BRANCH HEAD~)"...HEAD)
# Define the directories to check
skipped_directories=("docs/" "ui/" "website/" "grafana/")
skipped_directories=("docs/" "ui/" "website/" "grafana/" ".changelog/")
# Loop through the changed files and find directories/files outside the skipped ones
for file_to_check in "${files_to_check[@]}"; do
files_to_check_array=($files_to_check)
for file_to_check in "${files_to_check_array[@]}"; do
file_is_skipped=false
echo "checking file: $file_to_check"
# Allow changes to:
# - This script
# - Files in the skipped directories
# - Markdown files
for dir in "${skipped_directories[@]}"; do
if [[ "$file_to_check" == "$dir"* ]] || [[ "$file_to_check" == *.md && "$dir" == *"/" ]]; then
if [[ "$file_to_check" == */check_skip_ci.sh ]] ||
[[ "$file_to_check" == "$dir"* ]] ||
[[ "$file_to_check" == *.md ]]; then
file_is_skipped=true
break
fi
done
if [ "$file_is_skipped" != "true" ]; then
echo -e $file_to_check
SKIP_CI=false
echo "Changes detected in non-documentation files - skip-ci: $SKIP_CI"
echo "skip-ci=$SKIP_CI" >> "$GITHUB_OUTPUT"
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"
exit 0 ## if file is outside of the skipped_directory exit script
fi
done
echo -e "$files_to_check"
SKIP_CI=true
echo "Changes detected in only documentation files - skip-ci: $SKIP_CI"
echo "skip-ci=$SKIP_CI" >> "$GITHUB_OUTPUT"
echo "Changes detected in only documentation files - skipping tests and build"
echo "skip-ci=true" >> "$GITHUB_OUTPUT"

View File

@ -41,7 +41,7 @@ jobs:
fetch-depth: 0
- name: Get changed files
id: read-files
run: ./.github/scripts/filter_changed_files_go_test.sh
run: ./.github/scripts/check_skip_ci.sh
setup:
needs: [conditional-skip]

View File

@ -27,7 +27,7 @@ jobs:
fetch-depth: 0
- name: Get changed files
id: read-files
run: ./.github/scripts/filter_changed_files_go_test.sh
run: ./.github/scripts/check_skip_ci.sh
setup:
needs: [conditional-skip]

View File

@ -42,7 +42,7 @@ jobs:
fetch-depth: 0
- name: Get changed files
id: read-files
run: ./.github/scripts/filter_changed_files_go_test.sh
run: ./.github/scripts/check_skip_ci.sh
setup:
needs: [conditional-skip]