Skip to content

Commit 769e7bc

Browse files
authored
SP-000 add path-suffixes to filter better for frontend E2E and vitests failing tests (#12)
* SP-000 add path-suffixes to filter better for frontend E2E and vitests failing tests * SP-000 use tuple[str, ...] https://stackoverflow.com/questions/72001132/python-typing-tuplestr-vs-tuplestr
1 parent 9490d9e commit 769e7bc

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
repository: 'Staffbase/test-flaky'
2727
# optional: name of the branch where it should check, default: main
2828
branch: 'master'
29+
# optional: path suffixes to filter the test files
30+
path-suffixes: ".spec.ts,.spec.tsx,.test.ts,.test.tsx"
2931
# prefix of the test run which should be filtered out
3032
prefix: 'test-'
3133
# URL of the Slack incoming webhooks

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ inputs:
1717
required: false
1818
type: string
1919
default: 'main'
20+
path-suffixes:
21+
required: false
22+
type: string
2023
prefix:
2124
required: true
2225
type: string
@@ -45,6 +48,7 @@ runs:
4548
--slack-channel "${{ inputs.slack-channel-id }}" \
4649
--auth-token "${{ inputs.token }}" \
4750
--prefix "${{ inputs.prefix }}" \
51+
--path-suffixes "${{ inputs.path-suffixes }}" \
4852
${{ inputs.repository }} \
4953
${{ inputs.branch }} \
5054
> flaky_tests.json

find_flaky_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class AppState:
3131
repo: str
3232
branch: str
3333
slack_channel: str | None
34+
path_suffixes: tuple[str, ...] | None
3435
prefix: str | None
3536
since: datetime | None
3637
until: datetime | None
@@ -54,6 +55,14 @@ def parse_datetime(s):
5455
else:
5556
return datetime.strptime(s, '%Y-%m-%d')
5657

58+
# parse_suffixes_tuple is used to parse the suffixes argument from CLI
59+
# example: ".spec.ts,.spec.tsx,.test.ts,test.tsx" -> ('.spec.ts', '.spec.tsx', '.test.ts', 'test.tsx')
60+
def parse_suffixes_tuple(s: str | None) -> tuple[str, ...] | None:
61+
if s is None:
62+
return None
63+
else:
64+
return tuple(item.strip() for item in s.split(','))
65+
5766

5867
def validate_and_split_repo(repo: str) -> (str, str):
5968
if '/' not in repo:
@@ -69,6 +78,7 @@ def parse_args() -> AppState:
6978
parser.add_argument('--auth-token', type=str, help='GitHub auth token (required)', required=True)
7079
parser.add_argument('--slack-channel', type=str,
7180
help='Format output for posting in Slack to given channel')
81+
parser.add_argument('--path-suffixes', type=str, help='file path suffixes to filter annotations by. Could be tuple ".spec.ts,.spec.tsx,.test.ts,.test.tsx"',)
7282
parser.add_argument('--prefix', type=str, help='prefix to filter annotations by', required=True)
7383
parser.add_argument('--since', type=str,
7484
help='date to start from, format YYYY-MM-DD defaults to start of day (midnight UTC), '
@@ -91,6 +101,7 @@ def parse_args() -> AppState:
91101
since=parse_since(args.since),
92102
until=parse_until(args.until),
93103
slack_channel=args.slack_channel,
104+
path_suffixes=parse_suffixes_tuple(args.path_suffixes),
94105
prefix=args.prefix
95106
)
96107
except Exception as e:
@@ -221,6 +232,9 @@ def list_occurrences(state: AppState, r: Repository) -> List[Occurrence]:
221232
if ann.path == '.github':
222233
continue
223234
# filter out build errors or other issues, which are not flaky tests
235+
# filter out annotations that do not match the given suffixes in the file path
236+
if state.path_suffixes and not ann.path.endswith(tuple(state.path_suffixes)):
237+
continue
224238
if not ann.message.startswith(state.prefix):
225239
continue
226240
# annotation path contains something like ".../packageA/TestA.xml" or ".../packageB/TestB.kt"

0 commit comments

Comments
 (0)