Skip to content

Commit

Permalink
Validate regex before building image for e2e test (kedacore#5783)
Browse files Browse the repository at this point in the history
* added regex pre check before building image

Signed-off-by: Yaxhveer <[email protected]>

* updated changelog

Signed-off-by: Yaxhveer <[email protected]>

* refactored

Signed-off-by: Yaxhveer <[email protected]>

* corrected

Signed-off-by: Yaxhveer <[email protected]>

* corrected changelog

Signed-off-by: Yaxhveer <[email protected]>

* updated the workflow

Signed-off-by: Yaxhveer <[email protected]>

* updated the workflow

Signed-off-by: Yaxhveer <[email protected]>

---------

Signed-off-by: Yaxhveer <[email protected]>
Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
Yaxhveer authored and JorTurFer committed Jul 30, 2024
1 parent bdfeec3 commit 67ef8c1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pr-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 14 additions & 11 deletions tests/run-all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
//
Expand Down

0 comments on commit 67ef8c1

Please sign in to comment.