Skip to content

Commit 00e79c5

Browse files
committed
Bla
1 parent 9506bf3 commit 00e79c5

File tree

2 files changed

+74
-34
lines changed

2 files changed

+74
-34
lines changed

action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,41 @@ runs:
4949
${{ inputs.branch }} \
5050
> flaky_tests.json
5151
52+
- name: Dump flaky_tests.json
53+
shell: bash
54+
run: |
55+
echo "flaky_tests.json content:"
56+
cat flaky_tests.json
57+
58+
## Upload artifact
59+
- name: Upload
60+
uses: actions/upload-artifact@v4
61+
with:
62+
path: flaky_tests.json
63+
5264
- name: Post message to ${{ inputs.slack-channel-name }} Slack channel
65+
id: slackmessage
5366
if: success()
5467
uses: slackapi/[email protected]
5568
with:
5669
payload-file-path: './flaky_tests.json'
5770
webhook: ${{ inputs.slack-incoming-webhooks-url }}
5871
webhook-type: incoming-webhook
5972

73+
- name: Print action result
74+
shell: bash
75+
run: |
76+
echo "Action result:"
77+
echo "${{ steps.slackmessage.outputs.result }}"
78+
echo "Action status:"
79+
echo "${{ steps.slackmessage.outputs.status }}"
80+
echo "Action message:"
81+
echo "${{ steps.slackmessage.outputs.message }}"
82+
echo "Action error:"
83+
echo "${{ steps.slackmessage.outputs.error }}"
84+
echo "Action response:"
85+
echo "${{ steps.slackmessage.outputs.response }}"
86+
6087
branding:
6188
icon: 'list'
6289
color: 'blue'

find_flaky_tests.py

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from github import Auth, Repository
77
from github import Github
88
from typing import Dict, List
9+
import json as json_lib
910

1011
MAX_FILENAME_LENGTH = 60
1112

@@ -120,53 +121,65 @@ def render_msg_header(state: AppState) -> str:
120121

121122

122123
def print_for_slack(occurrences: List[Occurrence], state: AppState):
123-
json = """
124-
{
125-
"channel": "@CHANNEL@",
124+
occurrences_by_ann_path: Dict[str, List[Occurrence]] = {}
125+
for o in occurrences:
126+
occurrences_by_ann_path.setdefault(o.annotation_path, []).append(o)
127+
items = [i for i in occurrences_by_ann_path.items()]
128+
items.sort(key=lambda i: len(i[1]), reverse=True) # sort by number of occurrences, highest first
129+
130+
limit = 15 # limit to 12 items, to avoid running into issues with Slack API (limit 3000 chars)
131+
items = items[:limit]
132+
133+
chunk_size=5
134+
chunks = [items[i:i+chunk_size] for i in range(0, len(items), chunk_size)]
135+
136+
content_blocks = []
137+
138+
for chunk in chunks:
139+
content = ""
140+
for ann_path, occrs in chunk:
141+
nice_path = truncate_left(ann_path, MAX_FILENAME_LENGTH)
142+
count = len(occrs)
143+
content += f"{count}x `{nice_path}` "
144+
occrs.sort(key=lambda o: o.commit.timestamp, reverse=True)
145+
recent_occrs = occrs[:5]
146+
content += " ".join([f"<{occr.check_url}|{i+1}> " for i, occr in enumerate(recent_occrs)])
147+
content += '\\n'
148+
149+
content_blocks += [
150+
{
151+
"type": "section",
152+
"text": {
153+
"type": "mrkdwn",
154+
"text": f"Top failed runs (limit={limit}):\\n{content}"
155+
}
156+
}
157+
]
158+
159+
160+
data = {
161+
"channel": state.slack_channel,
126162
"text": "Flaky Tests Summary",
127163
"blocks": [
128164
{
129165
"type": "section",
130166
"text": {
131167
"type": "mrkdwn",
132-
"text": "@HEADER@"
168+
"text": render_msg_header(state),
133169
}
134170
},
135171
{
136172
"type": "section",
137173
"text": {
138174
"type": "mrkdwn",
139-
"text": "Top failed runs (limit=@LIMIT@):\\n@CONTENT@"
175+
"text": f"Top {len(items)} failed runs (limit={limit})",
140176
}
141177
}
142-
]
178+
] + content_blocks
143179
}
144-
"""
145-
146-
occurrences_by_ann_path: Dict[str, List[Occurrence]] = {}
147-
for o in occurrences:
148-
occurrences_by_ann_path.setdefault(o.annotation_path, []).append(o)
149-
items = [i for i in occurrences_by_ann_path.items()]
150-
items.sort(key=lambda i: len(i[1]), reverse=True) # sort by number of occurrences, highest first
151180

152-
limit = 12 # limit to 12 items, to avoid running into issues with Slack API (limit 3000 chars)
153-
items = items[:limit]
181+
json = json_lib.dumps(data, indent=4)
154182

155-
content = ""
156-
for ann_path, occrs in items:
157-
nice_path = truncate_left(ann_path, MAX_FILENAME_LENGTH)
158-
count = len(occrs)
159-
content += f"{count}x `{nice_path}`"
160-
occrs.sort(key=lambda o: o.commit.timestamp, reverse=True)
161-
recent_occrs = occrs[:10]
162-
content += " ".join([f"<{occr.check_url}|{i+1}> " for i, occr in enumerate(recent_occrs)])
163-
content += '\\n'
164-
165-
header = render_msg_header(state)
166-
json = json.replace("@HEADER@", header)
167-
json = json.replace("@LIMIT@", str(limit))
168-
json = json.replace("@CHANNEL@", state.slack_channel)
169-
json = json.replace("@CONTENT@", content)
170183
print(json)
171184

172185

@@ -218,10 +231,10 @@ def main():
218231
state: AppState = parse_args()
219232
r = access_repo(state)
220233
occurrences = list_occurrences(state, r)
221-
if state.slack_channel:
222-
print_for_slack(occurrences, state)
223-
else:
224-
print_for_humans(occurrences)
234+
#if state.slack_channel:
235+
print_for_slack(occurrences, state)
236+
#else:
237+
# print_for_humans(occurrences)
225238

226239

227240
if __name__ == '__main__':

0 commit comments

Comments
 (0)