From 67ef8c162e062031d27631e3d6f1bef6ff3baf4b Mon Sep 17 00:00:00 2001 From: Yashveer <101015836+Yaxhveer@users.noreply.github.com> Date: Sun, 26 May 2024 19:40:25 +0530 Subject: [PATCH] Validate regex before building image for e2e test (#5783) * added regex pre check before building image Signed-off-by: Yaxhveer * updated changelog Signed-off-by: Yaxhveer * refactored Signed-off-by: Yaxhveer * corrected Signed-off-by: Yaxhveer * corrected changelog Signed-off-by: Yaxhveer * updated the workflow Signed-off-by: Yaxhveer * updated the workflow Signed-off-by: Yaxhveer --------- Signed-off-by: Yaxhveer Signed-off-by: Jorge Turrado --- .github/workflows/pr-e2e.yml | 36 ++++++++++++++++++++++++++++++++++++ tests/run-all.go | 25 ++++++++++++++----------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr-e2e.yml b/.github/workflows/pr-e2e.yml index c111aa98600..2d7bc9c090f 100644 --- a/.github/workflows/pr-e2e.yml +++ b/.github/workflows/pr-e2e.yml @@ -93,6 +93,42 @@ jobs: gh pr checkout ${{ needs.triage.outputs.pr_num }} git checkout ${{ needs.triage.outputs.commit_sha }} + - name: Run regex checks + id: regex-validation + continue-on-error: true + env: + COMMENT_BODY: ${{ github.event.comment.body }} + run: | + MESSAGE="$COMMENT_BODY" + REGEX='/run-e2e (.+)' + if [[ "$MESSAGE" =~ $REGEX ]] + then + export E2E_TEST_REGEX="$(echo ${BASH_REMATCH[1]} | head -1)" + fi + make e2e-regex-check + + - name: React to comment with failure + uses: dkershner6/reaction-action@v2 + if: steps.regex-validation.outcome != 'success' + with: + token: ${{ secrets.GITHUB_TOKEN }} + commentId: ${{ github.event.comment.id }} + reaction: "-1" + + - name: Set status failure + uses: LouisBrunner/checks-action@6b626ffbad7cc56fd58627f774b9067e6118af23 # v2 + if: steps.regex-validation.outcome != 'success' + with: + token: ${{ secrets.GITHUB_TOKEN }} + sha: ${{ needs.triage.outputs.commit_sha }} + name: ${{ env.E2E_CHECK_NAME }} + conclusion: failure + details_url: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} + + - name: Exit on failure + if: steps.regex-validation.outcome != 'success' + run: exit 1 + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: diff --git a/tests/run-all.go b/tests/run-all.go index bf9029c5ff4..76134d55e32 100644 --- a/tests/run-all.go +++ b/tests/run-all.go @@ -41,11 +41,25 @@ type TestResult struct { func main() { ctx := context.Background() + // + // Detect test cases + // e2eRegex := os.Getenv("E2E_TEST_REGEX") if e2eRegex == "" { e2eRegex = ".*_test.go" } + regularTestFiles := getRegularTestFiles(e2eRegex) + sequentialTestFiles := getSequentialTestFiles(e2eRegex) + if len(regularTestFiles) == 0 && len(sequentialTestFiles) == 0 { + fmt.Printf("No test has been executed, please review your regex: '%s'\n", e2eRegex) + os.Exit(1) + } + + if len(os.Args) > 1 && os.Args[1] == "regex-check" { + return + } + // // Install KEDA // @@ -57,17 +71,6 @@ func main() { os.Exit(1) } - // - // Detect test cases - // - regularTestFiles := getRegularTestFiles(e2eRegex) - sequentialTestFiles := getSequentialTestFiles(e2eRegex) - if len(regularTestFiles) == 0 && len(sequentialTestFiles) == 0 { - uninstallKeda(ctx) - fmt.Printf("No test has been executed, please review your regex: '%s'\n", e2eRegex) - os.Exit(1) - } - // // Execute regular tests //