Skip to content

Commit a1192d7

Browse files
Merge pull request #713 from mozilla/philimon/choose_split
Philimon/l10n_choose_split
2 parents 372b86a + 0c9595f commit a1192d7

File tree

7 files changed

+128
-42
lines changed

7 files changed

+128
-42
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: L10N output mapping splits
3+
4+
run-name: ${{ github.actor }} is writing L10N mapping splits
5+
on:
6+
schedule:
7+
- cron: "0 0 * * 1"
8+
9+
permissions:
10+
contents: "write"
11+
12+
jobs:
13+
Select-Channels:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
channels: ${{ steps.splits.outputs.channels }}
17+
steps:
18+
- name: Create app token
19+
uses: actions/create-github-app-token@v1
20+
id: app-token
21+
with:
22+
app-id: ${{ secrets.BOT_CLIENT_ID }}
23+
private-key: ${{ secrets.BOT_PRIVATE_KEY }}
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
with:
27+
token: ${{ steps.app-token.outputs.token }}
28+
- name: Select test channels
29+
id: splits
30+
run: |
31+
python3 choose_l10n_beta_split.py

choose_l10n_beta_split.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import json
2+
import logging
3+
import sys
4+
from collections import defaultdict
5+
6+
from choose_l10n_ci_set import valid_l10n_mappings
7+
8+
9+
def distribute_mappings_evenly(mappings):
10+
"""
11+
Distribute the selected mappings into 3 splits and return the container.
12+
13+
Args:
14+
mappings (dict): A dictionary of mappings, where the keys are sites and the values are sets of regions.
15+
"""
16+
if not mappings:
17+
return {}
18+
# sort the mappings by the length of the regions per site
19+
mappings = dict(sorted(mappings.items(), key=lambda val: len(val[1]), reverse=True))
20+
# place the mappings into 3 containers evenly according to the load
21+
loads = [0, 0, 0]
22+
balanced_splits = [defaultdict(list) for _ in range(3)]
23+
for site, regions in mappings.items():
24+
min_idx = loads.index(min(loads))
25+
balanced_splits[min_idx][site] = list(regions)
26+
loads[min_idx] += len(regions)
27+
return balanced_splits
28+
29+
30+
if __name__ == "__main__":
31+
l10n_mappings = valid_l10n_mappings()
32+
all_splits = distribute_mappings_evenly(l10n_mappings)
33+
if not all_splits:
34+
logging.warning("No valid l10n mappings")
35+
sys.exit(1)
36+
for idx, split in enumerate(all_splits, start=1):
37+
with open(f"l10n_CM/beta_run_splits/l10n_split_{idx}.json", "w") as f:
38+
json.dump(split, f)

choose_l10n_ci_set.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,6 @@ def valid_l10n_mappings():
3434
return mapping
3535

3636

37-
def distribute_mappings_evenly(mappings, version):
38-
"""
39-
Distribute the selected mappings if its a reportable run.
40-
41-
Args:
42-
mappings (dict): A dictionary of mappings, where the keys are sites and the values are sets of regions.
43-
version (int): The beta_version of the beta.
44-
"""
45-
if not mappings:
46-
return {}
47-
if os.environ.get("TESTRAIL_REPORT"):
48-
# sort the mappings by the length of the regions per site
49-
mappings = dict(
50-
sorted(mappings.items(), key=lambda val: len(val[1]), reverse=True)
51-
)
52-
# place the mappings into 3 containers evenly according to the load
53-
loads = [0, 0, 0]
54-
containers = [defaultdict(set) for _ in range(3)]
55-
for key, value in mappings.items():
56-
min_idx = loads.index(min(loads))
57-
containers[min_idx][key] = value
58-
loads[min_idx] += len(value)
59-
# get container index according to beta beta_version
60-
run_idx = version % 3
61-
return containers[run_idx]
62-
else:
63-
return mappings
64-
65-
6637
def process_changed_file(f, selected_mappings):
6738
"""
6839
process the changed file to add the site/region mappings.
@@ -108,6 +79,21 @@ def save_mappings(selected_container):
10879
f.writelines(current_running_mappings)
10980

11081

82+
def select_l10n_mappings(beta_version):
83+
"""
84+
Select the correct l10n mappings.
85+
86+
Args:
87+
beta_version: the current beta version.
88+
"""
89+
beta_split = (beta_version % 3) + 1
90+
if os.path.exists(f"l10n_CM/beta_run_splits/l10n_split_{beta_split}.json"):
91+
with open(f"l10n_CM/beta_run_splits/l10n_split_{beta_split}.json", "r") as f:
92+
return json.load(f)
93+
else:
94+
return valid_l10n_mappings()
95+
96+
11197
if __name__ == "__main__":
11298
if os.path.exists(".env"):
11399
with open(".env") as fh:
@@ -134,11 +120,12 @@ def save_mappings(selected_container):
134120
except ValueError:
135121
# failsafe beta_version
136122
beta_version = 0
137-
l10n_mappings = valid_l10n_mappings()
123+
# choose split number
124+
l10n_mappings = select_l10n_mappings(beta_version)
138125
sample_mappings = {k: v for k, v in l10n_mappings.items() if k.startswith("demo")}
139126
if os.environ.get("TESTRAIL_REPORT") or os.environ.get("MANUAL"):
140127
# Run all tests if this is a scheduled beta or a manual run
141-
save_mappings(distribute_mappings_evenly(l10n_mappings, beta_version))
128+
save_mappings(l10n_mappings)
142129
sys.exit(0)
143130

144131
re_set_all = [
@@ -199,5 +186,5 @@ def save_mappings(selected_container):
199186
selected_mappings |= sample_mappings
200187
break
201188

202-
save_mappings(distribute_mappings_evenly(selected_mappings, beta_version))
189+
save_mappings(selected_mappings)
203190
sys.exit(0)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"demo": [
3+
"US",
4+
"GB",
5+
"DE",
6+
"FR",
7+
"PL",
8+
"ES",
9+
"CA"
10+
],
11+
"bijoubrigitte": [
12+
"DE"
13+
],
14+
"calvinklein": [
15+
"US"
16+
],
17+
"aldoshoes": [
18+
"US"
19+
],
20+
"peacocks": [
21+
"GB"
22+
],
23+
"assos": [
24+
"GB"
25+
],
26+
"fnac": [
27+
"FR"
28+
],
29+
"canadatire": [
30+
"CA"
31+
]
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"amazon": ["US", "CA", "DE", "FR"], "walmart": ["US", "CA"], "mediamarkt": ["DE"], "zalando": ["PL"], "bestbuy": ["US"], "apple": ["US"], "whittard": ["GB"], "tiffany": ["IT"], "yellowkorner": ["FR"], "burtsbees": ["CA"]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"ebay": ["ES", "IT", "CA", "GB"], "etsy": ["US", "CA"], "justspices": ["DE"], "lowes": ["US"], "newegg": ["US"], "wish": ["US"], "diy": ["GB"], "artsper": ["FR"], "newbalance": ["CA"]}

modules/testrail_integration.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55
import sys
66

7-
from choose_l10n_ci_set import distribute_mappings_evenly, valid_l10n_mappings
7+
from choose_l10n_ci_set import select_l10n_mappings
88
from modules import taskcluster as tc
99
from modules import testrail as tr
1010
from modules.testrail import TestRail
@@ -187,11 +187,9 @@ def reportable(platform_to_test=None):
187187

188188
plan_entries = this_plan.get("entries")
189189
if os.environ.get("FX_L10N"):
190-
report = True
191190
beta_version = int(minor_num.split("b")[-1])
192-
distributed_mappings = distribute_mappings_evenly(
193-
valid_l10n_mappings(), beta_version
194-
)
191+
distributed_mappings = select_l10n_mappings(beta_version)
192+
expected_mappings = sum(map(lambda x: len(x), distributed_mappings.values()))
195193
covered_mappings = 0
196194
# keeping this logic to still see how many mappings are reported.
197195
for entry in plan_entries:
@@ -205,13 +203,11 @@ def reportable(platform_to_test=None):
205203
and platform in run_platform
206204
):
207205
covered_mappings += 1
208-
report = False
209206
logging.warning(
210-
f"Potentially matching run found for {platform}, may be reportable. (Found {covered_mappings} site/region mappings reported.)"
207+
f"Potentially matching run found for {platform}, may be reportable. (Found {covered_mappings} site/region mappings reported, expected {expected_mappings}.)"
211208
)
212-
logging.warning(f"Run is reportable: {report}")
213-
# Only report when there is a new beta and no other site/region mappings are reported.
214-
return report
209+
# Only report when there is a new beta without a reported plan or if the selected split is not completely reported.
210+
return covered_mappings < expected_mappings
215211
else:
216212
covered_suites = 0
217213
for entry in plan_entries:

0 commit comments

Comments
 (0)