Skip to content

Commit bf838b3

Browse files
authored
Merge branch 'main' into anca/cm-pl-ceneo
2 parents ce048fb + a1192d7 commit bf838b3

File tree

15 files changed

+176
-54
lines changed

15 files changed

+176
-54
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"]}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"url": "http://127.0.0.1:8080/thenorthface_ad.html",
3+
"field_mapping": {
4+
"given_name": "3ac62090-2fdd-4b96-9691-0271af51b778",
5+
"family_name": "91c8be54-b56a-4d0f-8f8e-ec7713e98dbe",
6+
"street_address": "47942d7f-a8d6-4118-aa28-712d9e7f412c",
7+
"address_level_2": "eb636f6a-04d9-4072-b4c2-0d1be07d9dce",
8+
"postal_code": "e681a820-0fe0-4001-ae57-798bc6879ab9",
9+
"telephone": "3e0f9331-2942-42f1-ab9d-a99da230ed21",
10+
"email": "cd9a5f98-16a8-4314-ba4b-90e3acb419ef"
11+
},
12+
13+
"form_field": "*[data-moz-autofill-inspect-id='{given_name}']",
14+
"fields": [
15+
"3ac62090-2fdd-4b96-9691-0271af51b778",
16+
"91c8be54-b56a-4d0f-8f8e-ec7713e98dbe",
17+
"47942d7f-a8d6-4118-aa28-712d9e7f412c",
18+
"eb636f6a-04d9-4072-b4c2-0d1be07d9dce",
19+
"e681a820-0fe0-4001-ae57-798bc6879ab9",
20+
"3e0f9331-2942-42f1-ab9d-a99da230ed21",
21+
"cd9a5f98-16a8-4314-ba4b-90e3acb419ef"
22+
]
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"url": "http://127.0.0.1:8080/thenorthface_cc.html",
3+
"field_mapping": {
4+
"card_number": "cbdbd82e-0090-4545-9bdf-214e047228e8",
5+
"expiration_date": "7fb30475-14a0-4251-88f4-a6188cca11f9",
6+
"cvv": "6d9ffa11-9d5a-4dd5-b44f-51b3b8bd5b32"
7+
},
8+
9+
"form_field": "*[data-moz-autofill-inspect-id='{name}']",
10+
"skip": "True",
11+
"fields": [
12+
"cbdbd82e-0090-4545-9bdf-214e047228e8",
13+
"7fb30475-14a0-4251-88f4-a6188cca11f9",
14+
"6d9ffa11-9d5a-4dd5-b44f-51b3b8bd5b32"
15+
]
16+
}

l10n_CM/region/ES.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"demo",
55
"ebay",
66
"zooplus",
7+
"thenorthface",
78
"calvinklein"
89
],
910
"tests": [

l10n_CM/run_l10n.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"tanie-leczenie",
5252
"duka",
5353
"ceneo",
54-
"zooplus"
54+
"thenorthface"
5555
}
5656

5757
loaded_valid_sites = valid_l10n_mappings().keys()

0 commit comments

Comments
 (0)