Skip to content

Commit a7fbd6b

Browse files
committed
Update base ref property name
1 parent 341dc28 commit a7fbd6b

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

.github/scripts/filter_changed_files_go_test.sh

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,41 @@
22
# Copyright (c) HashiCorp, Inc.
33
# SPDX-License-Identifier: BUSL-1.1
44

5+
set -euo pipefail
56

67
# Get the list of changed files
7-
files_to_check=$(git diff --name-only origin/$GITHUB_BASE_REF)
8+
# Using `git merge-base` ensures that we're always comparing against the correct branch point.
9+
#For example, given the commits:
10+
#
11+
# A---B---C---D---W---X---Y---Z # origin/main
12+
# \---E---F # our feature branch
13+
#
14+
# ... `git merge-base origin/$SKIP_CHECK_BRANCH HEAD` would return commit `D`
15+
# `...HEAD` specifies from the common ancestor to the latest commit on the current branch (HEAD)..
16+
files_to_check=$(git diff --name-only "$(git merge-base origin/$SKIP_CHECK_BRANCH HEAD~)"...HEAD)
817

918
# Define the directories to check
1019
skipped_directories=("docs/" "ui/" "website/" "grafana/")
1120

12-
# Initialize a variable to track directories outside the skipped ones
13-
other_directories=""
14-
trigger_ci=true
21+
# Loop through the changed files and find directories/files outside the skipped ones
22+
for file_to_check in $files_to_check; do
23+
file_is_skipped=false
24+
for dir in "${skipped_directories[@]}"; do
25+
if [[ "$file_to_check" == "$dir"* ]] || [[ "$file_to_check" == *.md && "$dir" == *"/" ]]; then
26+
file_is_skipped=true
27+
break
28+
fi
29+
done
30+
if [ "$file_is_skipped" != "true" ]; then
31+
echo -e $file_to_check
32+
SKIP_CI=false # Set the SKIP_CI variable to false by default
33+
echo "Changes detected in non-documentation files - skip-ci: $SKIP_CI"
34+
export $SKIP_CI
35+
exit 0 ## if file is outside of the skipped_directory exit script
36+
fi
37+
done
1538

16-
# # Loop through the changed files and find directories/files outside the skipped ones
17-
# for file_to_check in $files_to_check; do
18-
# file_is_skipped=false
19-
# for dir in "${skipped_directories[@]}"; do
20-
# if [[ "$file_to_check" == "$dir"* ]] || [[ "$file_to_check" == *.md && "$dir" == *"/" ]]; then
21-
# file_is_skipped=true
22-
# break
23-
# fi
24-
# done
25-
# if [ "$file_is_skipped" = "false" ]; then
26-
# other_directories+="$(dirname "$file_to_check")\n"
27-
# trigger_ci=true
28-
# echo "Non doc file(s) changed - triggered ci: $trigger_ci"
29-
# echo -e $other_directories
30-
# echo "trigger-ci=$trigger_ci" >>"$GITHUB_OUTPUT"
31-
# exit 0 ## if file is outside of the skipped_directory exit script
32-
# fi
33-
# done
34-
35-
# echo "Only doc file(s) changed - triggered ci: $trigger_ci"
36-
echo "Doc file(s) change detection is currently disabled - triggering ci"
37-
echo "trigger-ci=$trigger_ci" >>"$GITHUB_OUTPUT"
39+
echo -e "$files_to_check"
40+
SKIP_CI=true
41+
echo "Changes detected in only documentation files - skip-ci: $SKIP_CI"
42+
export $SKIP_CI

.github/workflows/go-tests.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ permissions:
2222
env:
2323
TEST_RESULTS: /tmp/test-results
2424
GOPRIVATE: github.com/hashicorp # Required for enterprise deps
25+
SKIP_CHECK_BRANCH: ${{ github.head_ref || github.ref_name }}
2526

2627
# concurrency
2728
concurrency:
@@ -33,19 +34,21 @@ jobs:
3334
runs-on: ubuntu-latest
3435
name: Get files changed and conditionally skip CI
3536
outputs:
36-
trigger-ci: ${{ steps.read-files.outputs.trigger-ci }}
37+
skip-ci: ${{ steps.read-files.outputs.skip-ci }}
3738
steps:
3839
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
3940
with:
4041
fetch-depth: 0
4142
- name: Get changed files
4243
id: read-files
43-
run: ./.github/scripts/filter_changed_files_go_test.sh
44+
run: |
45+
./.github/scripts/filter_changed_files_go_test.sh
46+
echo "skip-ci=${SKIP_CI}" >> "${GITHUB_ENV}"
4447
4548
setup:
4649
needs: [conditional-skip]
4750
name: Setup
48-
if: needs.conditional-skip.outputs.trigger-ci == 'true'
51+
if: needs.conditional-skip.outputs.skip-ci != 'true'
4952
runs-on: ubuntu-latest
5053
outputs:
5154
compute-small: ${{ steps.setup-outputs.outputs.compute-small }}
@@ -506,7 +509,7 @@ jobs:
506509
- go-test-32bit
507510
# - go-test-s390x
508511
runs-on: ${{ fromJSON(needs.setup.outputs.compute-small) }}
509-
if: always() && needs.conditional-skip.outputs.trigger-ci == 'true'
512+
if: always() && needs.conditional-skip.outputs.skip-ci != 'true'
510513
steps:
511514
- name: evaluate upstream job results
512515
run: |

.github/workflows/test-integrations.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ env:
2424
# strip the hashicorp/ off the front of github.repository for consul
2525
CONSUL_LATEST_IMAGE_NAME: ${{ endsWith(github.repository, '-enterprise') && github.repository || 'hashicorp/consul' }}
2626
GOPRIVATE: github.com/hashicorp # Required for enterprise deps
27+
SKIP_CHECK_BRANCH: ${{ github.head_ref || github.ref_name }}
2728

2829
concurrency:
2930
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
@@ -34,20 +35,22 @@ jobs:
3435
runs-on: ubuntu-latest
3536
name: Get files changed and conditionally skip CI
3637
outputs:
37-
trigger-ci: ${{ steps.read-files.outputs.trigger-ci }}
38+
skip-ci: ${{ steps.read-files.outputs.skip-ci }}
3839
steps:
3940
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
4041
with:
4142
fetch-depth: 0
4243
- name: Get changed files
4344
id: read-files
44-
run: ./.github/scripts/filter_changed_files_go_test.sh
45+
run: |
46+
./.github/scripts/filter_changed_files_go_test.sh
47+
echo "skip-ci=${SKIP_CI}" >> "${GITHUB_ENV}"
4548
4649
setup:
4750
needs: [conditional-skip]
4851
runs-on: ubuntu-latest
4952
name: Setup
50-
if: needs.conditional-skip.outputs.trigger-ci == 'true'
53+
if: needs.conditional-skip.outputs.skip-ci != 'true'
5154
outputs:
5255
compute-small: ${{ steps.runners.outputs.compute-small }}
5356
compute-medium: ${{ steps.runners.outputs.compute-medium }}
@@ -495,7 +498,7 @@ jobs:
495498
- envoy-integration-test
496499
- compatibility-integration-test
497500
runs-on: ${{ fromJSON(needs.setup.outputs.compute-small) }}
498-
if: always() && needs.conditional-skip.outputs.trigger-ci == 'true'
501+
if: always() && needs.conditional-skip.outputs.skip-ci != 'true'
499502
steps:
500503
- name: evaluate upstream job results
501504
run: |

0 commit comments

Comments
 (0)