Skip to content

Commit

Permalink
ci: fix file parsing in conditional-skip script (#21343)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zalimeni authored Jun 18, 2024
1 parent a16bfc6 commit 830d1bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
set -euo pipefail

# Get the list of changed files
# Using `git merge-base` ensures that we're always comparing against the correct branch point.
# Using `git merge-base` ensures that we're always comparing against the correct branch point.
#For example, given the commits:
#
# A---B---C---D---W---X---Y---Z # origin/main
Expand All @@ -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"
4 changes: 2 additions & 2 deletions .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
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]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 830d1bf

Please sign in to comment.