Skip to content

Commit 1f61f1d

Browse files
feat(go-flaky-tests): add ignored-tests option to filter out specific test failures (#1359)
* Add ignored-tests option to filter out specific test failures Adds ability to exclude specific tests from flaky test analysis by name. Tests in the ignored list are filtered out before applying top-K limit, ensuring they don't consume analysis slots or generate GitHub issues. * remove whitespace
1 parent 052ae53 commit 1f61f1d

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

actions/go-flaky-tests/action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ inputs:
3535
description: "Include only the top K flaky tests by distinct branches count in analysis"
3636
required: false
3737
default: "3"
38+
ignored-tests:
39+
description: "Comma-delimited test names to skip failures for"
40+
required: false
41+
default: ""
3842

3943
runs:
4044
using: "composite"
@@ -67,3 +71,4 @@ runs:
6771
REPOSITORY_DIRECTORY: ${{ inputs.repository-directory }}
6872
SKIP_POSTING_ISSUES: ${{ inputs.skip-posting-issues }}
6973
TOP_K: ${{ inputs.top-k }}
74+
IGNORED_TESTS: ${{ inputs.ignored-tests }}

actions/go-flaky-tests/cmd/go-flaky-tests/analyzer.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ func (t *TestFailureAnalyzer) AnalyzeFailures(config Config) (*FailuresReport, e
118118
if err != nil {
119119
return nil, fmt.Errorf("failed to parse test failures: %w", err)
120120
}
121+
122+
// Filter out ignored tests
123+
if len(config.IgnoredTests) > 0 {
124+
log.Printf("🚫 Filtering out %d ignored tests: %v", len(config.IgnoredTests), config.IgnoredTests)
125+
var filteredTests []FlakyTest
126+
for _, test := range flakyTests {
127+
ignored := false
128+
for _, ignoredTest := range config.IgnoredTests {
129+
if test.TestName == ignoredTest {
130+
ignored = true
131+
break
132+
}
133+
}
134+
if !ignored {
135+
filteredTests = append(filteredTests, test)
136+
}
137+
}
138+
log.Printf("📊 Filtered tests: %d -> %d (removed %d ignored tests)", len(flakyTests), len(filteredTests), len(flakyTests)-len(filteredTests))
139+
flakyTests = filteredTests
140+
}
141+
121142
if len(flakyTests) > config.TopK {
122143
flakyTests = flakyTests[:config.TopK]
123144
}

actions/go-flaky-tests/cmd/go-flaky-tests/config.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55
"strconv"
6+
"strings"
67
)
78

89
type Config struct {
@@ -14,6 +15,7 @@ type Config struct {
1415
RepositoryDirectory string
1516
SkipPostingIssues bool
1617
TopK int
18+
IgnoredTests []string
1719
}
1820

1921
func getConfigFromEnv() Config {
@@ -26,6 +28,7 @@ func getConfigFromEnv() Config {
2628
RepositoryDirectory: getEnvWithDefault("REPOSITORY_DIRECTORY", "."),
2729
SkipPostingIssues: getBoolEnvWithDefault("SKIP_POSTING_ISSUES", true),
2830
TopK: getIntEnvWithDefault("TOP_K", 3),
31+
IgnoredTests: getStringSliceFromEnv("IGNORED_TESTS"),
2932
}
3033
}
3134

@@ -51,3 +54,19 @@ func getIntEnvWithDefault(key string, defaultValue int) int {
5154
}
5255
return defaultValue
5356
}
57+
58+
func getStringSliceFromEnv(key string) []string {
59+
value := os.Getenv(key)
60+
if value == "" {
61+
return []string{}
62+
}
63+
64+
var result []string
65+
for _, item := range strings.Split(value, ",") {
66+
trimmed := strings.TrimSpace(item)
67+
if trimmed != "" {
68+
result = append(result, trimmed)
69+
}
70+
}
71+
return result
72+
}

actions/go-flaky-tests/run-local.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ usage() {
2525
echo " --repository-directory DIR Repository directory (default: current directory)"
2626
echo " --skip-posting-issues BOOL Skip creating GitHub issues (default: ${DEFAULT_SKIP_POSTING_ISSUES})"
2727
echo " --top-k NUM Number of top flaky tests to analyze (default: ${DEFAULT_TOP_K})"
28+
echo " --ignored-tests TESTS Comma-delimited test names to skip failures for"
2829
echo ""
2930
echo "Environment variables:"
3031
echo " LOKI_URL, LOKI_USERNAME, LOKI_PASSWORD, REPOSITORY, TIME_RANGE,"
31-
echo " REPOSITORY_DIRECTORY, GITHUB_TOKEN, SKIP_POSTING_ISSUES, TOP_K"
32+
echo " REPOSITORY_DIRECTORY, GITHUB_TOKEN, SKIP_POSTING_ISSUES, TOP_K, IGNORED_TESTS"
3233
echo ""
3334
echo "Example:"
3435
echo " $0 --loki-url http://localhost:3100 --repository myorg/myrepo --time-range 7d"
@@ -77,6 +78,10 @@ while [[ $# -gt 0 ]]; do
7778
TOP_K="$2"
7879
shift 2
7980
;;
81+
--ignored-tests)
82+
IGNORED_TESTS="$2"
83+
shift 2
84+
;;
8085
*)
8186
echo "Unknown option: $1"
8287
usage
@@ -111,6 +116,7 @@ export GITHUB_TOKEN
111116
export REPOSITORY_DIRECTORY
112117
export SKIP_POSTING_ISSUES
113118
export TOP_K
119+
export IGNORED_TESTS
114120

115121
echo "🔧 Running go-flaky-tests locally..."
116122
echo "📊 Repository: $REPOSITORY"

0 commit comments

Comments
 (0)