From 830d1bf77f10c418b0ec54bc9a06ca2d974e0b5f Mon Sep 17 00:00:00 2001 From: Michael Zalimeni Date: Tue, 18 Jun 2024 15:38:35 -0400 Subject: [PATCH] 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. --- ...nged_files_go_test.sh => check_skip_ci.sh} | 31 ++++++++++++------- .github/workflows/go-tests.yml | 4 +-- .github/workflows/security-scan.yml | 2 +- .github/workflows/test-integrations.yml | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) rename .github/scripts/{filter_changed_files_go_test.sh => check_skip_ci.sh} (55%) diff --git a/.github/scripts/filter_changed_files_go_test.sh b/.github/scripts/check_skip_ci.sh similarity index 55% rename from .github/scripts/filter_changed_files_go_test.sh rename to .github/scripts/check_skip_ci.sh index bdd0e3f77f..628d8489df 100755 --- a/.github/scripts/filter_changed_files_go_test.sh +++ b/.github/scripts/check_skip_ci.sh @@ -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 @@ -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" \ No newline at end of file +echo "Changes detected in only documentation files - skipping tests and build" +echo "skip-ci=true" >> "$GITHUB_OUTPUT" \ No newline at end of file diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 10ee2325c5..6ea14b4fab 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -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] diff --git a/.github/workflows/security-scan.yml b/.github/workflows/security-scan.yml index 8c7af7a4f9..427acd02bb 100644 --- a/.github/workflows/security-scan.yml +++ b/.github/workflows/security-scan.yml @@ -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] diff --git a/.github/workflows/test-integrations.yml b/.github/workflows/test-integrations.yml index cae4e9f591..b106c30a53 100644 --- a/.github/workflows/test-integrations.yml +++ b/.github/workflows/test-integrations.yml @@ -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]