Skip to content

Commit 9bbf9f6

Browse files
committed
Bla
1 parent 9506bf3 commit 9bbf9f6

File tree

2 files changed

+75
-34
lines changed

2 files changed

+75
-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: 48 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,66 @@ 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 = 12
131+
items = items[:limit]
132+
133+
# Chunk results so that individual message blocks do not exceed the 3000 character limit from Slack API
134+
chunk_size=5
135+
chunks = [items[i:i+chunk_size] for i in range(0, len(items), chunk_size)]
136+
137+
content_blocks = []
138+
139+
for chunk in chunks:
140+
content = ""
141+
for ann_path, occrs in chunk:
142+
nice_path = truncate_left(ann_path, MAX_FILENAME_LENGTH)
143+
count = len(occrs)
144+
content += f"{count}x `{nice_path}` "
145+
occrs.sort(key=lambda o: o.commit.timestamp, reverse=True)
146+
recent_occrs = occrs[:5]
147+
content += " ".join([f"<{occr.check_url}|{i+1}> " for i, occr in enumerate(recent_occrs)])
148+
content += '\n'
149+
150+
content_blocks += [
151+
{
152+
"type": "section",
153+
"text": {
154+
"type": "mrkdwn",
155+
"text": content,
156+
}
157+
}
158+
]
159+
160+
161+
data = {
162+
"channel": state.slack_channel,
126163
"text": "Flaky Tests Summary",
127164
"blocks": [
128165
{
129166
"type": "section",
130167
"text": {
131168
"type": "mrkdwn",
132-
"text": "@HEADER@"
169+
"text": render_msg_header(state),
133170
}
134171
},
135172
{
136173
"type": "section",
137174
"text": {
138175
"type": "mrkdwn",
139-
"text": "Top failed runs (limit=@LIMIT@):\\n@CONTENT@"
176+
"text": f"Top {len(items)} failed runs (limit={limit})",
140177
}
141178
}
142-
]
179+
] + content_blocks
143180
}
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
151181

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

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)
170184
print(json)
171185

172186

@@ -218,10 +232,10 @@ def main():
218232
state: AppState = parse_args()
219233
r = access_repo(state)
220234
occurrences = list_occurrences(state, r)
221-
if state.slack_channel:
222-
print_for_slack(occurrences, state)
223-
else:
224-
print_for_humans(occurrences)
235+
#if state.slack_channel:
236+
print_for_slack(occurrences, state)
237+
#else:
238+
# print_for_humans(occurrences)
225239

226240

227241
if __name__ == '__main__':

0 commit comments

Comments
 (0)