From 43f13f5fd1dc3d4c18101577ae3cf71a1da10e5a Mon Sep 17 00:00:00 2001 From: Michael Zalimeni Date: Mon, 16 Sep 2024 17:27:26 -0400 Subject: [PATCH] ci: fix CI skip script hole In some environments, the script will not fail despite SKIP_CHECK_BRANCH being unset, leading to the script explicitly skipping CI when it should fail fast. Prevent this by explicitly checking for the env var. This change is a port of https://github.com/hashicorp/consul/pull/21741. --- .github/scripts/check_skip_ci.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/scripts/check_skip_ci.sh b/.github/scripts/check_skip_ci.sh index 0f65e46e..f7b70498 100755 --- a/.github/scripts/check_skip_ci.sh +++ b/.github/scripts/check_skip_ci.sh @@ -13,10 +13,11 @@ set -euo pipefail # # ... `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) +skip_check_branch=${SKIP_CHECK_BRANCH:?SKIP_CHECK_BRANCH is required} +files_to_check=$(git diff --name-only "$(git merge-base origin/$skip_check_branch HEAD~)"...HEAD) # Define the directories to check -skipped_directories=("_doc/" ".changelog/") +skipped_directories=("_doc" ".changelog") # Loop through the changed files and find directories/files outside the skipped ones files_to_check_array=($files_to_check) @@ -30,7 +31,7 @@ for file_to_check in "${files_to_check_array[@]}"; do # - Markdown files for dir in "${skipped_directories[@]}"; do if [[ "$file_to_check" == */check_skip_ci.sh ]] || - [[ "$file_to_check" == "$dir"* ]] || + [[ "$file_to_check" == "$dir/"* ]] || [[ "$file_to_check" == *.md ]]; then file_is_skipped=true break @@ -46,4 +47,4 @@ for file_to_check in "${files_to_check_array[@]}"; do done echo "Changes detected in only documentation files - skipping tests and build" -echo "skip-ci=true" >> "$GITHUB_OUTPUT" \ No newline at end of file +echo "skip-ci=true" >> "$GITHUB_OUTPUT"