Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update base ref property name #18851

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions .github/scripts/filter_changed_files_go_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 # 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
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
11 changes: 7 additions & 4 deletions .github/workflows/go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand Down