From 94e3ae77c946b2383d561528eb5645dd4bebc074 Mon Sep 17 00:00:00 2001 From: hc-github-team-consul-core Date: Mon, 19 Aug 2024 12:16:40 -0400 Subject: [PATCH] Backport of [NET-10737] Add CI Checks for Generated Testdata into release/1.19.x (#21615) * backport of commit 4e640697560289910044802ed8fb5d45f8245d4a * backport of commit ebafd9bd2e0c49933b094fdffbbad32e83b58da0 * backport of commit b5faaaf197dc6664f4db9f5a81b9d71e9985cce0 * backport of commit 6f84348147d1fd33daaae32ade1698f74f85c977 * backport of commit 31539a28be069f646a982642ca9a87c63115443a * backport of commit 3008a45f3f64fa36316d01d8ab382023713c5e85 * backport of commit 76203607d2e3c6500176338f44443e16a9d6270e * backport of commit e9f7fe987cd766019225e393d99963b58df8f80a * backport of commit 945b4529c1a2a86283bf79d76ef5bfd1553ea720 * backport of commit be49ab579cada74bbe27a23064903dc67e48143d --------- Co-authored-by: jm96441n --- .github/scripts/goldenfile_checker.sh | 21 +++++++++++++++++ .github/workflows/goldenfile-checker.yml | 30 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 .github/scripts/goldenfile_checker.sh create mode 100644 .github/workflows/goldenfile-checker.yml diff --git a/.github/scripts/goldenfile_checker.sh b/.github/scripts/goldenfile_checker.sh new file mode 100755 index 000000000000..61eb8e57243a --- /dev/null +++ b/.github/scripts/goldenfile_checker.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +set -euo pipefail + +# check if there is a diff in the xds testdata directory after running `make envoy-regen` +echo "regenerating xds files" +make envoy-regen &>/dev/null + +echo "calculating changed files" +changed_xds_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/$GITHUB_BRANCH_REF")" | egrep "agent/xds/testdata/.*" || true) +# If we do not find a file in .changelog/, we fail the check +if [ -z "$changed_xds_files" ]; then + # pass status check if no changes were found for xds files + echo "Found no changes to xds golden files" + exit 0 +else + echo "Found diffs with xds golden files run 'make envoy-regen' to update them and check that output is expected" + exit 0 +fi diff --git a/.github/workflows/goldenfile-checker.yml b/.github/workflows/goldenfile-checker.yml new file mode 100644 index 000000000000..fed1f30471dc --- /dev/null +++ b/.github/workflows/goldenfile-checker.yml @@ -0,0 +1,30 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +# This workflow checks that are no changes necessary to golden files for xds +# tests ensuring they are up to date + +name: Golden File Checker + +on: + pull_request: + types: [opened, synchronize, labeled] + # Runs on PRs to main and all release branches + branches: + - main + - release/* + +jobs: + # checks that there is no diff between the existing golden files + goldenfile-check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 # by default the checkout action doesn't checkout all branches + - name: Check for golden file xds tests in diff + run: ./.github/scripts/goldenfile_checker.sh + env: + GITHUB_BRANCH_REF: ${{ github.event.pull_request.head.ref }}