Module: Mysigner::CLI::BuildCommands
- Included in:
- Mysigner::CLI
- Defined in:
- lib/mysigner/cli/build_commands.rb
Defined Under Namespace
Classes: MetadataFileError
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
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 |
# File 'lib/mysigner/cli/build_commands.rb', line 17 def self.included(base) base.class_eval do desc 'ship TARGET', '🚀 Build + upload (iOS: testflight/appstore, Android: internal/alpha/beta/production)' long_desc <<~DESC Build your project, sign it, and upload in one go. iOS TARGETS testflight : Upload a beta build to TestFlight appstore : Upload a production build to App Store Connect ANDROID TARGETS internal : Upload to internal testing track alpha : Upload to alpha (closed testing) track beta : Upload to beta (open testing) track production : Upload to production track PLATFORM OPTIONS --platform ios Force iOS build (auto-detected by default) --platform android Force Android build iOS OPTIONS --wait Wait for Apple to finish processing the upload --team TEAM_ID Override the detected development team --bundle-id ID Override the bundle identifier pulled from the project ANDROID OPTIONS --release-notes TEXT Release notes for Play Store --package-name PKG Override the detected package name WORKFLOW For iOS TestFlight: mysigner ship testflight # Build → Upload → Done! #{' '} For Android Internal Testing: mysigner ship internal --platform android # Build → Upload → Done! EXAMPLES mysigner ship testflight # iOS to TestFlight mysigner ship appstore # iOS to App Store mysigner ship internal --platform android # Android internal track mysigner ship beta --platform android # Android beta track mysigner ship production --platform android # Android production DESC method_option :configuration, aliases: '-c', default: 'Release', desc: 'Build configuration' method_option :scheme, aliases: '-s', desc: 'Scheme to build (auto-detect if not specified)' method_option :wait, type: :boolean, default: false, desc: 'Wait for processing to complete' method_option :team, desc: 'Development team ID (overrides project setting)' method_option :bundle_id, aliases: '-b', desc: 'Bundle ID (overrides project setting)' method_option :platform, type: :string, desc: 'Platform: ios or android (auto-detect if not specified)' method_option :package_name, type: :string, desc: 'Android package name (overrides project setting)' method_option :release_notes, type: :string, desc: 'Release notes for Play Store (Android) / App Store (iOS whatsNew)' method_option :metadata_file, type: :string, desc: 'Path to metadata JSON file (iOS App Store submissions)' method_option :version, type: :string, desc: 'Set version name for Android (e.g., 1.2.0)' method_option :release_type, type: :string, enum: %w[AFTER_APPROVAL MANUAL SCHEDULED], desc: 'Release type for App Store: AFTER_APPROVAL, MANUAL, or SCHEDULED' method_option :scheduled_date, type: :string, banner: 'ISO8601', desc: 'Scheduled release date (ISO 8601, e.g., 2026-02-01T10:00:00Z)' method_option :auto_submit, type: :boolean, desc: 'Submit for App Store review after upload. Defaults to dashboard CLI Defaults, else true for ship appstore. Use --no-auto-submit to skip.' def ship(target) ios_targets = %w[testflight appstore] android_targets = %w[internal alpha beta production] # Determine platform from option or target platform = [:platform]&.to_sym if platform.nil? # Auto-detect from target if ios_targets.include?(target) platform = :ios elsif android_targets.include?(target) platform = :android else error "Invalid target: #{target}" say "Valid iOS targets: #{ios_targets.join(', ')}", :yellow say "Valid Android targets: #{android_targets.join(', ')}", :yellow exit 1 end end # Validate target matches platform if platform == :ios && !ios_targets.include?(target) error "Invalid iOS target: #{target}" say "Valid iOS targets: #{ios_targets.join(', ')}", :yellow exit 1 elsif platform == :android && !android_targets.include?(target) error "Invalid Android target: #{target}" say "Valid Android targets: #{android_targets.join(', ')}", :yellow exit 1 end # Route to platform-specific handler if platform == :android ship_android(target) return end # iOS flow continues below... is_appstore = (target == 'appstore') config = load_config client = create_client(config) overall_start = Time.now timings = {} archive_path = nil ipa_path = nil nil bundle_id = nil target_label = is_appstore ? 'App Store' : 'TestFlight' say "🚀 My Signer - Ship to #{target_label}", :cyan say '=' * 80, :cyan say '' say 'This will:', :bold say ' 1️⃣ Detect and build your project' say ' 2️⃣ Export IPA for App Store' say " 3️⃣ Upload to #{target_label}" if is_appstore say ' 4️⃣ Wait for Apple to process build' say ' 5️⃣ Submit for App Store review' end say '' say "⏱️ Estimated time: #{is_appstore ? '15-30 minutes' : '3-7 minutes'}", :yellow say '' begin # STEP 1: BUILD say '=' * 80, :cyan say '[1/3] Building Archive', :cyan say '=' * 80, :cyan say '' build_start = Time.now # Detect project project_info = Build::Detector.detect project_name = File.basename(project_info[:path], '.*') framework_label = case project_info[:framework] when :capacitor then 'Capacitor/Ionic' when :react_native then 'React Native' when :flutter then 'Flutter' else 'Native iOS' end say "✓ Found: #{File.basename(project_info[:path])} (#{framework_label})", :green say '' # Parse and build parser = Build::Parser.new(project_info) target_name = [:target] || parser.main_target.name bundle_id = [:bundle_id] || parser.bundle_id(target_name, [:configuration]) # Validate bundle ID format if overridden if [:bundle_id] if bundle_id =~ /\$\(|\$\{/ error "Bundle ID cannot contain variables: #{bundle_id}" exit 1 elsif bundle_id !~ /^[a-zA-Z0-9.-]+$/ error "Invalid bundle ID format: #{bundle_id}" say 'Bundle IDs must contain only letters, numbers, hyphens, and periods', :yellow exit 1 end end say "🎯 Target: #{target_name}", :cyan say "📦 Bundle ID: #{bundle_id}#{' (overridden)' if [:bundle_id]}", :cyan say '⏱️ Estimated: 2-5 minutes', :yellow say '' # Auto-fetch team ID from API if not provided and project missing it team_id_to_use = [:team] project_team_id = parser.team_id(target_name, [:configuration]) if !team_id_to_use && (project_team_id.nil? || project_team_id.empty?) say '🔍 No team set in project, fetching from My Signer...', :yellow begin org_response = client.get("/api/v1/organizations/#{config.current_organization_id}") api_team_id = org_response.dig(:data, 'app_store_connect_team_id') || org_response['app_store_connect_team_id'] if api_team_id && !api_team_id.empty? team_id_to_use = api_team_id say "✓ Using team from My Signer: #{api_team_id}", :green else say '⚠️ No team ID configured in My Signer', :yellow end rescue StandardError => e say "⚠️ Failed to fetch team from API: #{e.}", :yellow end end say '' # Pre-build validation say '🔍 Validating signing setup...', :cyan validator = Signing::Validator.new(parser, target_name, [:configuration], team_id: team_id_to_use) validator.validate! executor = Build::Executor.new(project_info, parser) archive_path = executor.build!( target_name, [:configuration], scheme: [:scheme], signing_style: parser.code_sign_style(target_name, [:configuration]), team_id: team_id_to_use ) timings[:build] = Time.now - build_start say '' say "✓ Build complete in #{format_duration(timings[:build])}", :green say '' # STEP 2: EXPORT say '=' * 80, :cyan say '[2/3] Exporting IPA', :cyan say '=' * 80, :cyan say '' say '⏱️ Estimated: 30-90 seconds', :yellow say '' export_start = Time.now exporter = Export::Exporter.new(archive_path) ipa_path = exporter.export!( method: :appstore, team_id: nil, signing_style: 'automatic' ) timings[:export] = Time.now - export_start say '' say "✓ Export complete in #{format_duration(timings[:export])}", :green say "📦 IPA: #{ipa_path}", :cyan say '' # STEP 2.5: Get current latest build (BEFORE upload) - App Store only latest_build_before_upload = nil if is_appstore say '=' * 80, :cyan say 'Getting Current Latest Build', :cyan say '=' * 80, :cyan say '' say '🔄 Syncing from App Store Connect...', :yellow begin client.post("/api/v1/organizations/#{config.current_organization_id}/sync", body: { force: true }) sleep 15 say '✓ Sync complete', :green rescue StandardError => e say "⚠️ Sync failed: #{e.}", :yellow end say '' begin app_response = client.get("/api/v1/organizations/#{config.current_organization_id}/apple_apps", params: { bundle_id: bundle_id }) app = Array(app_response.dig(:data, 'data', 'apps')).first if app builds_response = client.get("/api/v1/organizations/#{config.current_organization_id}/builds", params: { app_id: app['id'] }) latest = Array(builds_response.dig(:data, 'data', 'builds')).first if latest latest_build_before_upload = latest['build_number'].to_i say "✓ Current latest build: ##{latest_build_before_upload}", :green else say '✓ No builds yet', :green latest_build_before_upload = 0 end end rescue StandardError => e say "⚠️ Could not fetch builds: #{e.}", :yellow latest_build_before_upload = 0 end say '' end # STEP 3: UPLOAD say '=' * 80, :cyan say "[3/#{is_appstore ? '5' : '3'}] Uploading to #{target_label}", :cyan say '=' * 80, :cyan say '' say '⏱️ Estimated: 1-3 minutes', :yellow say '' upload_start = Time.now if ENV['MYSIGNER_USE_LEGACY_ASC'] == '1' # LEGACY PATH — altool with server-fetched .p8. Will be removed in next release. say '⚠️ MYSIGNER_USE_LEGACY_ASC=1 — using legacy altool upload path (deprecated).', :yellow # Fetch App Store Connect credentials say '🔐 Fetching App Store Connect credentials...', :yellow org_response = client.get("/api/v1/organizations/#{config.current_organization_id}") org_data = org_response[:data] unless org_data['app_store_connect_configured'] say '' say '✗ App Store Connect credentials not configured', :red say '' say 'Quick fix:', :cyan say ' mysigner doctor # Auto-configure now', :green say '' say 'Or manually:', :cyan say ' 1. Run: mysigner onboard' say ' 2. Follow Step 5 to add credentials' say '' exit 1 end api_key = org_data['app_store_connect_key_id'] api_issuer = org_data['app_store_connect_issuer_id'] private_key = org_data['app_store_connect_private_key'] unless api_key && api_issuer && private_key say '✗ Error: Invalid credentials received from API', :red exit 1 end say '✓ Credentials loaded', :green say '' # Upload (Uploader writes .p8 to Dir.mktmpdir + cleans up in ensure) uploader = Upload::Uploader.new( ipa_path, api_key: api_key, api_issuer: api_issuer, private_key: private_key ) uploader.upload!(wait_for_processing: [:wait]) else # DEFAULT PATH — ASC REST Build Upload API. No .p8 ever leaves the server. require_relative '../upload/asc_rest_uploader' # Resolve apple_app_id from bundle_id (may already have been fetched for is_appstore) if !defined?(app) || app.nil? app_response = client.get("/api/v1/organizations/#{config.current_organization_id}/apple_apps", params: { bundle_id: bundle_id }) app = Array(app_response.dig(:data, 'data', 'apps')).first end unless app && app['id'] say "✗ App not found in MySigner for bundle_id: #{bundle_id}", :red say 'Run: mysigner sync ios', :yellow exit 1 end # Read version info from the built IPA ipa_info = Upload::Uploader.extract_ipa_info(ipa_path) cf_version = ipa_info[:cf_bundle_version] || '1' cf_short = ipa_info[:cf_bundle_short_version_string] || '1.0' say "📤 Uploading via App Store Connect REST API (version #{cf_short} build #{cf_version})...", :cyan rest = Mysigner::Upload::AscRestUploader.new( client: client, organization_id: config.current_organization_id, ipa_path: ipa_path, apple_app_id: app['id'], cf_bundle_version: cf_version, cf_bundle_short_version_string: cf_short, platform: 'IOS' ) result = rest.call case result[:final_state] when 'COMPLETE' say '✓ Upload complete — Apple accepted the build', :green when 'FAILED', 'INVALIDATED' say "✗ Apple rejected the upload: #{result[:final_state]}", :red exit 1 when 'TIMEOUT' say '⚠ Apple is still processing — check App Store Connect.', :yellow end end timings[:upload] = Time.now - upload_start # STEP 4: Submit for App Store Review (appstore only) if is_appstore say '' say '=' * 80, :cyan say '[4/5] Waiting for Apple to Process Build', :cyan say '=' * 80, :cyan say '' submission_start = Time.now # Poll sync every 3 minutes until we find a newer build say "⏳ Waiting for build ##{latest_build_before_upload + 1} to sync (polls every 3min)...", :yellow timeout = 1800 # 30 minutes poll_interval = 180 # 3 minutes start_time = Time.now new_build = nil poll_count = 0 loop do poll_count += 1 elapsed = Time.now - start_time # Run sync begin client.post("/api/v1/organizations/#{config.current_organization_id}/sync", body: { force: true }) sleep 15 rescue StandardError => e # Ignore end # Check for new build begin app_response = client.get("/api/v1/organizations/#{config.current_organization_id}/apple_apps", params: { bundle_id: bundle_id }) app = Array(app_response.dig(:data, 'data', 'apps')).first if app builds_response = client.get("/api/v1/organizations/#{config.current_organization_id}/builds", params: { app_id: app['id'] }) latest = Array(builds_response.dig(:data, 'data', 'builds')).first current_build_num = latest ? latest['build_number'].to_i : 0 if current_build_num > latest_build_before_upload new_build = latest say "✅ Build ##{new_build['build_number']} synced! (#{new_build['processing_state']})", :green break else # Show progress print "\r [#{(elapsed / 60).to_i}m] Latest: ##{current_build_num}, waiting for ##{latest_build_before_upload + 1}..." $stdout.flush end end rescue StandardError => e say " ⚠️ Could not check builds: #{e.}", :yellow end # Check timeout if elapsed >= timeout say '' say "✗ Timeout after #{(elapsed / 60).to_i} minutes", :red say " Latest build is still ##{latest_build_before_upload}", :yellow exit 1 end # Wait before next poll sleep poll_interval unless new_build end say '' # Step 3: Now wait for the new build to be processed require_relative '../upload/app_store_submission' require_relative '../upload/app_store_automation' automation = Upload::AppStoreAutomation.new( client: client, organization_id: config.current_organization_id, opts: { wait: true, timeout: 1800, poll_interval: 15, no_submit: false, # ship appstore defaults to submitting for review, but # dashboard `cli_defaults.auto_submit = false` now wins # (the old hard-override that clobbered it was removed). default_submit: true } ) # Submit the new build (use its specific build number) # Build metadata overrides from CLI options — start from any # --metadata-file + --release-notes, then layer in ship-specific # release_type/scheduled_date. auto_submit is NOT forced here; # precedence is: --auto-submit flag > cli_defaults > command default. ship_overrides, override_sources = () ship_override_keys = [] if .key?(:auto_submit) ship_overrides['auto_submit'] = [:auto_submit] ship_override_keys << 'auto_submit' end if [:release_type] # Validate release_type valid_types = %w[AFTER_APPROVAL MANUAL SCHEDULED] rt = [:release_type].upcase unless valid_types.include?(rt) error "Invalid release type: #{[:release_type]}" say "Valid options: #{valid_types.join(', ')}", :yellow exit 1 end ship_overrides['release_type'] = rt ship_override_keys << 'release_type' # Validate scheduled_date is provided when SCHEDULED if rt == 'SCHEDULED' && ![:scheduled_date] error 'Scheduled release date is required when --release-type=SCHEDULED' say 'Use: --scheduled-date 2026-02-01T10:00:00Z', :yellow exit 1 end end if [:scheduled_date] begin parsed_date = Time.parse([:scheduled_date]) if parsed_date < Time.now + 3600 # At least 1 hour in the future error 'Scheduled date must be at least 1 hour in the future' exit 1 end ship_overrides['earliest_release_date'] = parsed_date.utc.iso8601 ship_override_keys << 'earliest_release_date' # Auto-set release_type to SCHEDULED if not already set unless ship_overrides['release_type'] ship_overrides['release_type'] = 'SCHEDULED' ship_override_keys << 'release_type' end rescue ArgumentError error "Invalid date format: #{[:scheduled_date]}" say 'Use ISO 8601 format, e.g., 2026-02-01T10:00:00Z', :yellow exit 1 end end override_sources << { type: :inline, keys: ship_override_keys } submission = Upload::AppStoreSubmission.new( client, config.current_organization_id, { bundle_id: bundle_id, build_number: new_build['build_number'] # Use the specific build we found }, metadata_overrides: ship_overrides, override_sources: override_sources ) submission_result = submission.submit_for_review!(automation: automation) timings[:submission] = Time.now - submission_start end timings[:total] = Time.now - overall_start # SUCCESS SUMMARY! say '' say '=' * 80, :green if is_appstore if submission_result && submission_result[:automation][:submitted] say '🎉 SUCCESS! Your app is submitted for App Store review!', :green else say '🎉 SUCCESS! Your app is uploaded to App Store Connect!', :green end else say '🎉 SUCCESS! Your app is on TestFlight!', :green end say '=' * 80, :green say '' # Summary table say '📊 Summary', :bold say '' say " Project: #{project_name}" say " Bundle ID: #{bundle_id}" say " Target: #{target_name}" say " IPA Size: #{format_bytes(File.size(ipa_path))}" say '' if is_appstore && [:submit_for_review] poll_msg = [:wait] ? "every #{automation.poll_interval}s" : 'skipped (--no-wait)' say " ASC Polling: #{poll_msg}" say " ASC Timeout: #{format_duration([:asc_timeout_seconds])}" if [:asc_timeout_seconds] end # Timing breakdown say '⏱️ Time Breakdown', :bold say '' say " Build: #{format_duration(timings[:build])}" say " Export: #{format_duration(timings[:export])}" say " Upload: #{format_duration(timings[:upload])}" say " Submission: #{format_duration(timings[:submission])}" if timings[:submission] say " #{'-' * 30}" say " Total: #{format_duration(timings[:total])}", :bold say '' # Files created say '📁 Files Created', :bold say '' say " Archive: #{archive_path}" say " IPA: #{ipa_path}" say '' # Next steps say '🔮 Next Steps', :bold say '' if is_appstore if submission_result && submission_result[:automation][:submitted] say ' ✓ Your build is submitted for App Store review!', :green say '' say ' Monitor review status:', :cyan say ' https://appstoreconnect.apple.com/apps', :green else say ' ⚠️ Submission completed but not submitted', :yellow say ' (May need release config in My Signer dashboard)', :yellow say '' say ' Or submit manually:', :cyan say ' mysigner submit', :green end else say ' 1. Wait 5-15 minutes for Apple to process your build' say ' 2. Open App Store Connect:' say ' https://appstoreconnect.apple.com/apps' say ' 3. Add testers and distribute via TestFlight' end say '' rescue MetadataFileError => e say '' say '=' * 80, :red say '✗ Ship Failed', :red say '=' * 80, :red say '' say "Error: #{e.}", :red say '' exit 1 rescue Build::Executor::BuildError => e # Analyze build errors and show helpful suggestions say '' if defined?(executor) && executor.respond_to?(:build_errors) require_relative '../build/error_analyzer' analyzer = Build::ErrorAnalyzer.new(executor.build_errors) say analyzer.format_suggestions, :cyan if analyzer.any_issues? end say '=' * 80, :red say '✗ Ship Failed', :red say '=' * 80, :red say '' say "Error: #{e.}", :red say '' say "Archive saved at: #{archive_path}", :yellow if archive_path && File.exist?(archive_path) exit 1 rescue Upload::AppStoreAutomation::AutomationError => e # Use enhanced error handler for App Store automation errors handle_apple_api_error(e, context: { title: 'App Store Automation Failed', archive_path: archive_path, ipa_path: ipa_path, bundle_id: defined?(bundle_id) ? bundle_id : nil }) exit 1 rescue Mysigner::ClientError => e # Handle API client errors with actionable suggestions handle_apple_api_error(e, context: { title: 'API Error', archive_path: archive_path, ipa_path: ipa_path }) exit 1 rescue Mysigner::Upload::AscRestUploader::BuildVersionConflictError => e say '' say "✗ #{e.}", :red say '' exit 1 rescue StandardError => e say '' say '=' * 80, :red say '✗ Ship Failed', :red say '=' * 80, :red say '' say "Error: #{e.}", :red say '' # Try to show actionable suggestions for unknown errors show_actionable_suggestions(e., platform: :ios) say "Archive saved at: #{archive_path}", :yellow if archive_path && File.exist?(archive_path) say "IPA saved at: #{ipa_path}", :yellow if ipa_path && File.exist?(ipa_path) show_debug_info(e) if ENV['DEBUG'] exit 1 end end no_commands do # Ship Android to Google Play def ship_android(track) config = load_config client = create_client(config) overall_start = Time.now timings = {} aab_path = nil package_name = nil track_labels = { 'internal' => 'Internal Testing', 'alpha' => 'Closed Testing (Alpha)', 'beta' => 'Open Testing (Beta)', 'production' => 'Production' } track_label = track_labels[track] || track.capitalize say "🤖 My Signer - Ship to Google Play (#{track_label})", :cyan say '=' * 80, :cyan say '' say 'This will:', :bold say ' 1️⃣ Detect and build your Android project' say ' 2️⃣ Sign with your keystore' say " 3️⃣ Upload to Google Play (#{track} track)" say '' say '⏱️ Estimated time: 3-10 minutes', :yellow say '' begin # STEP 1: Detect and build say '=' * 80, :cyan say '[1/3] Building Android App Bundle (AAB)', :cyan say '=' * 80, :cyan say '' build_start = Time.now # Detect Android project project_info = Build::Detector.detect_android framework_label = case project_info[:framework] when :capacitor then 'Capacitor/Ionic' when :react_native then 'React Native' when :flutter then 'Flutter' else 'Native Android' end say "✓ Found: Android project (#{framework_label})", :green say '' # Parse project require_relative '../build/android_parser' parser = Build::AndroidParser.new(project_info) package_name = [:package_name] || parser.application_id local_version_code = parser.version_code.to_i version_name = parser.version_name # Check highest version code from API and auto-increment if needed highest_version_code = fetch_android_highest_version_code(client, config, package_name) version_code = local_version_code version_code_override = nil if highest_version_code && local_version_code <= highest_version_code version_code = highest_version_code + 1 version_code_override = version_code say "📦 Package: #{package_name}", :cyan say "🔢 Version: #{version_name} (#{local_version_code} → #{version_code})", :cyan say " ↳ Auto-incremented (#{highest_version_code} already on Play Store)", :yellow # For Expo projects, need to regenerate android folder with new versionCode # since versionCode is hardcoded by expo prebuild if expo_project?(Dir.pwd) say '' say "🔄 Regenerating android folder with version code #{version_code}...", :yellow regenerate_expo_android(Dir.pwd, version_code) # Re-detect after regeneration project_info = Build::Detector.detect_android parser = Build::AndroidParser.new(project_info) version_code_override = nil # No longer need override, it's baked in say '✓ Android folder regenerated', :green end else say "📦 Package: #{package_name}", :cyan say "🔢 Version: #{version_name} (#{version_code})", :cyan end say '⏱️ Estimated: 2-5 minutes', :yellow say '' # STEP 2: Get keystore and sign say '=' * 80, :cyan say '[2/3] Signing with Keystore', :cyan say '=' * 80, :cyan say '' # Fetch keystore from API (prefer app-specific, fallback to org-wide) say '🔐 Fetching keystore from My Signer...', :yellow require_relative '../signing/keystore_manager' keystore_manager = Signing::KeystoreManager.new(client, config.current_organization_id) # Try to find the app to get app-specific + org-wide keystores app_id = nil begin response = client.get("/api/v1/organizations/#{config.current_organization_id}/android_apps") apps = response[:data]['android_apps'] || [] app = apps.find { |a| a['package_name'] == package_name } app_id = app['id'] if app rescue StandardError # Continue without app ID end active_keystore = keystore_manager.active_keystore(android_app_id: app_id, include_secrets: true) unless active_keystore say '' say '✗ No active keystore found', :red say '' say 'Quick fix:', :cyan say ' 1. Upload a keystore: mysigner keystore upload', :green say ' 2. Or configure in My Signer dashboard', :green say '' exit 1 end say "✓ Using keystore: #{active_keystore['name']}", :green # Download keystore keystore_info = keystore_manager.get_or_download(active_keystore['id']) say "✓ Keystore ready at: #{keystore_info[:path]}", :green say '' # Get keystore credentials from API response keystore_password = active_keystore['keystore_password'] || ENV.fetch('MYSIGNER_KEYSTORE_PASSWORD', nil) key_password = active_keystore['key_password'] || ENV['MYSIGNER_KEY_PASSWORD'] || keystore_password key_alias = active_keystore['key_alias'] unless keystore_password say '⚠️ Keystore password not found in My Signer', :yellow say ' Upload your keystore with password: mysigner keystore upload FILE', :yellow keystore_password = ask('Keystore password:', echo: false) say '' key_password ||= keystore_password end # Build AAB require_relative '../build/android_executor' executor = Build::AndroidExecutor.new(project_info, parser) aab_path = executor.build_aab!( variant: 'release', keystore_path: keystore_info[:path], keystore_password: keystore_password, key_alias: key_alias, key_password: key_password, version_code: version_code_override ) timings[:build] = Time.now - build_start say '' say "✓ Build complete in #{format_duration(timings[:build])}", :green say "📦 AAB: #{aab_path}", :cyan say '' # STEP 3: Upload to Google Play say '=' * 80, :cyan say '[3/3] Uploading to Google Play', :cyan say '=' * 80, :cyan say '' upload_start = Time.now # Phase 0: mint short-lived OAuth2 access token server-side. # Service-account JSON never leaves the server. say '🔐 Requesting Google Play access token...', :yellow begin token_response = client.post( "/api/v1/organizations/#{config.current_organization_id}/credentials/google_play/access_token" ) access_token = token_response[:data]['access_token'] rescue Mysigner::NotFoundError, Mysigner::ValidationError say '' say '✗ Google Play credentials not configured', :red say '' say 'Quick fix:', :cyan say ' Configure Google Play credentials in My Signer dashboard', :green say '' exit 1 end if access_token.nil? || access_token.to_s.empty? say '✗ Error: Failed to mint Google Play access token', :red exit 1 end say '✓ Access token minted (valid ~1 hour)', :green say '' # Phase 0: fetch Android CLI Defaults from the dashboard # (android_apps.cli_defaults JSONB). Fields here act as base # values; explicit CLI flags below layer on top. android_defaults = fetch_android_release_defaults(client, config, package_name) if android_defaults say "✓ Loaded CLI Defaults for #{package_name}", :green say '' end # Upload to Google Play with bare bearer token require_relative '../upload/play_store_uploader' # Merge release notes: flag > defaults.release_notes (Hash) release_notes = nil if [:release_notes] release_notes = { 'en-US' => [:release_notes] } elsif android_defaults && android_defaults['release_notes'].is_a?(Hash) && android_defaults['release_notes'].any? release_notes = android_defaults['release_notes'] end # Effective track: positional arg wins; defaults only kick in # if the user left it implicit (which `ship android` currently # doesn't allow — track is required — but kept here for # symmetry with submit_android and future-proofing). effective_track = track.presence || android_defaults&.dig('default_track') || 'internal' status = android_defaults&.dig('default_status') user_fraction = android_defaults&.dig('default_user_fraction') in_app_update_priority = android_defaults&.dig('default_in_app_update_priority') release_name = android_defaults&.dig('release_name') country_targeting = android_defaults&.dig('country_targeting') changes_not_sent_for_review = android_defaults&.key?('changes_not_sent_for_review') ? android_defaults['changes_not_sent_for_review'] : nil country_targeting = country_targeting.transform_keys(&:to_sym) if country_targeting.is_a?(Hash) uploader = Upload::PlayStoreUploader.new( aab_path: aab_path, access_token: access_token, package_name: package_name ) uploader.upload!( track: effective_track, release_notes: release_notes, user_fraction: user_fraction, status: status, in_app_update_priority: in_app_update_priority, release_name: release_name, country_targeting: country_targeting, changes_not_sent_for_review: changes_not_sent_for_review ) timings[:upload] = Time.now - upload_start timings[:total] = Time.now - overall_start # Link keystore to app in MySigner (so dashboard shows it) if active_keystore && active_keystore['id'] begin client.post( "/api/v1/organizations/#{config.current_organization_id}/android_keystores/#{active_keystore['id']}/link_to_app", body: { package_name: package_name } ) rescue StandardError => e # Non-fatal, continue end end # Save build record to MySigner (for version tracking) save_android_build_record(client, config, package_name, version_code, version_name) # SUCCESS SUMMARY say '' say '=' * 80, :green say "🎉 SUCCESS! Your app is on Google Play (#{track} track)!", :green say '=' * 80, :green say '' say '📊 Summary', :bold say '' say " Package: #{package_name}" say " Version: #{version_name} (#{version_code})" say " Track: #{track}" say " AAB Size: #{format_bytes(File.size(aab_path))}" say '' say '⏱️ Time Breakdown', :bold say '' say " Build: #{format_duration(timings[:build])}" say " Upload: #{format_duration(timings[:upload])}" say " #{'-' * 30}" say " Total: #{format_duration(timings[:total])}", :bold say '' say '📁 Files Created', :bold say '' say " AAB: #{aab_path}" say '' say '🔮 Next Steps', :bold say '' case track when 'internal' say ' 1. Add internal testers in Google Play Console' say ' 2. Testers will receive the build automatically' when 'alpha', 'beta' say ' 1. Review the build in Google Play Console' say " 2. Promote to #{'beta or ' if track == 'alpha'}production when ready" when 'production' say ' 1. Review is pending in Google Play Console' say ' 2. Once approved, users will receive the update' end say '' say ' Google Play Console: https://play.google.com/console', :green say '' rescue Build::Detector::NoProjectError => e say '' say '=' * 80, :red say '✗ Ship Failed', :red say '=' * 80, :red say '' say "Error: #{e.}", :red say '' say '💡 No Android Project Found: How to fix', :cyan say '' say " → Make sure you're in an Android project directory", :yellow say ' → Check for build.gradle or build.gradle.kts file', :yellow say ' → For React Native: cd android && check build.gradle exists', :yellow say ' → For Flutter: check android/app/build.gradle exists', :yellow say '' exit 1 rescue Upload::PlayStoreUploader::PartialUploadError => e # AAB was uploaded but track assignment/commit failed # Save build record to prevent version conflicts on retry say '' say '=' * 80, :red say '✗ Partial Upload - Track Assignment Failed', :red say '=' * 80, :red say '' say "Error: #{e.}", :red say '' # Save build record even on partial failure (AAB is on Play Store) if e.version_code save_android_build_record(client, config, package_name, e.version_code, version_name) say "📝 Build v#{e.version_code} recorded (prevents version conflicts on retry)", :yellow say '' end # Show track setup suggestions show_track_not_setup_suggestions(track) say "📦 AAB saved at: #{aab_path}", :yellow if aab_path && File.exist?(aab_path) say '' exit 1 rescue Upload::PlayStoreUploader::UploadError => e # Use enhanced error handler for Google Play errors handle_android_api_error(e, context: { title: 'Google Play Upload Failed', aab_path: aab_path, package_name: package_name, track: track }) exit 1 rescue Mysigner::ClientError => e # Handle My Signer API client errors handle_android_api_error(e, context: { title: 'API Error', aab_path: aab_path, package_name: package_name }) exit 1 rescue StandardError => e say '' say '=' * 80, :red say '✗ Ship Failed', :red say '=' * 80, :red say '' say "Error: #{e.}", :red say '' # Try to show actionable suggestions for unknown errors show_actionable_suggestions(e., platform: :android) say "📦 AAB saved at: #{aab_path}", :yellow if aab_path && File.exist?(aab_path) show_debug_info(e) if ENV['DEBUG'] exit 1 end end # Fetch Android CLI Defaults (android_apps.cli_defaults) for the # package_name. Returns nil if none configured or request fails — # ship proceeds with CLI-flag-only values in that case. def fetch_android_release_defaults(client, config, package_name) response = client.get( "/api/v1/organizations/#{config.current_organization_id}/android_releases", params: { package_name: package_name } ) data = response[:data] if response[:success] return nil unless data.is_a?(Hash) releases = data['android_releases'] return nil unless releases.is_a?(Array) && releases.any? releases.first rescue Mysigner::NotFoundError nil rescue StandardError => e # Non-fatal: log and proceed without defaults. puts "⚠️ Could not fetch Android CLI Defaults: #{e.}" if ENV['MYSIGNER_VERBOSE'] == '1' nil end # Fetch highest version code from API def fetch_android_highest_version_code(client, config, package_name) response = client.get("/api/v1/organizations/#{config.current_organization_id}/android_apps") apps = response[:data]['android_apps'] || [] app = apps.find { |a| a['package_name'] == package_name } return app['highest_version_code'].to_i if app && app['highest_version_code'] nil rescue StandardError # Silently fail - we'll use local version nil end # Save build record to MySigner backend for version tracking def save_android_build_record(client, config, package_name, version_code, version_name) # First, find the app ID response = client.get("/api/v1/organizations/#{config.current_organization_id}/android_apps") apps = response[:data]['android_apps'] || [] app = apps.find { |a| a['package_name'] == package_name } unless app # App doesn't exist in MySigner yet - create it with a friendly name friendly_name = generate_app_name_from_package(package_name) create_response = client.post( "/api/v1/organizations/#{config.current_organization_id}/android_apps", body: { android_app: { package_name: package_name, name: friendly_name } } ) app = create_response[:data]['android_app'] end # Now save the build record client.post( "/api/v1/organizations/#{config.current_organization_id}/android_apps/#{app['id']}/android_builds", body: { android_build: { version_code: version_code, version_name: version_name, status: 'completed' } } ) rescue StandardError => e # Non-fatal - just log for debugging say "⚠️ Could not save build record: #{e.}", :yellow if [:verbose] end # Generate a friendly app name from package name # e.g., "com.oopsfee.app" → "Oopsfee" # e.g., "com.example.myapp" → "Myapp" def generate_app_name_from_package(package_name) parts = package_name.to_s.split('.') # Take the most meaningful part (usually 2nd or 3rd segment) # Skip common prefixes like "com", "org", "io", "app" meaningful_part = parts.reject { |p| %w[com org io net app apps android].include?(p.downcase) }.first meaningful_part ||= parts.last # Capitalize first letter meaningful_part.to_s.capitalize end # Submit/promote existing Android build to a track def submit_android(track) config = load_config client = create_client(config) valid_tracks = %w[internal alpha beta production] unless valid_tracks.include?(track) error "Invalid Android track: #{track}" say "Valid tracks: #{valid_tracks.join(', ')}", :yellow exit 1 end track_labels = { 'internal' => 'Internal Testing', 'alpha' => 'Closed Testing (Alpha)', 'beta' => 'Open Testing (Beta)', 'production' => 'Production' } track_label = track_labels[track] say "📤 Promote to Google Play #{track_label}", :cyan say '=' * 80, :cyan say '' begin # Get package name package_name = [:package_name] unless package_name begin project_info = Build::Detector.detect_android require_relative '../build/android_parser' parser = Build::AndroidParser.new(project_info) package_name = parser.application_id say "✓ Detected package: #{package_name}", :green rescue StandardError error 'Could not detect package name from project' say '' say 'Please specify manually:', :yellow say " mysigner submit #{track} --platform android --package-name com.your.app", :cyan exit 1 end end say '' say "📦 Package: #{package_name}", :cyan say "🎯 Target Track: #{track_label}", :cyan say '' # Phase 0: mint short-lived access token server-side; JSON stays on server say '🔐 Requesting Google Play access token...', :yellow begin token_response = client.post( "/api/v1/organizations/#{config.current_organization_id}/credentials/google_play/access_token" ) access_token = token_response[:data]['access_token'] rescue Mysigner::NotFoundError, Mysigner::ValidationError say '' say '✗ Google Play credentials not configured', :red say '' say 'Configure Google Play credentials in My Signer dashboard', :cyan exit 1 end if access_token.nil? || access_token.to_s.empty? say '✗ Error: Failed to mint Google Play access token', :red exit 1 end say '✓ Access token minted', :green say '' # Get the latest build from the API say '🔍 Finding builds in My Signer...', :yellow apps_response = client.get( "/api/v1/organizations/#{config.current_organization_id}/android_apps", params: { q: package_name } ) apps = apps_response[:data]['android_apps'] || [] app = apps.find { |a| a['package_name'] == package_name } unless app say '' say '⚠️ App not found in My Signer', :yellow say '' say 'The app may not be synced yet. Try:', :cyan say ' mysigner sync android', :green say '' end # Use version code from option or prompt for it version_code = [:version_code] unless version_code say '' say "Enter the version code to promote to #{track}:", :yellow version_code = ask('Version code:') end say '' say "📤 Promoting version #{version_code} to #{track} track...", :cyan say '' # Use PlayStoreUploader to assign to track require_relative '../upload/play_store_uploader' release_notes = nil release_notes = { 'en-US' => [:release_notes] } if [:release_notes] # Use the Google API directly with the bare bearer token for track assignment require 'google/apis/androidpublisher_v3' service = Google::Apis::AndroidpublisherV3::AndroidPublisherService.new service. = access_token # Create edit edit = service.insert_edit(package_name, Google::Apis::AndroidpublisherV3::AppEdit.new) # Build release release = Google::Apis::AndroidpublisherV3::TrackRelease.new( version_codes: [version_code.to_s], status: 'completed' ) if release_notes release.release_notes = release_notes.map do |lang, text| Google::Apis::AndroidpublisherV3::LocalizedText.new(language: lang, text: text) end end # Update track track_obj = Google::Apis::AndroidpublisherV3::Track.new( track: track, releases: [release] ) service.update_edit_track(package_name, edit.id, track, track_obj) # Commit service.commit_edit(package_name, edit.id, changes_not_sent_for_review: true) say '' say '=' * 80, :green say "✓ Successfully promoted to #{track} track!", :green say '=' * 80, :green say '' say "📦 Package: #{package_name}" say "🔢 Version Code: #{version_code}" say "🎯 Track: #{track_label}" say '' say 'View in Google Play Console:', :cyan say ' https://play.google.com/console', :green say '' rescue Google::Apis::ClientError => e say '' say '=' * 80, :red say '✗ Promotion Failed', :red say '=' * 80, :red say '' say "Google Play API error: #{e.}", :red exit 1 rescue StandardError => e say '' say '=' * 80, :red say '✗ Promotion Failed', :red say '=' * 80, :red say '' say "Error: #{e.}", :red exit 1 end end def (opts) overrides = {} sources = [] if opts[:metadata_file] file_overrides = (opts[:metadata_file]) overrides = deep_merge_hashes(overrides, file_overrides) sources << { type: :file, path: File.(opts[:metadata_file]), keys: (file_overrides) } end if opts[:release_notes] overrides = deep_merge_hashes(overrides, { 'whats_new' => opts[:release_notes] }) sources << { type: :inline, keys: ['whats_new'] } end [overrides, sources] end def (path) = File.(path) raise MetadataFileError, "Metadata file not found: #{}" unless File.exist?() && File.file?() content = File.read() parsed = (content, ) raise MetadataFileError, 'Metadata file must contain a JSON/YAML object at the top level' unless parsed.is_a?(Hash) stringify_keys(parsed) rescue Errno::EACCES => e raise MetadataFileError, "Cannot read metadata file #{}: #{e.}" end def (content, path) stripped = content.lstrip begin return YAML.safe_load(content, aliases: true) || {} if stripped.start_with?('---') || stripped.start_with?('- ') JSON.parse(content) rescue JSON::ParserError begin YAML.safe_load(content, aliases: true) || {} rescue Psych::Exception => e raise MetadataFileError, "Failed to parse metadata file #{path}: #{e.}" end rescue Psych::Exception => e raise MetadataFileError, "Failed to parse metadata file #{path}: #{e.}" end end def deep_merge_hashes(base, overrides) base = stringify_keys(base || {}) overrides = stringify_keys(overrides || {}) merged = base.dup overrides.each do |key, value| merged[key] = if merged[key].is_a?(Hash) && value.is_a?(Hash) deep_merge_hashes(merged[key], value) else value end end merged end def (hash, prefix = nil, acc = []) hash.each do |key, value| current = prefix ? "#{prefix}.#{key}" : key if value.is_a?(Hash) (value, current, acc) else acc << current end end acc end def stringify_keys(object) case object when Hash object.each_with_object({}) do |(k, v), memo| memo[k.to_s] = stringify_keys(v) end when Array object.map { |item| stringify_keys(item) } else object end end def report_automation_outcome(result, override_sources) return unless result.is_a?(Hash) wait = result[:wait] || {} if wait[:enabled] timeout_seconds = wait[:timeout_seconds] || Upload::AppStoreAutomation::DEFAULT_WAIT_TIMEOUT timeout_str = format_duration(timeout_seconds) say " ASC Polling: every #{wait[:poll_seconds]}s (timeout #{timeout_str})" if wait[:timed_out] say " ⚠️ Build still processing after #{format_duration(wait[:elapsed_seconds])}", :yellow elsif wait[:elapsed_seconds].to_i.positive? say " ASC Polling: completed in #{format_duration(wait[:elapsed_seconds])}" end else say ' ASC Polling: skipped (--no-wait)', :yellow end if result[:submitted] say " Submission: sent via #{result[:submission_source]}", :green elsif result[:skip_reason] say " Submission: skipped (#{result[:skip_reason]})", :yellow end override_sources.each do |source| keys = Array(source[:keys]).join(', ') case source[:type] when :inline say " Overrides: CLI flag#{" (#{keys})" unless keys.empty?}" when :file say " Overrides: #{File.basename(source[:path])}#{" (#{keys})" unless keys.empty?}" end end end end desc 'build', "Build .xcarchive only (advanced - most users should use 'ship')" method_option :configuration, aliases: '-c', default: 'Release', desc: 'Build configuration (Debug, Release, etc.)' method_option :target, aliases: '-t', desc: 'Target to build (auto-detect if not specified)' method_option :scheme, aliases: '-s', desc: 'Scheme to build (defaults to target name)' method_option :type, default: 'appstore', desc: 'Build type: development, adhoc, appstore, enterprise' method_option :team, desc: 'Development team ID (overrides project setting)' method_option :bundle_id, aliases: '-b', desc: 'Bundle ID (overrides project setting)' method_option :skip_extensions, type: :boolean, default: false, desc: 'Skip extension targets (useful when extensions are not configured)' def build config = load_config client = create_client(config) say '🔍 Detecting project...', :cyan say '' begin # Detect project project_info = Build::Detector.detect framework_label = case project_info[:framework] when :capacitor then 'Capacitor/Ionic' when :react_native then 'React Native' when :flutter then 'Flutter' else 'Native iOS' end say "✓ Found: #{File.basename(project_info[:path])} (#{framework_label})", :green say '' # Parse project parser = Build::Parser.new(project_info) # Check if this is a buildable app (not framework/library) main_product_type = parser.product_type unless %i[app unknown].include?(main_product_type) error "Cannot build #{main_product_type} projects for TestFlight" say '' say 'My Signer builds iOS/macOS/tvOS apps for distribution.', :yellow say "This project builds a #{main_product_type}, not an app.", :yellow say '' exit 1 end # Check for multiple apps and prompt user if needed if parser.has_multiple_apps? && ![:target] app_targets = parser.app_targets say 'Multiple apps found in project:', :yellow app_targets.each_with_index do |target, i| say " #{i + 1}. #{target.name}", :cyan end say '' choice = ask("Select app to build (1-#{app_targets.count}):", limited_to: (1..app_targets.count).map(&:to_s)) target_name = app_targets[choice.to_i - 1].name else target_name = [:target] || parser.main_target.name end say "🎯 Target: #{target_name}", :cyan # Show platform if not iOS platform = parser.target_platform(target_name) unless platform == :ios platform_label = platform.to_s.upcase say "📱 Platform: #{platform_label}", :cyan end # Show extensions if any if parser.has_extensions? ext_count = parser.extension_targets.count if [:skip_extensions] say "🧩 Extensions: #{ext_count} (will be SKIPPED - signing disabled)", :yellow else say "🧩 Extensions: #{ext_count} (will be included in build)", :cyan end end bundle_id = [:bundle_id] || parser.bundle_id(target_name, [:configuration]) # Validate bundle ID format if overridden if [:bundle_id] if bundle_id =~ /\$\(|\$\{/ error "Bundle ID cannot contain variables: #{bundle_id}" exit 1 elsif bundle_id !~ /^[a-zA-Z0-9.-]+$/ error "Invalid bundle ID format: #{bundle_id}" say 'Bundle IDs must contain only letters, numbers, hyphens, and periods', :yellow exit 1 end end say "📦 Bundle ID: #{bundle_id}#{' (overridden)' if [:bundle_id]}", :cyan say "⚙️ Configuration: #{[:configuration]}", :cyan # Check signing style sign_style = parser.code_sign_style(target_name, [:configuration]) say "🔐 Signing: #{sign_style || 'Not Set'}", :cyan # Auto-fetch team ID from API if not provided and project missing it team_id_to_use = [:team] project_team_id = parser.team_id(target_name, [:configuration]) if !team_id_to_use && (project_team_id.nil? || project_team_id.empty?) say '🔍 No team set in project, fetching from My Signer...', :yellow begin org_response = client.get("/api/v1/organizations/#{config.current_organization_id}") api_team_id = org_response.dig(:data, 'app_store_connect_team_id') || org_response['app_store_connect_team_id'] if api_team_id && !api_team_id.empty? team_id_to_use = api_team_id say "✓ Using team from My Signer: #{api_team_id}", :green else say '⚠️ No team ID configured in My Signer', :yellow end rescue StandardError => e say "⚠️ Failed to fetch team from API: #{e.}", :yellow end end say '' # Handle signing based on style if sign_style == 'Automatic' say 'ℹ️ Using Automatic signing (Xcode will manage profiles)', :yellow elsif sign_style == 'Manual' # Check if manual signing is already configured if parser.signing_configured?(target_name, [:configuration]) say 'ℹ️ Manual signing already configured, using existing settings', :yellow else say '⚠️ Manual signing enabled but not configured', :yellow say '🔐 Configuring manual signing via My Signer API...', :cyan configurator = Build::Configurator.new(parser, client, config.current_organization_id) build_type = [:type].to_sym profile = configurator.configure!(target_name, [:configuration], build_type: build_type) say "✓ Configured with profile: #{profile['name']}", :green end else # No signing style set, default to automatic signing for simplicity say 'ℹ️ No signing style set, defaulting to Automatic signing', :yellow say 'ℹ️ Xcode will manage profiles automatically', :yellow say '' say '💡 To use Manual signing instead, run: mysigner signing configure', :cyan end say '' # Pre-build validation say '🔍 Validating signing setup...', :cyan validator = Signing::Validator.new(parser, target_name, [:configuration], team_id: team_id_to_use) validator.validate! # Build executor = Build::Executor.new(project_info, parser) archive_path = executor.build!( target_name, [:configuration], scheme: [:scheme], signing_style: sign_style, team_id: team_id_to_use, bundle_id: [:bundle_id], skip_extensions: [:skip_extensions] ) say '' say '=' * 80, :green say '✓ Build succeeded!', :green say '=' * 80, :green say '' say "📦 Archive: #{archive_path}", :cyan say '' say 'Next steps:', :bold say " mysigner export #{archive_path}" say ' mysigner ship testflight' say '' rescue Build::Detector::NoProjectError => e error e. say '' say 'Supported project types:', :yellow say ' - Native iOS (.xcodeproj, .xcworkspace)' say ' - Capacitor/Ionic (ionic project with ios/ folder)' say ' - React Native (RN project with ios/ folder)' say ' - Flutter (flutter project with ios/ folder)' exit 1 rescue Build::Configurator::ProfileNotFoundError => e error e. say '' say 'Try:', :yellow say ' mysigner profiles # List available profiles' say ' mysigner doctor # Auto-create or repair profiles' exit 1 rescue Build::Executor::BuildError => e # Analyze build errors and show helpful suggestions say '' if executor.respond_to?(:build_errors) require_relative '../build/error_analyzer' analyzer = Build::ErrorAnalyzer.new(executor.build_errors) say analyzer.format_suggestions, :cyan if analyzer.any_issues? end error e. exit 1 rescue StandardError => e error "Build failed: #{e.}" say '' say 'Full error:', :yellow say e. exit 1 end end desc 'export ARCHIVE_PATH', "Export .xcarchive to .ipa (advanced - most users should use 'ship')" method_option :method, type: :string, default: 'appstore', desc: 'Export method (appstore, adhoc, enterprise, development)' method_option :output, type: :string, desc: 'Output directory for .ipa file' def export(archive_path) load_config begin say '📦 My Signer - Export', :cyan say '=' * 80, :cyan say '' # Validate archive path unless File.exist?(archive_path) say "✗ Error: Archive not found: #{archive_path}", :red exit 1 end # Create exporter exporter = Export::Exporter.new( archive_path, output_dir: [:output] ) # Export method = [:method].to_sym ipa_path = exporter.export!( method: method, team_id: nil, signing_style: 'automatic' ) say '' say '=' * 80, :green say '✓ Export succeeded!', :green say '=' * 80, :green say '' say "📦 IPA: #{ipa_path}", :green say '' say 'Next steps:', :cyan say " mysigner upload testflight #{ipa_path}", :cyan say ' mysigner ship testflight', :cyan say '' rescue Export::Exporter::ExportError => e say '' say "✗ Error: #{e.}", :red exit 1 rescue StandardError => e say '' say "✗ Unexpected error: #{e.}", :red say e.backtrace.first(5).join("\n"), :red if ENV['DEBUG'] exit 1 end end desc 'upload testflight IPA_PATH', "Upload existing .ipa to TestFlight (advanced - most users should use 'ship')" method_option :wait, type: :boolean, default: false, desc: 'Wait for processing to complete' def upload(target, ipa_path) unless target == 'testflight' error "Only 'testflight' target is supported currently" say 'Usage: mysigner upload testflight IPA_PATH', :yellow exit 1 end config = load_config client = create_client(config) begin say '☁️ My Signer - Upload to TestFlight', :cyan say '=' * 80, :cyan say '' # Validate IPA path unless File.exist?(ipa_path) say "✗ Error: IPA file not found: #{ipa_path}", :red exit 1 end if ENV['MYSIGNER_USE_LEGACY_ASC'] == '1' # LEGACY PATH — altool with server-fetched .p8. Will be removed in next release. say '⚠️ MYSIGNER_USE_LEGACY_ASC=1 — using legacy altool upload path (deprecated).', :yellow say '🔐 Fetching App Store Connect credentials...', :yellow begin org_response = client.get("/api/v1/organizations/#{config.current_organization_id}") org_data = org_response[:data] unless org_data['app_store_connect_configured'] say '' say '✗ App Store Connect credentials not configured', :red say '' say 'Quick fix:', :cyan say ' mysigner doctor # Auto-configure now', :green say '' say 'Or manually:', :cyan say ' 1. Run: mysigner onboard' say ' 2. Follow Step 5 to add credentials' say '' exit 1 end api_key = org_data['app_store_connect_key_id'] api_issuer = org_data['app_store_connect_issuer_id'] private_key = org_data['app_store_connect_private_key'] unless api_key && api_issuer && private_key say '✗ Error: Invalid credentials received from API', :red exit 1 end say '✓ Credentials loaded', :green say '' rescue Mysigner::ClientError => e say '' say "✗ Error fetching credentials: #{e.}", :red exit 1 end uploader = Upload::Uploader.new( ipa_path, api_key: api_key, api_issuer: api_issuer, private_key: private_key ) uploader.upload!(wait_for_processing: [:wait]) else # DEFAULT PATH — ASC REST Build Upload API. require_relative '../upload/asc_rest_uploader' ipa_info = Upload::Uploader.extract_ipa_info(ipa_path) bundle_id = ipa_info[:bundle_id] cf_version = ipa_info[:cf_bundle_version] || '1' cf_short = ipa_info[:cf_bundle_short_version_string] || '1.0' if bundle_id.nil? || bundle_id.empty? say '✗ Could not extract bundle identifier from IPA.', :red say ' Ensure the file is a valid iOS .ipa with a Payload/*.app/Info.plist.', :yellow exit 1 end app_response = client.get("/api/v1/organizations/#{config.current_organization_id}/apple_apps", params: { bundle_id: bundle_id }) app = Array(app_response.dig(:data, 'data', 'apps')).first unless app && app['id'] say "✗ App with bundle ID '#{bundle_id}' not found in MySigner.", :red say ' Run: mysigner sync ios', :yellow exit 1 end say "📤 Uploading #{File.basename(ipa_path)} via App Store Connect REST API (version #{cf_short} build #{cf_version})...", :cyan rest = Mysigner::Upload::AscRestUploader.new( client: client, organization_id: config.current_organization_id, ipa_path: ipa_path, apple_app_id: app['id'], cf_bundle_version: cf_version, cf_bundle_short_version_string: cf_short, platform: 'IOS' ) result = rest.call case result[:final_state] when 'COMPLETE' say '✓ Upload complete — Apple accepted the build', :green when 'FAILED', 'INVALIDATED' say "✗ Apple rejected the upload: #{result[:final_state]}", :red exit 1 when 'TIMEOUT' say '⚠ Apple is still processing — check App Store Connect.', :yellow end end say '🎉 Upload complete!', :green say '' say 'Next steps:', :cyan say ' • Open App Store Connect to see your build' say ' • Wait for processing (5-15 minutes)' say ' • Distribute to TestFlight testers' say '' rescue Upload::Uploader::TransporterNotFoundError => e say '' say "✗ Error: #{e.}", :red exit 1 rescue Upload::Uploader::UploadError => e say '' say "✗ Upload Error: #{e.}", :red exit 1 rescue Mysigner::Upload::AscRestUploader::BuildVersionConflictError => e say '' say "✗ #{e.}", :red say '' exit 1 rescue StandardError => e say '' say "✗ Unexpected error: #{e.}", :red say e.backtrace.first(5).join("\n"), :red if ENV['DEBUG'] exit 1 end end desc 'submit [TRACK]', '📤 Submit existing build for store review (no upload)' long_desc <<~DESC Submit an existing build for review without building/uploading. iOS (App Store): mysigner submit # Submit latest iOS build mysigner submit --bundle-id com.app.id # Specify bundle ID mysigner submit --build-number 12 # Submit specific build Android (Google Play): mysigner submit production --platform android # Promote to production mysigner submit beta --platform android # Promote to beta track ANDROID TRACKS (optional argument): internal : Move to internal testing alpha : Move to closed testing (alpha) beta : Move to open testing (beta) production : Move to production iOS OPTIONS: --bundle-id ID Specify bundle ID (auto-detect from project if not provided) --build-number NUM Submit specific build number (defaults to latest) --version STRING Create version with specific version string ANDROID OPTIONS: --package-name PKG Android package name --version-code NUM Specific version code to promote --release-notes TEXT Release notes for the track COMMON OPTIONS: --platform ios or android (auto-detect if not specified) DESC method_option :bundle_id, aliases: '-b', desc: 'Bundle ID (auto-detect from project)' method_option :build_number, type: :string, desc: 'Specific build number to submit' method_option :version, type: :string, desc: 'Version string for App Store version' method_option :whats_new, type: :string, banner: 'TEXT', desc: "What's New text (required for submission)" method_option :support_url, type: :string, banner: 'URL', desc: 'Support URL (required for submission)' method_option :marketing_url, type: :string, banner: 'URL', desc: 'Marketing URL (optional)' method_option :privacy_url, type: :string, banner: 'URL', desc: 'Privacy Policy URL (optional)' method_option :release_type, type: :string, enum: %w[AFTER_APPROVAL MANUAL SCHEDULED], desc: 'Release type: AFTER_APPROVAL (auto-release), MANUAL (hold for manual release), or SCHEDULED' method_option :scheduled_date, type: :string, banner: 'ISO8601', desc: 'Scheduled release date (ISO 8601 format, e.g., 2026-02-01T10:00:00Z). Required when --release-type=SCHEDULED' method_option :platform, type: :string, desc: 'Platform: ios or android' method_option :package_name, type: :string, desc: 'Android package name' method_option :version_code, type: :string, desc: 'Android version code to promote' method_option :release_notes, type: :string, desc: 'Release notes for Android' method_option :auto_submit, type: :boolean, desc: 'Submit for review. Defaults to dashboard CLI Defaults, else true. Use --no-auto-submit to skip.' def submit(track = nil) config = load_config client = create_client(config) # Determine platform android_tracks = %w[internal alpha beta production] platform = [:platform]&.to_sym # Auto-detect platform from track argument or option if platform.nil? platform = if track && android_tracks.include?(track) :android else :ios end end # Route to Android submit if needed if platform == :android submit_android(track || 'production') return end # iOS submit flow continues below... say '📤 Submit for App Store Review', :cyan say '=' * 80, :cyan say '' # Get bundle ID from project or option bundle_id = [:bundle_id] unless bundle_id begin project_info = Build::Detector.detect parser = Build::Parser.new(project_info) target_name = parser.main_target.name bundle_id = parser.bundle_id(target_name, 'Release') say "✓ Detected bundle ID from project: #{bundle_id}", :green rescue StandardError error 'Could not detect bundle ID from project' say '' say 'Please specify manually:', :yellow say ' mysigner submit --bundle-id com.your.app.id', :cyan exit 1 end end say '' say "📱 Bundle ID: #{bundle_id}", :cyan say '' begin require_relative '../upload/app_store_submission' require_relative '../upload/app_store_automation' automation = Upload::AppStoreAutomation.new( client: client, organization_id: config.current_organization_id, opts: { wait: false, # No need to wait - only using already-processed builds no_submit: false, # `mysigner submit` without --auto-submit/--no-auto-submit # defaults to submitting; cli_defaults.auto_submit=false can # still suppress it. default_submit: true } ) # Get version from project or option version_string = [:version] unless version_string begin project_info ||= Build::Detector.detect parser ||= Build::Parser.new(project_info) target_name ||= parser.main_target.name version_string = parser.build_settings(target_name, 'Release')['MARKETING_VERSION'] rescue StandardError version_string = nil end end build_info = { bundle_id: bundle_id, version: version_string || '1.0', build_number: [:build_number] } # `mysigner submit` defaults to submitting (see AppStoreAutomation # opts[:default_submit]=true above) but no longer hard-clobbers # the user's dashboard `cli_defaults.auto_submit = false`. # Precedence: --auto-submit flag > cli_defaults > command default. = {} override_keys = [] if .key?(:auto_submit) ['auto_submit'] = [:auto_submit] override_keys << 'auto_submit' end if [:whats_new] ['whats_new'] = [:whats_new] override_keys << 'whats_new' end if [:support_url] ['support_url'] = [:support_url] override_keys << 'support_url' end if [:marketing_url] ['marketing_url'] = [:marketing_url] override_keys << 'marketing_url' end if [:privacy_url] ['privacy_policy_url'] = [:privacy_url] override_keys << 'privacy_policy_url' end if [:release_type] # Validate release_type valid_types = %w[AFTER_APPROVAL MANUAL SCHEDULED] rt = [:release_type].upcase unless valid_types.include?(rt) error "Invalid release type: #{[:release_type]}" say "Valid options: #{valid_types.join(', ')}", :yellow exit 1 end ['release_type'] = rt override_keys << 'release_type' # Validate scheduled_date is provided when SCHEDULED if rt == 'SCHEDULED' && ![:scheduled_date] error 'Scheduled release date is required when --release-type=SCHEDULED' say 'Use: --scheduled-date 2026-02-01T10:00:00Z', :yellow exit 1 end end if [:scheduled_date] begin parsed_date = Time.parse([:scheduled_date]) if parsed_date < Time.now + 3600 # At least 1 hour in the future error 'Scheduled date must be at least 1 hour in the future' exit 1 end ['earliest_release_date'] = parsed_date.utc.iso8601 override_keys << 'earliest_release_date' # Auto-set release_type to SCHEDULED if not already set unless ['release_type'] ['release_type'] = 'SCHEDULED' override_keys << 'release_type' end rescue ArgumentError => e error "Invalid date format: #{[:scheduled_date]}" say 'Use ISO 8601 format, e.g., 2026-02-01T10:00:00Z', :yellow exit 1 end end submission = Upload::AppStoreSubmission.new( client, config.current_organization_id, build_info, metadata_overrides: , override_sources: [{ type: :inline, keys: override_keys }] ) result = submission.submit_for_review!(automation: automation) say '' say '=' * 80, :green say '✓ Submission Complete!', :green say '=' * 80, :green say '' if result[:automation][:submitted] say '🎉 Your app is submitted for App Store review!', :green say '' say 'Monitor status:', :cyan say ' https://appstoreconnect.apple.com/apps', :green else say "⚠️ Submission skipped: #{result[:automation][:skip_reason]}", :yellow end say '' rescue Upload::AppStoreAutomation::AutomationError => e # Use enhanced error handler for App Store automation errors handle_apple_api_error(e, context: { title: 'Submission Failed', bundle_id: [:bundle_id] }) exit 1 rescue Mysigner::ClientError => e # Handle API client errors with actionable suggestions handle_apple_api_error(e, context: { title: 'API Error' }) exit 1 rescue StandardError => e say '' say '=' * 80, :red say '✗ Submission Failed', :red say '=' * 80, :red say '' say "Error: #{e.}", :red say '' # Try to show actionable suggestions for unknown errors show_actionable_suggestions(e., platform: :ios) show_debug_info(e) if ENV['DEBUG'] exit 1 end end desc 'signing configure', '🧙 Wizard: Configure manual code signing in your Xcode project' long_desc <<~DESC Guides you through setting up manual code signing for your project: 1. Detects your project and targets 2. Shows current signing configuration 3. Helps you select team ID and provisioning profile 4. Applies configuration to your Xcode project 5. Validates the setup This is useful when automatic signing doesn't work or you need specific profiles. OPTIONS: --target NAME Configure specific target only --all-targets Configure all app and extension targets EXAMPLES: mysigner signing configure # Configure main app (auto-detect) mysigner signing configure --target MyWidget # Configure specific target mysigner signing configure --all-targets # Configure all targets DESC method_option :target, aliases: '-t', desc: 'Target name to configure' method_option :all_targets, type: :boolean, default: false, desc: 'Configure all targets' def signing(action) unless action == 'configure' error "Unknown action: #{action}" say 'Usage: mysigner signing configure', :yellow exit 1 end config = load_config unless config.api_token error "Not logged in. Please run 'mysigner login' or 'mysigner onboard' first." exit 1 end client = create_client(config) begin # Detect project project_info = Build::Detector.detect parser = Build::Parser.new(project_info) # Validate options if [:target] && [:all_targets] error 'Cannot use both --target and --all-targets' exit 1 end # Check current signing style target_name = [:target] || parser.main_target.name signing_style = parser.code_sign_style(target_name) if signing_style == 'Automatic' say '⚠️ Project uses Automatic signing', :yellow say '' say 'Your project is configured for Automatic signing, which means:', :cyan say ' • Xcode manages profiles automatically' say ' • No manual profile configuration needed' say ' • Team ID is all you need' say '' say "Current Team ID: #{parser.team_id(target_name) || '(not set)'}", :green say '' say 'You can build with: mysigner build' say '' say '💡 To convert to Manual signing, use: mysigner signing configure --force-manual' return end # Run wizard for Manual signing require_relative '../signing/wizard' = { target: [:target], all_targets: [:all_targets] } wizard = Signing::Wizard.new(parser, client, config.current_organization_id, ) wizard.run! rescue Build::Detector::NoProjectError => e error e. exit 1 rescue Signing::Wizard::WizardError => e error "Wizard failed: #{e.}" exit 1 rescue StandardError => e error "Unexpected error: #{e.}" say e.backtrace.first(5).join("\n"), :red if ENV['DEBUG'] exit 1 end end end end |