1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
These transformations take a task description and turn it into a TaskCluster
task definition (along with attributes, label, etc.). The input to these
transformations is generic to any kind of task, but abstracts away some of the
complexities of worker implementations, scopes, and treeherder annotations.
"""
import datetime
import hashlib
import os
import re
import time
from mozbuild.util import memoize
from mozilla_taskgraph.util.signed_artifacts import get_signed_artifacts
from taskcluster.utils import fromNow
from taskgraph import MAX_DEPENDENCIES
from taskgraph.transforms.base import TransformSequence
from taskgraph.transforms.task import payload_builder, payload_builders
from taskgraph.util.copy import deepcopy
from taskgraph.util.keyed_by import evaluate_keyed_by
from taskgraph.util.schema import (
Schema,
optionally_keyed_by,
resolve_keyed_by,
taskref_or_string,
validate_schema,
)
from taskgraph.util.treeherder import split_symbol
from voluptuous import All, Any, Extra, Match, NotIn, Optional, Required
from gecko_taskgraph import GECKO
from gecko_taskgraph.optimize.schema import OptimizationSchema
from gecko_taskgraph.transforms.job.common import get_expiration
from gecko_taskgraph.util import docker as dockerutil
from gecko_taskgraph.util.attributes import TRUNK_PROJECTS, is_try, release_level
from gecko_taskgraph.util.chunking import TEST_VARIANTS
from gecko_taskgraph.util.hash import hash_path
from gecko_taskgraph.util.partners import get_partners_to_be_published
from gecko_taskgraph.util.scriptworker import BALROG_ACTIONS, get_release_config
from gecko_taskgraph.util.workertypes import get_worker_type, worker_type_implementation
RUN_TASK_HG = os.path.join(GECKO, "taskcluster", "scripts", "run-task")
RUN_TASK_GIT = os.path.join(
GECKO,
"third_party",
"python",
"taskcluster_taskgraph",
"taskgraph",
"run-task",
"run-task",
)
SCCACHE_GCS_PROJECT = "sccache-3"
@memoize
def _run_task_suffix(repo_type):
"""String to append to cache names under control of run-task."""
if repo_type == "hg":
return hash_path(RUN_TASK_HG)[0:20]
return hash_path(RUN_TASK_GIT)[0:20]
def _compute_geckoview_version(app_version, moz_build_date):
"""Geckoview version string that matches geckoview gradle configuration"""
# Must be synchronized with /mobile/android/geckoview/build.gradle computeVersionCode(...)
version_without_milestone = re.sub(r"a[0-9]", "", app_version, 1)
parts = version_without_milestone.split(".")
return f"{parts[0]}.{parts[1]}.{moz_build_date}"
# A task description is a general description of a TaskCluster task
task_description_schema = Schema(
{
# the label for this task
Required("label"): str,
# description of the task (for metadata)
Required("description"): str,
# attributes for this task
Optional("attributes"): {str: object},
# relative path (from config.path) to the file task was defined in
Optional("task-from"): str,
# dependencies of this task, keyed by name; these are passed through
# verbatim and subject to the interpretation of the Task's get_dependencies
# method.
Optional("dependencies"): {
All(
str,
NotIn(
["self", "decision"],
"Can't use 'self` or 'decision' as depdency names.",
),
): object,
},
# Soft dependencies of this task, as a list of tasks labels
Optional("soft-dependencies"): [str],
# Dependencies that must be scheduled in order for this task to run.
Optional("if-dependencies"): [str],
Optional("requires"): Any("all-completed", "all-resolved"),
# expiration and deadline times, relative to task creation, with units
# (e.g., "14 days"). Defaults are set based on the project.
Optional("expires-after"): str,
Optional("deadline-after"): str,
Optional("expiration-policy"): str,
# custom routes for this task; the default treeherder routes will be added
# automatically
Optional("routes"): [str],
# custom scopes for this task; any scopes required for the worker will be
# added automatically. The following parameters will be substituted in each
# scope:
# {level} -- the scm level of this push
# {project} -- the project of this push
Optional("scopes"): [str],
# Tags
Optional("tags"): {str: str},
# custom "task.extra" content
Optional("extra"): {str: object},
# treeherder-related information; see
# https://firefox-ci-tc.services.mozilla.com/schemas/taskcluster-treeherder/v1/task-treeherder-config.json
# If not specified, no treeherder extra information or routes will be
# added to the task
Optional("treeherder"): {
# either a bare symbol, or "grp(sym)".
"symbol": str,
# the job kind
"kind": Any("build", "test", "other"),
# tier for this task
"tier": int,
# task platform, in the form platform/collection, used to set
# treeherder.machine.platform and treeherder.collection or
# treeherder.labels
"platform": Match("^[A-Za-z0-9_-]{1,50}/[A-Za-z0-9_-]{1,50}$"),
},
# information for indexing this build so its artifacts can be discovered;
# if omitted, the build will not be indexed.
Optional("index"): {
# the name of the product this build produces
"product": str,
# the names to use for this job in the TaskCluster index
"job-name": str,
# Type of gecko v2 index to use
"type": Any(
"generic",
"l10n",
"shippable",
"shippable-l10n",
"android-shippable",
"android-shippable-with-multi-l10n",
"shippable-with-multi-l10n",
),
# The rank that the task will receive in the TaskCluster
# index. A newly completed task supercedes the currently
# indexed task iff it has a higher rank. If unspecified,
# 'by-tier' behavior will be used.
"rank": Any(
# Rank is equal the timestamp of the build_date for tier-1
# tasks, and one for non-tier-1. This sorts tier-{2,3}
# builds below tier-1 in the index, but above eager-index.
"by-tier",
# Rank is given as an integer constant (e.g. zero to make
# sure a task is last in the index).
int,
# Rank is equal to the timestamp of the build_date. This
# option can be used to override the 'by-tier' behavior
# for non-tier-1 tasks.
"build_date",
),
},
# The `run_on_repo_type` attribute, defaulting to "hg". This dictates
# the types of repositories on which this task should be included in
# the target task set. See the attributes documentation for details.
Optional("run-on-repo-type"): [Any("git", "hg")],
# The `run_on_projects` attribute, defaulting to "all". This dictates the
# projects on which this task should be included in the target task set.
# See the attributes documentation for details.
Optional("run-on-projects"): optionally_keyed_by("build-platform", [str]),
# Like `run_on_projects`, `run-on-hg-branches` defaults to "all".
Optional("run-on-hg-branches"): optionally_keyed_by("project", [str]),
# The `shipping_phase` attribute, defaulting to None. This specifies the
# release promotion phase that this task belongs to.
Required("shipping-phase"): Any(
None,
"build",
"promote",
"push",
"ship",
),
# The `shipping_product` attribute, defaulting to None. This specifies the
# release promotion product that this task belongs to.
Required("shipping-product"): Any(None, str),
# The `always-target` attribute will cause the task to be included in the
# target_task_graph regardless of filtering. Tasks included in this manner
# will be candidates for optimization even when `optimize_target_tasks` is
# False, unless the task was also explicitly chosen by the target_tasks
# method.
Required("always-target"): bool,
# Optimization to perform on this task during the optimization phase.
# Optimizations are defined in taskcluster/gecko_taskgraph/optimize.py.
Required("optimization"): OptimizationSchema,
# the provisioner-id/worker-type for the task. The following parameters will
# be substituted in this string:
# {level} -- the scm level of this push
"worker-type": str,
# Whether the job should use sccache compiler caching.
Required("use-sccache"): bool,
# information specific to the worker implementation that will run this task
Optional("worker"): {
Required("implementation"): str,
Extra: object,
},
# Override the default priority for the project
Optional("priority"): str,
# Override the default 5 retries
Optional("retries"): int,
}
)
TC_TREEHERDER_SCHEMA_URL = (
"https://github.com/taskcluster/taskcluster-treeherder/"
"blob/master/schemas/task-treeherder-config.yml"
)
UNKNOWN_GROUP_NAME = (
"Treeherder group {} (from {}) has no name; " "add it to taskcluster/config.yml"
)
V2_ROUTE_TEMPLATES = [
"index.{trust-domain}.v2.{project}.latest.{product}.{job-name}",
"index.{trust-domain}.v2.{project}.pushdate.{build_date_long}.{product}.{job-name}",
"index.{trust-domain}.v2.{project}.pushdate.{build_date}.latest.{product}.{job-name}",
"index.{trust-domain}.v2.{project}.pushlog-id.{pushlog_id}.{product}.{job-name}",
"index.{trust-domain}.v2.{project}.revision.{branch_rev}.{product}.{job-name}",
"index.{trust-domain}.v2.{project}.revision.{branch_git_rev}.{product}.{job-name}",
]
# {central, inbound, autoland} write to a "trunk" index prefix. This facilitates
# walking of tasks with similar configurations.
V2_TRUNK_ROUTE_TEMPLATES = [
"index.{trust-domain}.v2.trunk.revision.{branch_rev}.{product}.{job-name}",
]
V2_SHIPPABLE_TEMPLATES = [
"index.{trust-domain}.v2.{project}.shippable.latest.{product}.{job-name}",
"index.{trust-domain}.v2.{project}.shippable.{build_date}.revision.{branch_rev}.{product}.{job-name}", # noqa - too long
"index.{trust-domain}.v2.{project}.shippable.{build_date}.latest.{product}.{job-name}",
"index.{trust-domain}.v2.{project}.shippable.revision.{branch_rev}.{product}.{job-name}",
"index.{trust-domain}.v2.{project}.shippable.revision.{branch_git_rev}.{product}.{job-name}",
]
V2_SHIPPABLE_L10N_TEMPLATES = [
"index.{trust-domain}.v2.{project}.shippable.latest.{product}-l10n.{job-name}.{locale}",
"index.{trust-domain}.v2.{project}.shippable.{build_date}.revision.{branch_rev}.{product}-l10n.{job-name}.{locale}", # noqa - too long
"index.{trust-domain}.v2.{project}.shippable.{build_date}.latest.{product}-l10n.{job-name}.{locale}", # noqa - too long
"index.{trust-domain}.v2.{project}.shippable.revision.{branch_rev}.{product}-l10n.{job-name}.{locale}", # noqa - too long
]
V2_L10N_TEMPLATES = [
"index.{trust-domain}.v2.{project}.revision.{branch_rev}.{product}-l10n.{job-name}.{locale}",
"index.{trust-domain}.v2.{project}.pushdate.{build_date_long}.{product}-l10n.{job-name}.{locale}", # noqa - too long
"index.{trust-domain}.v2.{project}.pushlog-id.{pushlog_id}.{product}-l10n.{job-name}.{locale}",
"index.{trust-domain}.v2.{project}.latest.{product}-l10n.{job-name}.{locale}",
]
# This index is specifically for builds that include geckoview releases,
# so we can hard-code the project to "geckoview"
V2_GECKOVIEW_RELEASE = "index.{trust-domain}.v2.{project}.geckoview-version.{geckoview-version}.{product}.{job-name}" # noqa - too long
# the roots of the treeherder routes
TREEHERDER_ROUTE_ROOT = "tc-treeherder"
def get_branch_rev(config):
return config.params[
"{}head_rev".format(config.graph_config["project-repo-param-prefix"])
]
def get_branch_git_rev(config):
return config.params[
"{}head_git_rev".format(config.graph_config["project-repo-param-prefix"])
]
def get_branch_repo(config):
return config.params[
"{}head_repository".format(
config.graph_config["project-repo-param-prefix"],
)
]
@memoize
def get_default_priority(graph_config, project):
return evaluate_keyed_by(
graph_config["task-priority"], "Graph Config", {"project": project}
)
# define a collection of index builders, depending on the type implementation
index_builders = {}
def index_builder(name):
def wrap(func):
assert name not in index_builders, f"duplicate index builder name {name}"
index_builders[name] = func
return func
return wrap
UNSUPPORTED_INDEX_PRODUCT_ERROR = """\
The gecko-v2 product {product} is not in the list of configured products in
`taskcluster/config.yml'.
"""
def verify_index(config, index):
product = index["product"]
if product not in config.graph_config["index"]["products"]:
raise Exception(UNSUPPORTED_INDEX_PRODUCT_ERROR.format(product=product))
RUN_TASK_RE = re.compile(r"run-task(-(git|hg))?$")
def is_run_task(cmd: str) -> bool:
return bool(re.search(RUN_TASK_RE, cmd))
@payload_builder(
"docker-worker",
schema={
Required("os"): "linux",
# For tasks that will run in docker-worker, this is the
# name of the docker image or in-tree docker image to run the task in. If
# in-tree, then a dependency will be created automatically. This is
# generally `desktop-test`, or an image that acts an awful lot like it.
Required("docker-image"): Any(
# a raw Docker image path (repo/image:tag)
str,
# an in-tree generated docker image (from `taskcluster/docker/<name>`)
{"in-tree": str},
# an indexed docker image
{"indexed": str},
),
# worker features that should be enabled
Required("chain-of-trust"): bool,
Required("taskcluster-proxy"): bool,
Required("allow-ptrace"): bool,
Required("loopback-video"): bool,
Required("loopback-audio"): bool,
Required("docker-in-docker"): bool, # (aka 'dind')
Required("privileged"): bool,
Optional("kvm"): bool,
# Paths to Docker volumes.
#
# For in-tree Docker images, volumes can be parsed from Dockerfile.
# This only works for the Dockerfile itself: if a volume is defined in
# a base image, it will need to be declared here. Out-of-tree Docker
# images will also require explicit volume annotation.
#
# Caches are often mounted to the same path as Docker volumes. In this
# case, they take precedence over a Docker volume. But a volume still
# needs to be declared for the path.
Optional("volumes"): [str],
Optional(
"required-volumes",
description=(
"Paths that are required to be volumes for performance reasons. "
"For in-tree images, these paths will be checked to verify that they "
"are defined as volumes."
),
): [str],
# caches to set up for the task
Optional("caches"): [
{
# only one type is supported by any of the workers right now
"type": "persistent",
# name of the cache, allowing re-use by subsequent tasks naming the
# same cache
"name": str,
# location in the task image where the cache will be mounted
"mount-point": str,
# Whether the cache is not used in untrusted environments
# (like the Try repo).
Optional("skip-untrusted"): bool,
}
],
# artifacts to extract from the task image after completion
Optional("artifacts"): [
{
# type of artifact -- simple file, or recursive directory
"type": Any("file", "directory"),
# task image path from which to read artifact
"path": str,
# name of the produced artifact (root of the names for
# type=directory)
"name": str,
"expires-after": str,
}
],
# environment variables
Required("env"): {str: taskref_or_string},
# the command to run; if not given, docker-worker will default to the
# command in the docker image
Optional("command"): [taskref_or_string],
# the maximum time to run, in seconds
Required("max-run-time"): int,
# the exit status code(s) that indicates the task should be retried
Optional("retry-exit-status"): [int],
# the exit status code(s) that indicates the caches used by the task
# should be purged
Optional("purge-caches-exit-status"): [int],
# Whether any artifacts are assigned to this worker
Optional("skip-artifacts"): bool,
},
)
def build_docker_worker_payload(config, task, task_def):
worker = task["worker"]
level = int(config.params["level"])
image = worker["docker-image"]
if isinstance(image, dict):
if "in-tree" in image:
name = image["in-tree"]
docker_image_task = "docker-image-" + image["in-tree"]
task.setdefault("dependencies", {})["docker-image"] = docker_image_task
image = {
"path": "public/image.tar.zst",
"taskId": {"task-reference": "<docker-image>"},
"type": "task-image",
}
# Find VOLUME in Dockerfile.
volumes = dockerutil.parse_volumes(name)
for v in sorted(volumes):
if v in worker["volumes"]:
raise Exception(
"volume %s already defined; "
"if it is defined in a Dockerfile, "
"it does not need to be specified in the "
"worker definition" % v
)
worker["volumes"].append(v)
elif "indexed" in image:
image = {
"path": "public/image.tar.zst",
"namespace": image["indexed"],
"type": "indexed-image",
}
else:
raise Exception("unknown docker image type")
features = {}
if worker.get("taskcluster-proxy"):
features["taskclusterProxy"] = True
if worker.get("allow-ptrace"):
features["allowPtrace"] = True
task_def["scopes"].append("docker-worker:feature:allowPtrace")
if worker.get("chain-of-trust"):
features["chainOfTrust"] = True
if worker.get("docker-in-docker"):
features["dind"] = True
# Never enable sccache on the toolchains repo, as there is no benefit from it
# because each push uses a different compiler.
if task.get("use-sccache") and config.params["project"] != "toolchains":
features["taskclusterProxy"] = True
task_def["scopes"].append(
"assume:project:taskcluster:{trust_domain}:level-{level}-sccache-buckets".format(
trust_domain=config.graph_config["trust-domain"],
level=config.params["level"],
)
)
worker["env"]["USE_SCCACHE"] = "1"
worker["env"]["SCCACHE_GCS_PROJECT"] = SCCACHE_GCS_PROJECT
# Disable sccache idle shutdown.
worker["env"]["SCCACHE_IDLE_TIMEOUT"] = "0"
else:
worker["env"]["SCCACHE_DISABLE"] = "1"
capabilities = {}
for lo in "audio", "video":
if worker.get("loopback-" + lo):
capitalized = "loopback" + lo.capitalize()
devices = capabilities.setdefault("devices", {})
devices[capitalized] = True
task_def["scopes"].append("docker-worker:capability:device:" + capitalized)
if worker.get("kvm"):
devices = capabilities.setdefault("devices", {})
devices["kvm"] = True
task_def["scopes"].append("docker-worker:capability:device:kvm")
if worker.get("privileged"):
capabilities["privileged"] = True
task_def["scopes"].append("docker-worker:capability:privileged")
task_def["payload"] = payload = {
"image": image,
"env": worker["env"],
}
if "command" in worker:
payload["command"] = worker["command"]
if "max-run-time" in worker:
payload["maxRunTime"] = worker["max-run-time"]
run_task = is_run_task(payload.get("command", [""])[0])
# run-task exits EXIT_PURGE_CACHES if there is a problem with caches.
# Automatically retry the tasks and purge caches if we see this exit
# code.
# TODO move this closer to code adding run-task once bug 1469697 is
# addressed.
if run_task:
worker.setdefault("retry-exit-status", []).append(72)
worker.setdefault("purge-caches-exit-status", []).append(72)
payload["onExitStatus"] = {}
if "retry-exit-status" in worker:
payload["onExitStatus"]["retry"] = worker["retry-exit-status"]
if "purge-caches-exit-status" in worker:
payload["onExitStatus"]["purgeCaches"] = worker["purge-caches-exit-status"]
if "artifacts" in worker:
artifacts = {}
for artifact in worker["artifacts"]:
artifacts[artifact["name"]] = {
"path": artifact["path"],
"type": artifact["type"],
"expires": {"relative-datestamp": artifact["expires-after"]},
}
payload["artifacts"] = artifacts
if isinstance(worker.get("docker-image"), str):
out_of_tree_image = worker["docker-image"]
else:
out_of_tree_image = None
image = worker.get("docker-image", {}).get("in-tree")
if "caches" in worker:
caches = {}
# run-task knows how to validate caches.
#
# To help ensure new run-task features and bug fixes don't interfere
# with existing caches, we seed the hash of run-task into cache names.
# So, any time run-task changes, we should get a fresh set of caches.
# This means run-task can make changes to cache interaction at any time
# without regards for backwards or future compatibility.
#
# But this mechanism only works for in-tree Docker images that are built
# with the current run-task! For out-of-tree Docker images, we have no
# way of knowing their content of run-task. So, in addition to varying
# cache names by the contents of run-task, we also take the Docker image
# name into consideration. This means that different Docker images will
# never share the same cache. This is a bit unfortunate. But it is the
# safest thing to do. Fortunately, most images are defined in-tree.
#
# For out-of-tree Docker images, we don't strictly need to incorporate
# the run-task content into the cache name. However, doing so preserves
# the mechanism whereby changing run-task results in new caches
# everywhere.
# As an additional mechanism to force the use of different caches, the
# string literal in the variable below can be changed. This is
# preferred to changing run-task because it doesn't require images
# to be rebuilt.
cache_version = "v3"
if run_task:
suffix = (
f"{cache_version}-{_run_task_suffix(config.params['repository_type'])}"
)
if out_of_tree_image:
name_hash = hashlib.sha256(
out_of_tree_image.encode("utf-8")
).hexdigest()
suffix += name_hash[0:12]
else:
suffix = cache_version
skip_untrusted = is_try(config.params) or level == 1
for cache in worker["caches"]:
# Some caches aren't enabled in environments where we can't
# guarantee certain behavior. Filter those out.
if cache.get("skip-untrusted") and skip_untrusted:
continue
name = "{trust_domain}-level-{level}-{name}-{suffix}".format(
trust_domain=config.graph_config["trust-domain"],
level=config.params["level"],
name=cache["name"],
suffix=suffix,
)
caches[name] = cache["mount-point"]
task_def["scopes"].append("docker-worker:cache:%s" % name)
# Assertion: only run-task is interested in this.
if run_task:
payload["env"]["TASKCLUSTER_CACHES"] = ";".join(sorted(caches.values()))
payload["cache"] = caches
# And send down volumes information to run-task as well.
if run_task and worker.get("volumes"):
payload["env"]["TASKCLUSTER_VOLUMES"] = ";".join(sorted(worker["volumes"]))
if payload.get("cache") and skip_untrusted:
payload["env"]["TASKCLUSTER_UNTRUSTED_CACHES"] = "1"
if features:
payload["features"] = features
if capabilities:
payload["capabilities"] = capabilities
check_caches_are_volumes(task)
check_required_volumes(task)
@payload_builder(
"generic-worker",
schema={
Required("os"): Any(
"windows", "macosx", "linux", "linux-bitbar", "linux-lambda"
),
# see http://schemas.taskcluster.net/generic-worker/v1/payload.json
# and https://docs.taskcluster.net/reference/workers/generic-worker/payload
# command is a list of commands to run, sequentially
# on Windows, each command is a string, on OS X and Linux, each command is
# a string array
Required("command"): Any(
[taskref_or_string], [[taskref_or_string]] # Windows # Linux / OS X
),
# artifacts to extract from the task image after completion; note that artifacts
# for the generic worker cannot have names
Optional("artifacts"): [
{
# type of artifact -- simple file, or recursive directory
"type": Any("file", "directory"),
# filesystem path from which to read artifact
"path": str,
# if not specified, path is used for artifact name
Optional("name"): str,
"expires-after": str,
}
],
# Directories and/or files to be mounted.
# The actual allowed combinations are stricter than the model below,
# but this provides a simple starting point.
# See https://docs.taskcluster.net/reference/workers/generic-worker/payload
Optional("mounts"): [
{
# A unique name for the cache volume, implies writable cache directory
# (otherwise mount is a read-only file or directory).
Optional("cache-name"): str,
# Optional content for pre-loading cache, or mandatory content for
# read-only file or directory. Pre-loaded content can come from either
# a task artifact or from a URL.
Optional("content"): {
# *** Either (artifact and task-id) or url must be specified. ***
# Artifact name that contains the content.
Optional("artifact"): str,
# Task ID that has the artifact that contains the content.
Optional("task-id"): taskref_or_string,
# URL that supplies the content in response to an unauthenticated
# GET request.
Optional("url"): str,
},
# *** Either file or directory must be specified. ***
# If mounting a cache or read-only directory, the filesystem location of
# the directory should be specified as a relative path to the task
# directory here.
Optional("directory"): str,
# If mounting a file, specify the relative path within the task
# directory to mount the file (the file will be read only).
Optional("file"): str,
# Required if and only if `content` is specified and mounting a
# directory (not a file). This should be the archive format of the
# content (either pre-loaded cache or read-only directory).
Optional("format"): Any("rar", "tar.bz2", "tar.gz", "zip", "tar.xz"),
}
],
# environment variables
Required("env"): {str: taskref_or_string},
# the maximum time to run, in seconds
Required("max-run-time"): int,
# os user groups for test task workers
Optional("os-groups"): [str],
# feature for test task to run as administarotr
Optional("run-as-administrator"): bool,
# optional features
Required("chain-of-trust"): bool,
Optional("taskcluster-proxy"): bool,
# the exit status code(s) that indicates the task should be retried
Optional("retry-exit-status"): [int],
# Wether any artifacts are assigned to this worker
Optional("skip-artifacts"): bool,
},
)
def build_generic_worker_payload(config, task, task_def):
worker = task["worker"]
features = {}
task_def["payload"] = {
"command": worker["command"],
"maxRunTime": worker["max-run-time"],
}
if worker["os"] == "windows":
task_def["payload"]["onExitStatus"] = {
"retry": [
# These codes (on windows) indicate a process interruption,
# rather than a task run failure. See bug 1544403.
1073807364, # process force-killed due to system shutdown
3221225786, # sigint (any interrupt)
]
}
if "retry-exit-status" in worker:
task_def["payload"].setdefault("onExitStatus", {}).setdefault(
"retry", []
).extend(worker["retry-exit-status"])
if worker["os"] in ["linux-bitbar", "linux-lambda"]:
task_def["payload"].setdefault("onExitStatus", {}).setdefault("retry", [])
# exit code 4 is used to indicate an intermittent android device error
if 4 not in task_def["payload"]["onExitStatus"]["retry"]:
task_def["payload"]["onExitStatus"]["retry"].extend([4])
env = worker.get("env", {})
# Never enable sccache on the toolchains repo, as there is no benefit from it
# because each push uses a different compiler.
if task.get("use-sccache") and config.params["project"] != "toolchains":
features["taskclusterProxy"] = True
task_def["scopes"].append(
"assume:project:taskcluster:{trust_domain}:level-{level}-sccache-buckets".format(
trust_domain=config.graph_config["trust-domain"],
level=config.params["level"],
)
)
env["USE_SCCACHE"] = "1"
worker["env"]["SCCACHE_GCS_PROJECT"] = SCCACHE_GCS_PROJECT
# Disable sccache idle shutdown.
env["SCCACHE_IDLE_TIMEOUT"] = "0"
else:
env["SCCACHE_DISABLE"] = "1"
if env:
task_def["payload"]["env"] = env
artifacts = []
for artifact in worker.get("artifacts", []):
a = {
"path": artifact["path"],
"type": artifact["type"],
"expires": {"relative-datestamp": artifact["expires-after"]},
}
if "name" in artifact:
a["name"] = artifact["name"]
artifacts.append(a)
if artifacts:
task_def["payload"]["artifacts"] = artifacts
# Need to copy over mounts, but rename keys to respect naming convention
# * 'cache-name' -> 'cacheName'
# * 'task-id' -> 'taskId'
# All other key names are already suitable, and don't need renaming.
mounts = deepcopy(worker.get("mounts", []))
for mount in mounts:
if "cache-name" in mount:
mount["cacheName"] = "{trust_domain}-level-{level}-{name}".format(
trust_domain=config.graph_config["trust-domain"],
level=config.params["level"],
name=mount.pop("cache-name"),
)
task_def["scopes"].append(
"generic-worker:cache:{}".format(mount["cacheName"])
)
if "content" in mount:
if "task-id" in mount["content"]:
mount["content"]["taskId"] = mount["content"].pop("task-id")
if "artifact" in mount["content"]:
if not mount["content"]["artifact"].startswith("public/"):
task_def["scopes"].append(
"queue:get-artifact:{}".format(mount["content"]["artifact"])
)
if mounts:
task_def["payload"]["mounts"] = mounts
if worker.get("os-groups"):
task_def["payload"]["osGroups"] = worker["os-groups"]
task_def["scopes"].extend(
[
"generic-worker:os-group:{}/{}".format(task["worker-type"], group)
for group in worker["os-groups"]
]
)
if worker.get("chain-of-trust"):
features["chainOfTrust"] = True
if worker.get("taskcluster-proxy"):
features["taskclusterProxy"] = True
if worker.get("run-as-administrator", False):
features["runAsAdministrator"] = True
task_def["scopes"].append(
"generic-worker:run-as-administrator:{}".format(task["worker-type"]),
)
if features:
task_def["payload"]["features"] = features
@payload_builder(
"iscript",
schema={
Required("signing-type"): str,
# the maximum time to run, in seconds
Required("max-run-time"): int,
# list of artifact URLs for the artifacts that should be signed
Required("upstream-artifacts"): [
{
# taskId of the task with the artifact
Required("taskId"): taskref_or_string,
# type of signing task (for CoT)
Required("taskType"): str,
# Paths to the artifacts to sign
Required("paths"): [str],
# Signing formats to use on each of the paths
Required("formats"): [str],
Optional("singleFileGlobs"): [str],
}
],
# behavior for mac iscript
Optional("mac-behavior"): Any(
"apple_notarization",
"apple_notarization_stacked",
"mac_sign_and_pkg",
"mac_sign_and_pkg_hardened",
"mac_geckodriver",
"mac_notarize_geckodriver",
"mac_single_file",
"mac_notarize_single_file",
),
Optional("entitlements-url"): str,
Optional("requirements-plist-url"): str,
Optional("provisioning-profile-config"): [
{
Required("profile_name"): str,
Required("target_path"): str,
}
],
Optional("hardened-sign-config"): [
{
Optional("deep"): bool,
Optional("runtime"): bool,
Optional("force"): bool,
Optional("entitlements"): str,
Optional("requirements"): str,
Required("globs"): [str],
}
],
},
)
def build_iscript_payload(config, task, task_def):
worker = task["worker"]
task_def["payload"] = {
"maxRunTime": worker["max-run-time"],
"upstreamArtifacts": worker["upstream-artifacts"],
}
if worker.get("mac-behavior"):
task_def["payload"]["behavior"] = worker["mac-behavior"]
for attribute in (
"entitlements-url",
"requirements-plist-url",
"hardened-sign-config",
"provisioning-profile-config",
):
if worker.get(attribute):
task_def["payload"][attribute] = worker[attribute]
# Set scopes
scope_prefix = config.graph_config["scriptworker"]["scope-prefix"]
scopes = set(task_def.get("scopes", []))
scopes.add(f"{scope_prefix}:signing:cert:{worker['signing-type']}")
task_def["scopes"] = sorted(scopes)
artifacts = set(task.setdefault("attributes", {}).get("release_artifacts", []))
for upstream_artifact in worker["upstream-artifacts"]:
for path in upstream_artifact["paths"]:
artifacts.update(
get_signed_artifacts(
input=path,
formats=upstream_artifact["formats"],
behavior=worker.get("mac-behavior"),
)
)
task["attributes"]["release_artifacts"] = sorted(list(artifacts))
@payload_builder(
"beetmover",
schema={
# the maximum time to run, in seconds
Optional("max-run-time"): int,
# locale key, if this is a locale beetmover job
Optional("locale"): str,
Required("release-properties"): {
"app-name": str,
"app-version": str,
"branch": str,
"build-id": str,
"hash-type": str,
"platform": str,
},
# list of artifact URLs for the artifacts that should be beetmoved
Required("upstream-artifacts"): [
{
# taskId of the task with the artifact
Required("taskId"): taskref_or_string,
# type of signing task (for CoT)
Required("taskType"): str,
# Paths to the artifacts to sign
Required("paths"): [str],
# locale is used to map upload path and allow for duplicate simple names
Required("locale"): str,
}
],
Optional("artifact-map"): object,
},
)
def build_beetmover_payload(config, task, task_def):
worker = task["worker"]
release_config = get_release_config(config)
release_properties = worker["release-properties"]
task_def["payload"] = {
"releaseProperties": {
"appName": release_properties["app-name"],
"appVersion": release_properties["app-version"],
"branch": release_properties["branch"],
"buildid": release_properties["build-id"],
"hashType": release_properties["hash-type"],
"platform": release_properties["platform"],
},
"upload_date": config.params["build_date"],
"upstreamArtifacts": worker["upstream-artifacts"],
}
if worker.get("locale"):
task_def["payload"]["locale"] = worker["locale"]
if worker.get("artifact-map"):
task_def["payload"]["artifactMap"] = worker["artifact-map"]
if release_config:
task_def["payload"].update(release_config)
@payload_builder(
"beetmover-push-to-release",
schema={
# the maximum time to run, in seconds
Optional("max-run-time"): int,
Required("product"): str,
},
)
def build_beetmover_push_to_release_payload(config, task, task_def):
worker = task["worker"]
release_config = get_release_config(config)
partners = [f"{p}/{s}" for p, s, _ in get_partners_to_be_published(config)]
task_def["payload"] = {
"product": worker["product"],
"version": release_config["version"],
"build_number": release_config["build_number"],
"partners": partners,
}
@payload_builder(
"beetmover-import-from-gcs-to-artifact-registry",
schema={
Optional("max-run-time"): int,
Required("gcs-sources"): [str],
Required("product"): str,
},
)
def build_import_from_gcs_to_artifact_registry_payload(config, task, task_def):
task_def["payload"] = {
"product": task["worker"]["product"],
"gcs_sources": task["worker"]["gcs-sources"],
}
@payload_builder(
"beetmover-maven",
schema={
Optional("max-run-time"): int,
Required("release-properties"): {
"app-name": str,
"app-version": str,
"branch": str,
"build-id": str,
"artifact-id": str,
"hash-type": str,
"platform": str,
},
Required("upstream-artifacts"): [
{
Required("taskId"): taskref_or_string,
Required("taskType"): str,
Required("paths"): [str],
Optional("zipExtract"): bool,
}
],
Optional("artifact-map"): object,
},
)
def build_beetmover_maven_payload(config, task, task_def):
build_beetmover_payload(config, task, task_def)
task_def["payload"]["artifact_id"] = task["worker"]["release-properties"][
"artifact-id"
]
if task["worker"].get("artifact-map"):
task_def["payload"]["artifactMap"] = task["worker"]["artifact-map"]
task_def["payload"]["version"] = _compute_geckoview_version(
task["worker"]["release-properties"]["app-version"],
task["worker"]["release-properties"]["build-id"],
)
del task_def["payload"]["releaseProperties"]["hashType"]
del task_def["payload"]["releaseProperties"]["platform"]
@payload_builder(
"balrog",
schema={
Required("balrog-action"): Any(*BALROG_ACTIONS),
Optional("product"): str,
Optional("platforms"): [str],
Optional("release-eta"): str,
Optional("channel-names"): optionally_keyed_by("release-type", [str]),
Optional("require-mirrors"): bool,
Optional("publish-rules"): optionally_keyed_by(
"release-type", "release-level", [int]
),
Optional("rules-to-update"): optionally_keyed_by(
"release-type", "release-level", [str]
),
Optional("archive-domain"): optionally_keyed_by("release-level", str),
Optional("download-domain"): optionally_keyed_by("release-level", str),
Optional("blob-suffix"): str,
Optional("complete-mar-filename-pattern"): str,
Optional("complete-mar-bouncer-product-pattern"): str,
Optional("update-line"): object,
Optional("suffixes"): [str],
Optional("background-rate"): optionally_keyed_by(
"release-type", "beta-number", Any(int, None)
),
Optional("force-fallback-mapping-update"): optionally_keyed_by(
"release-type", "beta-number", bool
),
Optional("pin-channels"): optionally_keyed_by(
"release-type", "release-level", [str]
),
# list of artifact URLs for the artifacts that should be beetmoved
Optional("upstream-artifacts"): [
{
# taskId of the task with the artifact
Required("taskId"): taskref_or_string,
# type of signing task (for CoT)
Required("taskType"): str,
# Paths to the artifacts to sign
Required("paths"): [str],
}
],
},
)
def build_balrog_payload(config, task, task_def):
worker = task["worker"]
release_config = get_release_config(config)
beta_number = None
if "b" in release_config["version"]:
beta_number = release_config["version"].split("b")[-1]
task_def["payload"] = {
"behavior": worker["balrog-action"],
}
if (
worker["balrog-action"] == "submit-locale"
or worker["balrog-action"] == "v2-submit-locale"
):
task_def["payload"].update(
{
"upstreamArtifacts": worker["upstream-artifacts"],
"suffixes": worker["suffixes"],
}
)
else:
for prop in (
"archive-domain",
"channel-names",
"download-domain",
"publish-rules",
"rules-to-update",
"background-rate",
"force-fallback-mapping-update",
"pin-channels",
):
if prop in worker:
resolve_keyed_by(
worker,
prop,
task["description"],
**{
"release-type": config.params["release_type"],
"release-level": release_level(config.params["project"]),
"beta-number": beta_number,
},
)
task_def["payload"].update(
{
"build_number": release_config["build_number"],
"product": worker["product"],
"version": release_config["version"],
}
)
for prop in (
"blob-suffix",
"complete-mar-filename-pattern",
"complete-mar-bouncer-product-pattern",
"pin-channels",
):
if prop in worker:
task_def["payload"][prop.replace("-", "_")] = worker[prop]
if (
worker["balrog-action"] == "submit-toplevel"
or worker["balrog-action"] == "v2-submit-toplevel"
):
task_def["payload"].update(
{
"app_version": release_config["appVersion"],
"archive_domain": worker["archive-domain"],
"channel_names": worker["channel-names"],
"download_domain": worker["download-domain"],
"partial_versions": release_config.get("partial_versions", ""),
"platforms": worker["platforms"],
"rules_to_update": worker["rules-to-update"],
"require_mirrors": worker["require-mirrors"],
"update_line": worker["update-line"],
}
)
else: # schedule / ship
task_def["payload"].update(
{
"publish_rules": worker["publish-rules"],
"release_eta": worker.get(
"release-eta", config.params.get("release_eta")
)
or "",
}
)
if worker.get("force-fallback-mapping-update"):
task_def["payload"]["force_fallback_mapping_update"] = worker[
"force-fallback-mapping-update"
]
if worker.get("background-rate"):
task_def["payload"]["background_rate"] = worker["background-rate"]
@payload_builder(
"bouncer-aliases",
schema={
Required("entries"): object,
},
)
def build_bouncer_aliases_payload(config, task, task_def):
worker = task["worker"]
task_def["payload"] = {"aliases_entries": worker["entries"]}
@payload_builder(
"bouncer-locations",
schema={
Required("implementation"): "bouncer-locations",
Required("bouncer-products"): [str],
},
)
def build_bouncer_locations_payload(config, task, task_def):
worker = task["worker"]
release_config = get_release_config(config)
task_def["payload"] = {
"bouncer_products": worker["bouncer-products"],
"version": release_config["version"],
"product": task["shipping-product"],
}
@payload_builder(
"bouncer-submission",
schema={
Required("locales"): [str],
Required("entries"): object,
},
)
def build_bouncer_submission_payload(config, task, task_def):
worker = task["worker"]
task_def["payload"] = {
"locales": worker["locales"],
"submission_entries": worker["entries"],
}
@payload_builder(
"push-flatpak",
schema={
Required("channel"): str,
Required("upstream-artifacts"): [
{
Required("taskId"): taskref_or_string,
Required("taskType"): str,
Required("paths"): [str],
}
],
},
)
def build_push_flatpak_payload(config, task, task_def):
worker = task["worker"]
task_def["payload"] = {
"channel": worker["channel"],
"upstreamArtifacts": worker["upstream-artifacts"],
}
@payload_builder(
"push-msix",
schema={
Required("channel"): str,
Optional("publish-mode"): str,
Required("upstream-artifacts"): [
{
Required("taskId"): taskref_or_string,
Required("taskType"): str,
Required("paths"): [str],
}
],
},
)
def build_push_msix_payload(config, task, task_def):
worker = task["worker"]
task_def["payload"] = {
"channel": worker["channel"],
"upstreamArtifacts": worker["upstream-artifacts"],
}
if worker.get("publish-mode"):
task_def["payload"]["publishMode"] = worker["publish-mode"]
@payload_builder(
"shipit-update-product-channel-version",
schema={
Required("product"): str,
Required("channel"): str,
Required("version"): str,
},
)
def build_ship_it_update_product_channel_version_payload(config, task, task_def):
worker = task["worker"]
task_def["payload"] = {
"product": worker["product"],
"version": worker["version"],
"channel": worker["channel"],
}
@payload_builder(
"shipit-shipped",
schema={
Required("release-name"): str,
},
)
def build_ship_it_shipped_payload(config, task, task_def):
worker = task["worker"]
task_def["payload"] = {"release_name": worker["release-name"]}
@payload_builder(
"shipit-maybe-release",
schema={
Required("phase"): str,
},
)
def build_ship_it_maybe_release_payload(config, task, task_def):
# expect branch name, including path
branch = config.params["head_repository"][len("https://hg.mozilla.org/") :]
# 'version' is e.g. '71.0b13' (app_version doesn't have beta number)
version = config.params["version"]
task_def["payload"] = {
"product": task["shipping-product"],
"branch": branch,
"phase": task["worker"]["phase"],
"version": version,
"cron_revision": config.params["head_rev"],
}
@payload_builder(
"push-addons",
schema={
Required("channel"): Any("listed", "unlisted"),
Required("upstream-artifacts"): [
{
Required("taskId"): taskref_or_string,
Required("taskType"): str,
Required("paths"): [str],
}
],
},
)
def build_push_addons_payload(config, task, task_def):
worker = task["worker"]
task_def["payload"] = {
"channel": worker["channel"],
"upstreamArtifacts": worker["upstream-artifacts"],
}
@payload_builder(
"treescript",
schema={
Required("tags"): [Any("buildN", "release", None)],
Required("bump"): bool,
Optional("bump-files"): [str],
Optional("repo-param-prefix"): str,
Optional("dontbuild"): bool,
Optional("ignore-closed-tree"): bool,
Optional("force-dry-run"): bool,
Optional("push"): bool,
Optional("source-repo"): str,
Optional("ssh-user"): str,
Optional("l10n-bump-info"): [
{
Required("name"): str,
Required("path"): str,
Required("version-path"): str,
Optional("l10n-repo-url"): str,
Optional("l10n-repo-target-branch"): str,
Optional("ignore-config"): object,
Required("platform-configs"): [
{
Required("platforms"): [str],
Required("path"): str,
Optional("format"): str,
}
],
}
],
Optional("actions"): object,
Optional("merge-info"): object,
Optional("android-l10n-import-info"): {
Required("from-repo-url"): str,
Required("toml-info"): [
{
Required("toml-path"): str,
Required("dest-path"): str,
}
],
},
Optional("android-l10n-sync-info"): {
Required("from-repo-url"): str,
Required("toml-info"): [
{
Required("toml-path"): str,
}
],
},
},
)
def build_treescript_payload(config, task, task_def):
worker = task["worker"]
release_config = get_release_config(config)
task_def["payload"] = {"actions": []}
actions = task_def["payload"]["actions"]
if worker["tags"]:
tag_names = []
product = task["shipping-product"].upper()
version = release_config["version"].replace(".", "_")
buildnum = release_config["build_number"]
if "buildN" in worker["tags"]:
tag_names.extend(
[
f"{product}_{version}_BUILD{buildnum}",
]
)
if "release" in worker["tags"]:
tag_names.extend([f"{product}_{version}_RELEASE"])
tag_info = {
"tags": tag_names,
"revision": config.params[
"{}head_rev".format(worker.get("repo-param-prefix", ""))
],
}
task_def["payload"]["tag_info"] = tag_info
actions.append("tag")
if worker["bump"]:
if not worker["bump-files"]:
raise Exception("Version Bump requested without bump-files")
bump_info = {}
bump_info["next_version"] = release_config["next_version"]
bump_info["files"] = worker["bump-files"]
task_def["payload"]["version_bump_info"] = bump_info
actions.append("version_bump")
if worker.get("l10n-bump-info"):
l10n_bump_info = []
l10n_repo_urls = set()
for lbi in worker["l10n-bump-info"]:
new_lbi = {}
if "l10n-repo-url" in lbi:
l10n_repo_urls.add(lbi["l10n-repo-url"])
for k, v in lbi.items():
new_lbi[k.replace("-", "_")] = lbi[k]
l10n_bump_info.append(new_lbi)
task_def["payload"]["l10n_bump_info"] = l10n_bump_info
if len(l10n_repo_urls) > 1:
raise Exception(
"Must use the same l10n-repo-url for all files in the same task!"
)
elif len(l10n_repo_urls) == 1:
if "github.com" in l10n_repo_urls.pop():
actions.append("l10n_bump_github")
else:
actions.append("l10n_bump")
if worker.get("merge-info"):
merge_info = {
merge_param_name.replace("-", "_"): merge_param_value
for merge_param_name, merge_param_value in worker["merge-info"].items()
if merge_param_name != "version-files"
}
merge_info["version_files"] = [
{
file_param_name.replace("-", "_"): file_param_value
for file_param_name, file_param_value in file_entry.items()
}
for file_entry in worker["merge-info"]["version-files"]
]
task_def["payload"]["merge_info"] = merge_info
actions.append("merge_day")
if worker.get("android-l10n-import-info"):
android_l10n_import_info = {}
for k, v in worker["android-l10n-import-info"].items():
android_l10n_import_info[k.replace("-", "_")] = worker[
"android-l10n-import-info"
][k]
android_l10n_import_info["toml_info"] = [
{
param_name.replace("-", "_"): param_value
for param_name, param_value in entry.items()
}
for entry in worker["android-l10n-import-info"]["toml-info"]
]
task_def["payload"]["android_l10n_import_info"] = android_l10n_import_info
actions.append("android_l10n_import")
if worker.get("android-l10n-sync-info"):
android_l10n_sync_info = {}
for k, v in worker["android-l10n-sync-info"].items():
android_l10n_sync_info[k.replace("-", "_")] = worker[
"android-l10n-sync-info"
][k]
android_l10n_sync_info["toml_info"] = [
{
param_name.replace("-", "_"): param_value
for param_name, param_value in entry.items()
}
for entry in worker["android-l10n-sync-info"]["toml-info"]
]
task_def["payload"]["android_l10n_sync_info"] = android_l10n_sync_info
actions.append("android_l10n_sync")
if worker["push"]:
actions.append("push")
if worker.get("force-dry-run"):
task_def["payload"]["dry_run"] = True
if worker.get("dontbuild"):
task_def["payload"]["dontbuild"] = True
if worker.get("ignore-closed-tree") is not None:
task_def["payload"]["ignore_closed_tree"] = worker["ignore-closed-tree"]
if worker.get("source-repo"):
task_def["payload"]["source_repo"] = worker["source-repo"]
if worker.get("ssh-user"):
task_def["payload"]["ssh_user"] = worker["ssh-user"]
@payload_builder(
"landoscript",
schema={
Required("lando-repo"): str,
Optional("hg-repo-url"): str,
Optional("ignore-closed-tree"): bool,
Optional("dontbuild"): bool,
Optional("tags"): [Any("buildN", "release", None)],
Optional("force-dry-run"): bool,
Optional("push"): bool,
Optional("android-l10n-import-info"): {
Required("from-repo-url"): str,
Required("toml-info"): [
{
Required("toml-path"): str,
Required("dest-path"): str,
}
],
},
Optional("android-l10n-sync-info"): {
Required("from-branch"): str,
Required("toml-info"): [
{
Required("toml-path"): str,
}
],
},
Optional("l10n-bump-info"): [
{
Required("name"): str,
Required("path"): str,
Optional("l10n-repo-url"): str,
Optional("l10n-repo-target-branch"): str,
Optional("ignore-config"): object,
Required("platform-configs"): [
{
Required("platforms"): [str],
Required("path"): str,
Optional("format"): str,
}
],
}
],
Optional("bump-files"): [str],
Optional("merge-info"): object,
},
)
def build_landoscript_payload(config, task, task_def):
worker = task["worker"]
release_config = get_release_config(config)
task_def["payload"] = {"actions": [], "lando_repo": worker["lando-repo"]}
actions = task_def["payload"]["actions"]
if worker.get("ignore-closed-tree") is not None:
task_def["payload"]["ignore_closed_tree"] = worker["ignore-closed-tree"]
if worker.get("dontbuild"):
task_def["payload"]["dontbuild"] = True
if worker.get("force-dry-run"):
task_def["payload"]["dry_run"] = True
if worker.get("android-l10n-import-info"):
android_l10n_import_info = {}
for k, v in worker["android-l10n-import-info"].items():
android_l10n_import_info[k.replace("-", "_")] = worker[
"android-l10n-import-info"
][k]
android_l10n_import_info["toml_info"] = [
{
param_name.replace("-", "_"): param_value
for param_name, param_value in entry.items()
}
for entry in worker["android-l10n-import-info"]["toml-info"]
]
task_def["payload"]["android_l10n_import_info"] = android_l10n_import_info
actions.append("android_l10n_import")
if worker.get("android-l10n-sync-info"):
android_l10n_sync_info = {}
for k, v in worker["android-l10n-sync-info"].items():
android_l10n_sync_info[k.replace("-", "_")] = worker[
"android-l10n-sync-info"
][k]
android_l10n_sync_info["toml_info"] = [
{
param_name.replace("-", "_"): param_value
for param_name, param_value in entry.items()
}
for entry in worker["android-l10n-sync-info"]["toml-info"]
]
task_def["payload"]["android_l10n_sync_info"] = android_l10n_sync_info
actions.append("android_l10n_sync")
if worker.get("l10n-bump-info"):
l10n_bump_info = []
l10n_repo_urls = set()
for lbi in worker["l10n-bump-info"]:
new_lbi = {}
if "l10n-repo-url" in lbi:
l10n_repo_urls.add(lbi["l10n-repo-url"])
for k, v in lbi.items():
new_lbi[k.replace("-", "_")] = lbi[k]
l10n_bump_info.append(new_lbi)
task_def["payload"]["l10n_bump_info"] = l10n_bump_info
if len(l10n_repo_urls) > 1:
raise Exception(
"Must use the same l10n-repo-url for all files in the same task!"
)
elif len(l10n_repo_urls) == 1:
actions.append("l10n_bump")
if worker.get("tags"):
tag_names = []
product = task["shipping-product"].upper()
version = release_config["version"].replace(".", "_")
buildnum = release_config["build_number"]
if "buildN" in worker["tags"]:
tag_names.extend(
[
f"{product}_{version}_BUILD{buildnum}",
]
)
if "release" in worker["tags"]:
tag_names.extend([f"{product}_{version}_RELEASE"])
tag_info = {
"tags": tag_names,
"hg_repo_url": worker["hg-repo-url"],
"revision": config.params[
"{}head_rev".format(worker.get("repo-param-prefix", ""))
],
}
task_def["payload"]["tag_info"] = tag_info
actions.append("tag")
if worker.get("bump-files"):
bump_info = {}
bump_info["next_version"] = release_config["next_version"]
bump_info["files"] = worker["bump-files"]
task_def["payload"]["version_bump_info"] = bump_info
actions.append("version_bump")
if worker.get("merge-info"):
merge_info = {
merge_param_name.replace("-", "_"): merge_param_value
for merge_param_name, merge_param_value in worker["merge-info"].items()
if merge_param_name != "version-files"
}
merge_info["version_files"] = [
{
file_param_name.replace("-", "_"): file_param_value
for file_param_name, file_param_value in file_entry.items()
}
for file_entry in worker["merge-info"]["version-files"]
]
# hack alert: co-opt the l10n_bump_info into the merge_info section
# this should be cleaned up to avoid l10n_bump_info ever existing
# in the payload
if task_def["payload"].get("l10n_bump_info"):
actions.remove("l10n_bump")
merge_info["l10n_bump_info"] = task_def["payload"].pop("l10n_bump_info")
task_def["payload"]["merge_info"] = merge_info
actions.append("merge_day")
scopes = set(task_def.get("scopes", []))
scopes.add(f"project:releng:lando:repo:{worker['lando-repo']}")
scopes.update([f"project:releng:lando:action:{action}" for action in actions])
task_def["scopes"] = sorted(scopes)
transforms = TransformSequence()
@transforms.add
def set_implementation(config, tasks):
"""
Set the worker implementation based on the worker-type alias.
"""
for task in tasks:
default_worker_implementation, default_os = worker_type_implementation(
config.graph_config, config.params, task["worker-type"]
)
worker = task.setdefault("worker", {})
tags = task.setdefault("tags", {})
worker_implementation = worker.get(
"implementation", default_worker_implementation
)
tag_worker_implementation = _get_worker_implementation_tag(
config, task["worker-type"], worker_implementation
)
if worker_implementation:
worker["implementation"] = worker_implementation
tags["worker-implementation"] = tag_worker_implementation
os = worker.get("os", default_os)
if os:
tags["os"] = os
worker["os"] = os
yield task
def _get_worker_implementation_tag(config, task_worker_type, worker_implementation):
# Scriptworkers have different types of payload and each sets its own
# worker-implementation. Per bug 1955941, we want to bundle them all in one category
# through their tags.
provisioner_id, _ = get_worker_type(
config.graph_config,
config.params,
task_worker_type,
)
if provisioner_id in ("scriptworker-k8s", "scriptworker-prov-v1"):
return "scriptworker"
return worker_implementation
@transforms.add
def set_defaults(config, tasks):
for task in tasks:
task.setdefault("shipping-phase", None)
task.setdefault("shipping-product", None)
task.setdefault("always-target", False)
task.setdefault("optimization", None)
task.setdefault("use-sccache", False)
worker = task["worker"]
if worker["implementation"] in ("docker-worker",):
worker.setdefault("chain-of-trust", False)
worker.setdefault("taskcluster-proxy", False)
worker.setdefault("allow-ptrace", True)
worker.setdefault("loopback-video", False)
worker.setdefault("loopback-audio", False)
worker.setdefault("docker-in-docker", False)
worker.setdefault("privileged", False)
worker.setdefault("volumes", [])
worker.setdefault("env", {})
if "caches" in worker:
for c in worker["caches"]:
c.setdefault("skip-untrusted", False)
elif worker["implementation"] == "generic-worker":
worker.setdefault("env", {})
worker.setdefault("os-groups", [])
if worker["os-groups"] and worker["os"] not in (
"windows",
"linux",
):
raise Exception(
"os-groups feature of generic-worker is only supported on "
"Windows and Linux, not on {}".format(worker["os"])
)
worker.setdefault("chain-of-trust", False)
elif worker["implementation"] in ("iscript",):
worker.setdefault("max-run-time", 600)
elif worker["implementation"] == "push-apk":
worker.setdefault("commit", False)
yield task
@transforms.add
def setup_raptor(config, tasks):
"""Add options that are specific to raptor jobs (identified by suite=raptor).
This variant uses a separate set of transforms for manipulating the tests at the
task-level. Currently only used for setting the taskcluster proxy setting and
the scopes required for perftest secrets.
"""
from gecko_taskgraph.transforms.test.raptor import (
task_transforms as raptor_transforms,
)
for task in tasks:
if task.get("extra", {}).get("suite", "") != "raptor":
yield task
continue
yield from raptor_transforms(config, [task])
@transforms.add
def task_name_from_label(config, tasks):
for task in tasks:
taskname = task.pop("name", None)
if "label" not in task:
if taskname is None:
raise Exception("task has neither a name nor a label")
task["label"] = f"{config.kind}-{taskname}"
yield task
UNSUPPORTED_SHIPPING_PRODUCT_ERROR = """\
The shipping product {product} is not in the list of configured products in
`taskcluster/config.yml'.
"""
def validate_shipping_product(config, product):
if product not in config.graph_config["release-promotion"]["products"]:
raise Exception(UNSUPPORTED_SHIPPING_PRODUCT_ERROR.format(product=product))
@transforms.add
def validate(config, tasks):
for task in tasks:
validate_schema(
task_description_schema,
task,
"In task {!r}:".format(task.get("label", "?no-label?")),
)
validate_schema(
payload_builders[task["worker"]["implementation"]].schema,
task["worker"],
"In task.run {!r}:".format(task.get("label", "?no-label?")),
)
if task["shipping-product"] is not None:
validate_shipping_product(config, task["shipping-product"])
yield task
@index_builder("generic")
def add_generic_index_routes(config, task):
index = task.get("index")
routes = task.setdefault("routes", [])
verify_index(config, index)
subs = config.params.copy()
subs["job-name"] = index["job-name"]
subs["build_date_long"] = time.strftime(
"%Y.%m.%d.%Y%m%d%H%M%S", time.gmtime(config.params["build_date"])
)
subs["build_date"] = time.strftime(
"%Y.%m.%d", time.gmtime(config.params["build_date"])
)
subs["product"] = index["product"]
subs["trust-domain"] = config.graph_config["trust-domain"]
subs["branch_rev"] = get_branch_rev(config)
try:
subs["branch_git_rev"] = get_branch_git_rev(config)
except KeyError:
pass
project = config.params.get("project")
for tpl in V2_ROUTE_TEMPLATES:
try:
routes.append(tpl.format(**subs))
except KeyError:
# Ignore errors that arise from branch_git_rev not being set.
pass
# Additionally alias all tasks for "trunk" repos into a common
# namespace.
if project and project in TRUNK_PROJECTS:
for tpl in V2_TRUNK_ROUTE_TEMPLATES:
routes.append(tpl.format(**subs))
return task
@index_builder("shippable")
def add_shippable_index_routes(config, task):
index = task.get("index")
routes = task.setdefault("routes", [])
verify_index(config, index)
subs = config.params.copy()
subs["job-name"] = index["job-name"]
subs["build_date_long"] = time.strftime(
"%Y.%m.%d.%Y%m%d%H%M%S", time.gmtime(config.params["build_date"])
)
subs["build_date"] = time.strftime(
"%Y.%m.%d", time.gmtime(config.params["build_date"])
)
subs["product"] = index["product"]
subs["trust-domain"] = config.graph_config["trust-domain"]
subs["branch_rev"] = get_branch_rev(config)
try:
subs["branch_git_rev"] = get_branch_git_rev(config)
except KeyError:
pass
for tpl in V2_SHIPPABLE_TEMPLATES:
try:
routes.append(tpl.format(**subs))
except KeyError:
# Ignore errors that arise from branch_git_rev not being set.
pass
# Also add routes for en-US
task = add_shippable_l10n_index_routes(config, task, force_locale="en-US")
return task
@index_builder("shippable-with-multi-l10n")
def add_shippable_multi_index_routes(config, task):
task = add_shippable_index_routes(config, task)
task = add_l10n_index_routes(config, task, force_locale="multi")
return task
@index_builder("l10n")
def add_l10n_index_routes(config, task, force_locale=None):
index = task.get("index")
routes = task.setdefault("routes", [])
verify_index(config, index)
subs = config.params.copy()
subs["job-name"] = index["job-name"]
subs["build_date_long"] = time.strftime(
"%Y.%m.%d.%Y%m%d%H%M%S", time.gmtime(config.params["build_date"])
)
subs["product"] = index["product"]
subs["trust-domain"] = config.graph_config["trust-domain"]
subs["branch_rev"] = get_branch_rev(config)
locales = task["attributes"].get(
"chunk_locales", task["attributes"].get("all_locales")
)
# Some tasks has only one locale set
if task["attributes"].get("locale"):
locales = [task["attributes"]["locale"]]
if force_locale:
# Used for en-US and multi-locale
locales = [force_locale]
if not locales:
raise Exception("Error: Unable to use l10n index for tasks without locales")
# If there are too many locales, we can't write a route for all of them
# See Bug 1323792
if len(locales) > 18: # 18 * 3 = 54, max routes = 64
return task
for locale in locales:
for tpl in V2_L10N_TEMPLATES:
routes.append(tpl.format(locale=locale, **subs))
return task
@index_builder("shippable-l10n")
def add_shippable_l10n_index_routes(config, task, force_locale=None):
index = task.get("index")
routes = task.setdefault("routes", [])
verify_index(config, index)
subs = config.params.copy()
subs["job-name"] = index["job-name"]
subs["build_date_long"] = time.strftime(
"%Y.%m.%d.%Y%m%d%H%M%S", time.gmtime(config.params["build_date"])
)
subs["product"] = index["product"]
subs["trust-domain"] = config.graph_config["trust-domain"]
subs["branch_rev"] = get_branch_rev(config)
locales = task["attributes"].get(
"chunk_locales", task["attributes"].get("all_locales")
)
# Some tasks has only one locale set
if task["attributes"].get("locale"):
locales = [task["attributes"]["locale"]]
if force_locale:
# Used for en-US and multi-locale
locales = [force_locale]
if not locales:
raise Exception("Error: Unable to use l10n index for tasks without locales")
# If there are too many locales, we can't write a route for all of them
# See Bug 1323792
if len(locales) > 18: # 18 * 3 = 54, max routes = 64
return task
for locale in locales:
for tpl in V2_SHIPPABLE_L10N_TEMPLATES:
routes.append(tpl.format(locale=locale, **subs))
return task
def add_geckoview_index_routes(config, task):
index = task.get("index")
routes = task.setdefault("routes", [])
geckoview_version = _compute_geckoview_version(
config.params["app_version"], config.params["moz_build_date"]
)
subs = {
"geckoview-version": geckoview_version,
"job-name": index["job-name"],
"product": index["product"],
"project": config.params["project"],
"trust-domain": config.graph_config["trust-domain"],
}
routes.append(V2_GECKOVIEW_RELEASE.format(**subs))
return task
@index_builder("android-shippable")
def add_android_shippable_index_routes(config, task):
task = add_shippable_index_routes(config, task)
task = add_geckoview_index_routes(config, task)
return task
@index_builder("android-shippable-with-multi-l10n")
def add_android_shippable_multi_index_routes(config, task):
task = add_shippable_multi_index_routes(config, task)
task = add_geckoview_index_routes(config, task)
return task
@transforms.add
def add_index_routes(config, tasks):
for task in tasks:
index = task.get("index", {})
# The default behavior is to rank tasks according to their tier
extra_index = task.setdefault("extra", {}).setdefault("index", {})
rank = index.get("rank", "by-tier")
if rank == "by-tier":
# rank is one for non-tier-1 tasks and based on pushid for others;
# this sorts tier-{2,3} builds below tier-1 in the index, but above
# eager-index
tier = task.get("treeherder", {}).get("tier", 3)
extra_index["rank"] = 1 if tier > 1 else int(config.params["build_date"])
elif rank == "build_date":
extra_index["rank"] = int(config.params["build_date"])
else:
extra_index["rank"] = rank
if not index:
yield task
continue
index_type = index.get("type", "generic")
task = index_builders[index_type](config, task)
del task["index"]
yield task
@transforms.add
def try_task_config_env(config, tasks):
"""Set environment variables in the task."""
env = config.params["try_task_config"].get("env")
if not env:
yield from tasks
return
# Find all implementations that have an 'env' key.
implementations = {
name
for name, builder in payload_builders.items()
if "env" in builder.schema.schema
}
for task in tasks:
if task["worker"]["implementation"] in implementations:
task["worker"]["env"].update(env)
yield task
@transforms.add
def try_task_config_priority(config, tasks):
"""Change priority based on the try_task_config."""
priority = config.params["try_task_config"].get("priority")
if not priority:
yield from tasks
return
for task in tasks:
task["priority"] = priority
yield task
@transforms.add
def try_task_config_routes(config, tasks):
"""Set routes in the task."""
routes = config.params["try_task_config"].get("routes")
for task in tasks:
if routes:
task_routes = task.setdefault("routes", [])
task_routes.extend(routes)
yield task
@transforms.add
def set_task_and_artifact_expiry(config, jobs):
"""Set the default expiry for tasks and their artifacts.
These values are read from ci/config.yml
"""
now = datetime.datetime.utcnow()
# We don't want any configuration leading to anything with an expiry longer
# than 28 days on try.
cap = (
"28 days"
if is_try(config.params) and int(config.params["level"]) == 1
else None
)
cap_from_now = fromNow(cap, now) if cap else None
for job in jobs:
expires = get_expiration(config, job.get("expiration-policy", "default"))
job_expiry = job.setdefault("expires-after", expires)
job_expiry_from_now = fromNow(job_expiry, now)
if cap and job_expiry_from_now > cap_from_now:
job_expiry, job_expiry_from_now = cap, cap_from_now
# If the task has no explicit expiration-policy, but has an expires-after,
# we use that as the default artifact expiry.
artifact_expires = expires if "expiration-policy" in job else job_expiry
for artifact in job["worker"].get("artifacts", ()):
artifact_expiry = artifact.setdefault("expires-after", artifact_expires)
# By using > instead of >=, there's a chance of mismatch
# where the artifact expires sooner than the task.
# There is no chance, however, of mismatch where artifacts
# expire _after_ the task.
# Currently this leads to some build tasks having logs
# that expire in 1 year while the task expires in 3 years.
if fromNow(artifact_expiry, now) > job_expiry_from_now:
artifact["expires-after"] = job_expiry
yield job
def group_name_variant(group_names, groupSymbol):
# iterate through variants, allow for Base-[variant_list]
# sorting longest->shortest allows for finding variants when
# other variants have a suffix that is a subset
variant_symbols = sorted(
[
(
v,
TEST_VARIANTS[v]["suffix"],
TEST_VARIANTS[v].get("description", "{description}"),
)
for v in TEST_VARIANTS
if TEST_VARIANTS[v].get("suffix", "")
],
key=lambda tup: len(tup[1]),
reverse=True,
)
# strip known variants
# build a list of known variants
base_symbol = groupSymbol
found_variants = []
for variant, suffix, description in variant_symbols:
if f"-{suffix}" in base_symbol:
base_symbol = base_symbol.replace(f"-{suffix}", "")
found_variants.append((variant, description))
if base_symbol not in group_names:
return ""
description = group_names[base_symbol]
for variant, desc in found_variants:
description = desc.format(description=description)
return description
@transforms.add
def build_task(config, tasks):
for task in tasks:
level = str(config.params["level"])
task_worker_type = task["worker-type"]
worker_overrides = config.params["try_task_config"].get("worker-overrides", {})
if task_worker_type in worker_overrides:
worker_pool = worker_overrides[task_worker_type]
provisioner_id, worker_type = worker_pool.split("/", 1)
else:
provisioner_id, worker_type = get_worker_type(
config.graph_config,
config.params,
task_worker_type,
)
task["worker-type"] = "/".join([provisioner_id, worker_type])
project = config.params["project"]
routes = task.get("routes", [])
scopes = [
s.format(level=level, project=project) for s in task.get("scopes", [])
]
# set up extra
extra = task.get("extra", {})
extra["parent"] = {"task-reference": "<decision>"}
task_th = task.get("treeherder")
if task_th:
extra.setdefault("treeherder-platform", task_th["platform"])
treeherder = extra.setdefault("treeherder", {})
machine_platform, collection = task_th["platform"].split("/", 1)
treeherder["machine"] = {"platform": machine_platform}
treeherder["collection"] = {collection: True}
group_names = config.graph_config["treeherder"]["group-names"]
groupSymbol, symbol = split_symbol(task_th["symbol"])
if groupSymbol != "?":
treeherder["groupSymbol"] = groupSymbol
description = group_names.get(
groupSymbol, group_name_variant(group_names, groupSymbol)
)
if not description:
path = os.path.join(config.path, task.get("task-from", ""))
raise Exception(UNKNOWN_GROUP_NAME.format(groupSymbol, path))
treeherder["groupName"] = description
treeherder["symbol"] = symbol
if len(symbol) > 25 or len(groupSymbol) > 25:
raise RuntimeError(
"Treeherder group and symbol names must not be longer than "
"25 characters: {} (see {})".format(
task_th["symbol"],
TC_TREEHERDER_SCHEMA_URL,
)
)
treeherder["jobKind"] = task_th["kind"]
treeherder["tier"] = task_th["tier"]
branch_rev = get_branch_rev(config)
routes.append(
"{}.v2.{}.{}".format(
TREEHERDER_ROUTE_ROOT,
config.params["project"],
branch_rev,
)
)
if "deadline-after" not in task:
task["deadline-after"] = "1 day"
if "priority" not in task:
task["priority"] = get_default_priority(
config.graph_config, config.params["project"]
)
tags = task.get("tags", {})
attributes = task.get("attributes", {})
tags.update(
{
"createdForUser": config.params["owner"],
"kind": config.kind,
"label": task["label"],
"retrigger": "true" if attributes.get("retrigger", False) else "false",
"project": config.params["project"],
"trust-domain": config.graph_config["trust-domain"],
}
)
task_def = {
"provisionerId": provisioner_id,
"workerType": worker_type,
"routes": routes,
"created": {"relative-datestamp": "0 seconds"},
"deadline": {"relative-datestamp": task["deadline-after"]},
"expires": {"relative-datestamp": task["expires-after"]},
"scopes": scopes,
"metadata": {
"description": task["description"],
"name": task["label"],
"owner": config.params["owner"],
"source": config.params.file_url(config.path, pretty=True),
},
"extra": extra,
"tags": tags,
"priority": task["priority"],
}
if task.get("requires", None):
task_def["requires"] = task["requires"]
if task.get("retries") is not None:
task_def["retries"] = task["retries"]
if task_th:
# link back to treeherder in description
th_job_link = (
"https://treeherder.mozilla.org/#/jobs?repo={}&revision={}&selectedTaskRun=<self>"
).format(config.params["project"], branch_rev)
task_def["metadata"]["description"] = {
"task-reference": "{description} ([Treeherder job]({th_job_link}))".format(
description=task_def["metadata"]["description"],
th_job_link=th_job_link,
)
}
# add the payload and adjust anything else as required (e.g., scopes)
payload_builders[task["worker"]["implementation"]].builder(
config, task, task_def
)
# Resolve run-on-projects
build_platform = attributes.get("build_platform")
resolve_keyed_by(
task,
"run-on-projects",
item_name=task["label"],
**{"build-platform": build_platform},
)
attributes["run_on_repo_type"] = task.get("run-on-repo-type", ["git", "hg"])
attributes["run_on_projects"] = task.get("run-on-projects", ["all"])
attributes["always_target"] = task["always-target"]
# This logic is here since downstream tasks don't always match their
# upstream dependency's shipping_phase.
# A text_type task['shipping-phase'] takes precedence, then
# an existing attributes['shipping_phase'], then fall back to None.
if task.get("shipping-phase") is not None:
attributes["shipping_phase"] = task["shipping-phase"]
else:
attributes.setdefault("shipping_phase", None)
# shipping_product will always match the upstream task's
# shipping_product, so a pre-set existing attributes['shipping_product']
# takes precedence over task['shipping-product']. However, make sure
# we don't have conflicting values.
if task.get("shipping-product") and attributes.get("shipping_product") not in (
None,
task["shipping-product"],
):
raise Exception(
"{} shipping_product {} doesn't match task shipping-product {}!".format(
task["label"],
attributes["shipping_product"],
task["shipping-product"],
)
)
attributes.setdefault("shipping_product", task["shipping-product"])
# Set some MOZ_* settings on all jobs.
if task["worker"]["implementation"] in (
"generic-worker",
"docker-worker",
):
payload = task_def.get("payload")
if payload:
env = payload.setdefault("env", {})
env.update(
{
"MOZ_AUTOMATION": "1",
"MOZ_BUILD_DATE": config.params["moz_build_date"],
"MOZ_SCM_LEVEL": config.params["level"],
"MOZ_SOURCE_CHANGESET": get_branch_rev(config),
"MOZ_SOURCE_REPO": get_branch_repo(config),
}
)
dependencies = task.get("dependencies", {})
if_dependencies = task.get("if-dependencies", [])
if if_dependencies:
for i, dep in enumerate(if_dependencies):
if dep in dependencies:
if_dependencies[i] = dependencies[dep]
continue
raise Exception(
"{label} specifies '{dep}' in if-dependencies, "
"but {dep} is not a dependency!".format(
label=task["label"], dep=dep
)
)
yield {
"label": task["label"],
"description": task["description"],
"task": task_def,
"dependencies": dependencies,
"if-dependencies": if_dependencies,
"soft-dependencies": task.get("soft-dependencies", []),
"attributes": attributes,
"optimization": task.get("optimization", None),
}
@transforms.add
def chain_of_trust(config, tasks):
for task in tasks:
if task["task"].get("payload", {}).get("features", {}).get("chainOfTrust"):
image = task.get("dependencies", {}).get("docker-image")
if image:
cot = (
task["task"].setdefault("extra", {}).setdefault("chainOfTrust", {})
)
cot.setdefault("inputs", {})["docker-image"] = {
"task-reference": "<docker-image>"
}
yield task
@transforms.add
def check_task_identifiers(config, tasks):
"""Ensures that all tasks have well defined identifiers:
``^[a-zA-Z0-9_-]{1,38}$``
"""
e = re.compile("^[a-zA-Z0-9_-]{1,38}$")
for task in tasks:
for attrib in ("workerType", "provisionerId"):
if not e.match(task["task"][attrib]):
raise Exception(
"task {}.{} is not a valid identifier: {}".format(
task["label"], attrib, task["task"][attrib]
)
)
yield task
@transforms.add
def check_task_dependencies(config, tasks):
"""Ensures that tasks don't have more than 100 dependencies."""
for task in tasks:
if len(task["dependencies"]) > MAX_DEPENDENCIES:
raise Exception(
"task {}/{} has too many dependencies ({} > {})".format(
config.kind,
task["label"],
len(task["dependencies"]),
MAX_DEPENDENCIES,
)
)
yield task
@transforms.add
def check_perf_task_fission_filtering(config, tasks):
for task in tasks:
if (
("chrome-m" in task["label"] or "cstm-car-m" in task["label"])
and "nofis" not in task["label"]
and "android" in task["label"]
and "startup" not in task["label"]
):
continue
yield task
def check_caches_are_volumes(task):
"""Ensures that all cache paths are defined as volumes.
Caches and volumes are the only filesystem locations whose content
isn't defined by the Docker image itself. Some caches are optional
depending on the job environment. We want paths that are potentially
caches to have as similar behavior regardless of whether a cache is
used. To help enforce this, we require that all paths used as caches
to be declared as Docker volumes. This check won't catch all offenders.
But it is better than nothing.
"""
volumes = {s for s in task["worker"]["volumes"]}
paths = {c["mount-point"] for c in task["worker"].get("caches", [])}
missing = paths - volumes
if not missing:
return
raise Exception(
"task %s (image %s) has caches that are not declared as "
"Docker volumes: %s "
"(have you added them as VOLUMEs in the Dockerfile?)"
% (task["label"], task["worker"]["docker-image"], ", ".join(sorted(missing)))
)
def check_required_volumes(task):
"""
Ensures that all paths that are required to be volumes are defined as volumes.
Performance of writing to files in poor in directories not marked as
volumes, in docker. Ensure that paths that are often written to are marked
as volumes.
"""
volumes = set(task["worker"]["volumes"])
paths = set(task["worker"].get("required-volumes", []))
missing = paths - volumes
if not missing:
return
raise Exception(
"task %s (image %s) has paths that should be volumes for peformance "
"that are not declared as Docker volumes: %s "
"(have you added them as VOLUMEs in the Dockerfile?)"
% (task["label"], task["worker"]["docker-image"], ", ".join(sorted(missing)))
)
@transforms.add
def check_run_task_caches(config, tasks):
"""Audit for caches requiring run-task.
run-task manages caches in certain ways. If a cache managed by run-task
is used by a non run-task task, it could cause problems. So we audit for
that and make sure certain cache names are exclusive to run-task.
IF YOU ARE TEMPTED TO MAKE EXCLUSIONS TO THIS POLICY, YOU ARE LIKELY
CONTRIBUTING TECHNICAL DEBT AND WILL HAVE TO SOLVE MANY OF THE PROBLEMS
THAT RUN-TASK ALREADY SOLVES. THINK LONG AND HARD BEFORE DOING THAT.
"""
re_reserved_caches = re.compile(
"""^
(checkouts|tooltool-cache)
""",
re.VERBOSE,
)
re_checkout_cache = re.compile("^checkouts")
re_sparse_checkout_cache = re.compile("^checkouts-sparse")
re_shallow_checkout_cache = re.compile("^checkouts-git-shallow")
cache_prefix = "{trust_domain}-level-{level}-".format(
trust_domain=config.graph_config["trust-domain"],
level=config.params["level"],
)
suffix = _run_task_suffix(config.params["repository_type"])
for task in tasks:
payload = task["task"].get("payload", {})
command = payload.get("command") or [""]
main_command = command[0] if isinstance(command[0], str) else ""
run_task = is_run_task(main_command)
require_sparse_cache = False
require_shallow_cache = False
have_checkout_cache = False
have_sparse_cache = False
have_shallow_cache = False
if run_task:
for arg in command[1:]:
if not isinstance(arg, str):
continue
if arg == "--":
break
if arg.startswith("--gecko-sparse-profile"):
if "=" not in arg:
raise Exception(
"{} is specifying `--gecko-sparse-profile` to run-task "
"as two arguments. Unable to determine if the sparse "
"profile exists.".format(task["label"])
)
_, sparse_profile = arg.split("=", 1)
if not os.path.exists(os.path.join(GECKO, sparse_profile)):
raise Exception(
"{} is using non-existant sparse profile {}.".format(
task["label"], sparse_profile
)
)
require_sparse_cache = True
break
if arg == "--gecko-shallow-clone":
require_shallow_cache = True
break
for cache in payload.get("cache", {}):
if not cache.startswith(cache_prefix):
raise Exception(
"{} is using a cache ({}) which is not appropriate "
"for its trust-domain and level. It should start with {}.".format(
task["label"], cache, cache_prefix
)
)
cache = cache[len(cache_prefix) :]
if re_checkout_cache.match(cache):
have_checkout_cache = True
if re_sparse_checkout_cache.match(cache):
have_sparse_cache = True
if re_shallow_checkout_cache.match(cache):
have_shallow_cache = True
if not re_reserved_caches.match(cache):
continue
if not run_task:
raise Exception(
"%s is using a cache (%s) reserved for run-task "
"change the task to use run-task or use a different "
"cache name" % (task["label"], cache)
)
if not cache.endswith(suffix):
raise Exception(
"%s is using a cache (%s) reserved for run-task "
"but the cache name is not dependent on the contents "
"of run-task; change the cache name to conform to the "
"naming requirements" % (task["label"], cache)
)
if have_checkout_cache and require_sparse_cache and not have_sparse_cache:
raise Exception(
"%s is using a sparse checkout but not using "
"a sparse checkout cache; change the checkout "
"cache name so it is sparse aware" % task["label"]
)
if have_checkout_cache and require_shallow_cache and not have_shallow_cache:
raise Exception(
"%s is using a shallow clone but not using "
"a shallow checkout cache; change the checkout "
"cache name so it is shallow aware" % task["label"]
)
yield task
|