Skip to content

Commit 911fbed

Browse files
Merge pull request #275 from mozilla-mobile/philimon/parallelize_weekly_staging
Philimon/parallelize weekly staging
2 parents 58e9b0d + 896a538 commit 911fbed

2 files changed

Lines changed: 54 additions & 48 deletions

File tree

.github/workflows/staging-weekly-desktop.yml

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,29 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
deploy:
11-
name: Desktop TestOps Report (WEEKLY) - Production
10+
reports:
11+
name: Weekly reports (${{ matrix.name }})
1212
runs-on: ubuntu-latest
1313

14+
strategy:
15+
fail-fast: false
16+
max-parallel: 4
17+
matrix:
18+
include:
19+
- name: Query Test Plans and Runs
20+
args: --report-type testrail-test-results --project firefox-desktop
21+
- name: Query Test Run Average Health
22+
args: --report-type testrail-test-health --project firefox-desktop --platform desktop --num-days 7
23+
- name: Query Bugzilla Release Flags Bugs
24+
args: --report-type bugzilla-desktop-release-flags-for-bugs
25+
- name: Query Bugzilla Overall Bugs
26+
args: --report-type bugzilla-desktop-overall-bugs
27+
1428
steps:
1529
- name: Check out source repository
1630
uses: actions/checkout@v6
1731

18-
- name: Setup python
32+
- name: Setup python
1933
uses: actions/setup-python@v6
2034

2135
- name: Establish Cloud SQL Proxy
@@ -26,10 +40,10 @@ jobs:
2640
port: ${{ secrets.CLOUD_SQL_DATABASE_PORT }}
2741
proxy_version: "1.37.11"
2842

29-
- name: Install requirements
43+
- name: Install requirements
3044
run: pip install -r requirements.txt
3145

32-
- name: Set env vars
46+
- name: Set env vars
3347
run: |
3448
echo "CLOUD_SQL_DATABASE_USERNAME=${{ secrets.CLOUD_SQL_DATABASE_USERNAME }}" >> $GITHUB_ENV
3549
echo "CLOUD_SQL_DATABASE_PASSWORD=${{ secrets.CLOUD_SQL_DATABASE_PASSWORD }}" >> $GITHUB_ENV
@@ -46,29 +60,21 @@ jobs:
4660
echo "JIRA_HOST=${{ secrets.JIRA_HOST }}" >> $GITHUB_ENV
4761
echo "JIRA_USER=${{ secrets.JIRA_USER }}" >> $GITHUB_ENV
4862
echo "JIRA_PASSWORD=${{ secrets.JIRA_PASSWORD }}" >> $GITHUB_ENV
49-
50-
- name: Query Test Plans and Runs
51-
run: python ./__main__.py --report-type testrail-test-results --project firefox-desktop
52-
continue-on-error: true
53-
54-
- name: Query Test Run Average Health
55-
run: python ./__main__.py --report-type testrail-test-health --project firefox-desktop --platform desktop --num-days 7
63+
- run: python ./__main__.py ${{ matrix.args }}
5664
continue-on-error: true
5765

58-
- name: Query Bugzilla Release Flags Bugs
59-
run: python ./__main__.py --report-type bugzilla-desktop-release-flags-for-bugs
60-
continue-on-error: true
61-
62-
- name: Query Bugzilla Overall Bugs
63-
run: python ./__main__.py --report-type bugzilla-desktop-overall-bugs
6466

67+
notify:
68+
name: Send workflow status notification
69+
runs-on: ubuntu-latest
70+
needs: [reports]
71+
if: always()
72+
steps:
73+
- uses: actions/checkout@v6
6574
- name: Set job log URL
66-
if: always()
6775
run: echo "JOB_LOG_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV
6876

69-
- name: Send custom JSON data to Slack workflow
70-
if: always()
71-
id: slack
77+
- name: Send workflow status to Slack
7278
uses: slackapi/slack-github-action@v2.1.1
7379
env:
7480
WORKFLOW_NAME: ${{ github.workflow }}
@@ -77,9 +83,8 @@ jobs:
7783
JOB_STATUS_COLOR: ${{ job.status == 'success' && '#36a64f' || job.status == 'failure' && '#FF0000' }}
7884
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_MOBILE_ALERTS_TOOLING }}
7985
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
80-
8186
with:
8287
webhook: ${{ secrets.SLACK_WEBHOOK_URL_MOBILE_ALERTS_TOOLING }}
8388
webhook-type: webhook-trigger
8489
payload-templated: true
85-
payload-file-path: "./config/payload-slack-content.json"
90+
payload-file-path: "./config/payload-slack-content.json"

api/testrail/report_test_health.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from api.testrail.client import TestRail
2222
from api.testrail.helpers import testrail_project_ids
2323

24-
2524
_DB = None
2625
_TR = None
2726

@@ -93,21 +92,18 @@ def update_testrail_test_health_row(payload, update_list):
9392

9493
def increment_average(starting_count, starting_average, new_value) -> float:
9594
return (
96-
float(starting_average)
97-
* (float(starting_count) / float(starting_count + 1))
98-
) + (float(new_value) * (1.0 / float(starting_count + 1)))
95+
((float(starting_average) * float(starting_count)) + float(new_value))
96+
/ (float(starting_count) + 1)
97+
)
9998

10099
new_row["testrail_case_id"] = payload.get("case_id")
101100
new_row["testrail_project_id"] = payload.get("project_id")
102101
new_row["testrail_case_name"] = payload.get("case_name")
103102
new_row["testrail_suite_name"] = payload.get("suite_name")
104103

105104
try:
106-
matching_update = [
107-
u for u in update_list if u["testrail_case_id"] == payload["case_id"]
108-
]
109-
if matching_update:
110-
row = Update(**matching_update[0])
105+
if payload["case_id"] in update_list:
106+
row = Update(**(update_list.get(payload["case_id"])))
111107
else:
112108
row = db.session.scalars(
113109
select(ReportTestRailTestHealth).where(
@@ -153,7 +149,9 @@ def testrail_test_health(project, num_days=1):
153149

154150
# Dictionary of project ids and their respective service acct user id
155151
AUTOUSERS = {17: 976}
156-
updates = []
152+
suite_cache = {}
153+
test_cache = {}
154+
updates = {}
157155
project_ids_list = testrail_project_ids(project)[0]
158156
start_date = datetime.now() - timedelta(days=int(num_days))
159157
for project_id in project_ids_list:
@@ -171,12 +169,22 @@ def testrail_test_health(project, num_days=1):
171169
plan_details = tr.get_test_plan(plan.get("id"))
172170
for entry in plan_details.get("entries"):
173171
for run in entry.get("runs"):
174-
for result in tr.test_results_for_run(run.get("id")).get("results"):
172+
run_id = run.get("id")
173+
suite_id = run.get("suite_id")
174+
if suite_id not in suite_cache:
175+
suite_cache[suite_id] = tr.test_suite(
176+
suite_id).get("name")
177+
print(f"Processing Run: {run.get('name')}...")
178+
run_results = tr.test_results_for_run(run_id).get("results", [])
179+
print(f"Processing {len(run_results)} test results...")
180+
for result in run_results:
175181
if not result.get("elapsed"):
176182
continue
177-
test = tr.get_test(result.get("test_id"))
178-
suite_name = tr.test_suite(
179-
run.get("suite_id")).get("name")
183+
test_id = result.get("test_id")
184+
if test_id not in test_cache:
185+
test_cache[test_id] = tr.get_test(test_id)
186+
test = test_cache.get(test_id)
187+
suite_name = suite_cache.get(suite_id)
180188
update_payload = {
181189
"case_id": test.get("case_id"),
182190
"project_id": project_id,
@@ -191,23 +199,16 @@ def testrail_test_health(project, num_days=1):
191199
new_row = update_testrail_test_health_row(
192200
update_payload, updates
193201
)
194-
matching_row = [
195-
u
196-
for u in updates
197-
if u.get("testrail_case_id") == new_row["testrail_case_id"]
198-
]
199-
if matching_row:
200-
updates.remove(matching_row[0])
201-
updates.append(new_row)
202+
updates[new_row.get("testrail_case_id")] = new_row
202203

203204
report_test_health_update(updates)
204205

205206

206207
def report_test_health_update(payload):
207208
db = _db()
208-
for row in payload:
209+
for testrail_case_id, row in payload.items():
209210
matching_row = db.session.query(ReportTestRailTestHealth).filter(
210-
ReportTestRailTestHealth.testrail_case_id == row["testrail_case_id"]
211+
ReportTestRailTestHealth.testrail_case_id == testrail_case_id
211212
)
212213
if matching_row.all():
213214
matching_row.update(row, synchronize_session="fetch")

0 commit comments

Comments
 (0)