From a7fbd6b7b3229a7d8bc5a8a96ad3caeb255fb8a4 Mon Sep 17 00:00:00 2001 From: NiniOak Date: Mon, 18 Sep 2023 12:30:18 -0700 Subject: [PATCH 1/3] Update base ref property name --- .../scripts/filter_changed_files_go_test.sh | 57 ++++++++++--------- .github/workflows/go-tests.yml | 11 ++-- .github/workflows/test-integrations.yml | 11 ++-- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/.github/scripts/filter_changed_files_go_test.sh b/.github/scripts/filter_changed_files_go_test.sh index 1366cc2eeb26..aa3c9c3dd375 100755 --- a/.github/scripts/filter_changed_files_go_test.sh +++ b/.github/scripts/filter_changed_files_go_test.sh @@ -2,36 +2,41 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: BUSL-1.1 +set -euo pipefail # Get the list of changed files -files_to_check=$(git diff --name-only origin/$GITHUB_BASE_REF) +# 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 +# \---E---F # our 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) # Define the directories to check skipped_directories=("docs/" "ui/" "website/" "grafana/") -# Initialize a variable to track directories outside the skipped ones -other_directories="" -trigger_ci=true +# Loop through the changed files and find directories/files outside the skipped ones +for file_to_check in $files_to_check; do + file_is_skipped=false + for dir in "${skipped_directories[@]}"; do + if [[ "$file_to_check" == "$dir"* ]] || [[ "$file_to_check" == *.md && "$dir" == *"/" ]]; then + file_is_skipped=true + break + fi + done + if [ "$file_is_skipped" != "true" ]; then + echo -e $file_to_check + SKIP_CI=false # Set the SKIP_CI variable to false by default + echo "Changes detected in non-documentation files - skip-ci: $SKIP_CI" + export $SKIP_CI + exit 0 ## if file is outside of the skipped_directory exit script + fi +done -# # Loop through the changed files and find directories/files outside the skipped ones -# for file_to_check in $files_to_check; do -# file_is_skipped=false -# for dir in "${skipped_directories[@]}"; do -# if [[ "$file_to_check" == "$dir"* ]] || [[ "$file_to_check" == *.md && "$dir" == *"/" ]]; then -# file_is_skipped=true -# break -# fi -# done -# if [ "$file_is_skipped" = "false" ]; then -# other_directories+="$(dirname "$file_to_check")\n" -# trigger_ci=true -# echo "Non doc file(s) changed - triggered ci: $trigger_ci" -# echo -e $other_directories -# echo "trigger-ci=$trigger_ci" >>"$GITHUB_OUTPUT" -# exit 0 ## if file is outside of the skipped_directory exit script -# fi -# done - -# echo "Only doc file(s) changed - triggered ci: $trigger_ci" -echo "Doc file(s) change detection is currently disabled - triggering ci" -echo "trigger-ci=$trigger_ci" >>"$GITHUB_OUTPUT" +echo -e "$files_to_check" +SKIP_CI=true +echo "Changes detected in only documentation files - skip-ci: $SKIP_CI" +export $SKIP_CI \ No newline at end of file diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 6782a3e4d752..05ec8d07b88c 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -22,6 +22,7 @@ permissions: env: TEST_RESULTS: /tmp/test-results GOPRIVATE: github.com/hashicorp # Required for enterprise deps + SKIP_CHECK_BRANCH: ${{ github.head_ref || github.ref_name }} # concurrency concurrency: @@ -33,19 +34,21 @@ jobs: runs-on: ubuntu-latest name: Get files changed and conditionally skip CI outputs: - trigger-ci: ${{ steps.read-files.outputs.trigger-ci }} + skip-ci: ${{ steps.read-files.outputs.skip-ci }} steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: fetch-depth: 0 - name: Get changed files id: read-files - run: ./.github/scripts/filter_changed_files_go_test.sh + run: | + ./.github/scripts/filter_changed_files_go_test.sh + echo "skip-ci=${SKIP_CI}" >> "${GITHUB_ENV}" setup: needs: [conditional-skip] name: Setup - if: needs.conditional-skip.outputs.trigger-ci == 'true' + if: needs.conditional-skip.outputs.skip-ci != 'true' runs-on: ubuntu-latest outputs: compute-small: ${{ steps.setup-outputs.outputs.compute-small }} @@ -506,7 +509,7 @@ jobs: - go-test-32bit # - go-test-s390x runs-on: ${{ fromJSON(needs.setup.outputs.compute-small) }} - if: always() && needs.conditional-skip.outputs.trigger-ci == 'true' + if: always() && needs.conditional-skip.outputs.skip-ci != 'true' steps: - name: evaluate upstream job results run: | diff --git a/.github/workflows/test-integrations.yml b/.github/workflows/test-integrations.yml index 70315390e3b0..3a2703037c23 100644 --- a/.github/workflows/test-integrations.yml +++ b/.github/workflows/test-integrations.yml @@ -24,6 +24,7 @@ env: # strip the hashicorp/ off the front of github.repository for consul CONSUL_LATEST_IMAGE_NAME: ${{ endsWith(github.repository, '-enterprise') && github.repository || 'hashicorp/consul' }} GOPRIVATE: github.com/hashicorp # Required for enterprise deps + SKIP_CHECK_BRANCH: ${{ github.head_ref || github.ref_name }} concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} @@ -34,20 +35,22 @@ jobs: runs-on: ubuntu-latest name: Get files changed and conditionally skip CI outputs: - trigger-ci: ${{ steps.read-files.outputs.trigger-ci }} + skip-ci: ${{ steps.read-files.outputs.skip-ci }} steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: fetch-depth: 0 - name: Get changed files id: read-files - run: ./.github/scripts/filter_changed_files_go_test.sh + run: | + ./.github/scripts/filter_changed_files_go_test.sh + echo "skip-ci=${SKIP_CI}" >> "${GITHUB_ENV}" setup: needs: [conditional-skip] runs-on: ubuntu-latest name: Setup - if: needs.conditional-skip.outputs.trigger-ci == 'true' + if: needs.conditional-skip.outputs.skip-ci != 'true' outputs: compute-small: ${{ steps.runners.outputs.compute-small }} compute-medium: ${{ steps.runners.outputs.compute-medium }} @@ -495,7 +498,7 @@ jobs: - envoy-integration-test - compatibility-integration-test runs-on: ${{ fromJSON(needs.setup.outputs.compute-small) }} - if: always() && needs.conditional-skip.outputs.trigger-ci == 'true' + if: always() && needs.conditional-skip.outputs.skip-ci != 'true' steps: - name: evaluate upstream job results run: | From adb87b70571e37c0b059a6316059f75ac0009722 Mon Sep 17 00:00:00 2001 From: Anita Akaeze Date: Wed, 20 Sep 2023 14:02:56 -0700 Subject: [PATCH 2/3] Test skip ci (#18924) test_push_merge --- .github/workflows/go-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 05ec8d07b88c..49e50e62ccc7 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -30,7 +30,7 @@ concurrency: cancel-in-progress: true jobs: - conditional-skip: + conditional-skip: #test-delete-me runs-on: ubuntu-latest name: Get files changed and conditionally skip CI outputs: From 43839f7944bd0923bbc5ed83fc65386783041fd8 Mon Sep 17 00:00:00 2001 From: NiniOak Date: Wed, 20 Sep 2023 14:14:00 -0700 Subject: [PATCH 3/3] cleanup test push code --- .github/scripts/filter_changed_files_go_test.sh | 4 ++-- .github/workflows/go-tests.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/scripts/filter_changed_files_go_test.sh b/.github/scripts/filter_changed_files_go_test.sh index aa3c9c3dd375..ce5380f8f170 100755 --- a/.github/scripts/filter_changed_files_go_test.sh +++ b/.github/scripts/filter_changed_files_go_test.sh @@ -9,7 +9,7 @@ set -euo pipefail #For example, given the commits: # # A---B---C---D---W---X---Y---Z # origin/main -# \---E---F # our feature branch +# \---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).. @@ -29,7 +29,7 @@ for file_to_check in $files_to_check; do done if [ "$file_is_skipped" != "true" ]; then echo -e $file_to_check - SKIP_CI=false # Set the SKIP_CI variable to false by default + SKIP_CI=false echo "Changes detected in non-documentation files - skip-ci: $SKIP_CI" export $SKIP_CI exit 0 ## if file is outside of the skipped_directory exit script diff --git a/.github/workflows/go-tests.yml b/.github/workflows/go-tests.yml index 49e50e62ccc7..05ec8d07b88c 100644 --- a/.github/workflows/go-tests.yml +++ b/.github/workflows/go-tests.yml @@ -30,7 +30,7 @@ concurrency: cancel-in-progress: true jobs: - conditional-skip: #test-delete-me + conditional-skip: runs-on: ubuntu-latest name: Get files changed and conditionally skip CI outputs: