Fastfile (7083B)
1 require "tmpdir" 2 3 default_platform(:ios) 4 5 # Developer account (team CM5RQKJH56); the App Store Connect key comes from the environment (~/.zshrc_build on the build Mac). 6 APP_ID = "org.schurger.subrascasse" 7 8 def api_key 9 app_store_connect_api_key( 10 key_id: ENV["PERSO_ASC_KEY_ID"], 11 issuer_id: ENV["PERSO_ASC_ISSUER_ID"], 12 key_filepath: ENV["PERSO_ASC_KEY_PATH"], 13 ) 14 end 15 16 def xcode_auth 17 [ 18 "-allowProvisioningUpdates", 19 "-authenticationKeyPath", ENV["PERSO_ASC_KEY_PATH"], 20 "-authenticationKeyID", ENV["PERSO_ASC_KEY_ID"], 21 "-authenticationKeyIssuerID", ENV["PERSO_ASC_ISSUER_ID"], 22 ] 23 end 24 25 platform :ios do 26 def asc(method, path, body = nil) 27 require "net/http" 28 uri = URI(path.start_with?("http") ? path : "https://api.appstoreconnect.apple.com#{path}") 29 klass = { get: Net::HTTP::Get, post: Net::HTTP::Post, patch: Net::HTTP::Patch }[method] 30 req = klass.new(uri, "Content-Type" => "application/json", "Authorization" => "Bearer #{Spaceship::ConnectAPI.token.text}") 31 req.body = body.to_json if body 32 res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |h| h.request(req) } 33 [res.code.to_i, (JSON.parse(res.body) rescue {})] 34 end 35 36 desc "Turns the iCloud capability on for the app identifier (the iCloud container itself is assigned in the developer portal)" 37 lane :icloud_setup do 38 api_key 39 _, found = asc(:get, "/v1/bundleIds?filter[identifier]=#{APP_ID}&include=bundleIdCapabilities") 40 bundle = found["data"].find { |b| b["attributes"]["identifier"] == APP_ID } or UI.user_error!("No bundle identifier #{APP_ID}") 41 capabilities = (found["included"] || []).map { |c| c["attributes"]["capabilityType"] } 42 UI.message("CAPABILITIES #{capabilities.sort.join(", ")}") 43 unless capabilities.include?("ICLOUD") 44 c, r = asc(:post, "/v1/bundleIdCapabilities", { data: { type: "bundleIdCapabilities", 45 attributes: { capabilityType: "ICLOUD", settings: [{ key: "ICLOUD_VERSION", options: [{ key: "XCODE_6" }] }] }, 46 relationships: { bundleId: { data: { type: "bundleIds", id: bundle["id"] } } } } }) 47 UI.message("ICLOUD -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}") 48 end 49 end 50 51 desc "Internal tester group, TestFlight texts and notes of the latest build" 52 lane :beta_setup do 53 api_key 54 app = Spaceship::ConnectAPI::App.find(APP_ID) 55 _, groups = asc(:get, "/v1/apps/#{app.id}/betaGroups") 56 group = groups["data"].find { |g| g["attributes"]["name"] == "Interne" } 57 unless group 58 # Raw POST: spaceship sends publicLinkLimitEnabled, which is refused for an internal group. 59 c, r = asc(:post, "/v1/betaGroups", { data: { type: "betaGroups", 60 attributes: { name: "Interne", isInternalGroup: true, hasAccessToAllBuilds: true }, 61 relationships: { app: { data: { type: "apps", id: app.id } } } } }) 62 UI.message("GROUP Interne -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}") 63 group = r["data"] 64 end 65 # The internal tester comes from the build machine's environment, never from the repository. 66 email = ENV["PERSO_APPLE_ID"] or UI.user_error!("PERSO_APPLE_ID is not set") 67 first_name = ENV["PERSO_FIRST_NAME"] || "Internal" 68 last_name = ENV["PERSO_LAST_NAME"] || "Tester" 69 _, testers = asc(:get, "/v1/betaTesters?filter[email]=#{email}&filter[apps]=#{app.id}") 70 if testers["data"].empty? 71 c, r = asc(:post, "/v1/betaTesters", { data: { type: "betaTesters", attributes: { email: email, firstName: first_name, lastName: last_name }, 72 relationships: { betaGroups: { data: [{ type: "betaGroups", id: group["id"] }] } } } }) 73 UI.message("TESTER #{email} -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}") 74 else 75 UI.message("TESTER #{email} already there") 76 end 77 texts = { 78 "fr-CA" => ["Votre carnet de plongée sur iPhone : profils, modification hors ligne, ordinateur de plongée en Bluetooth, synchronisation facultative avec le nuage Subsurface, sauvegarde iCloud. Application indépendante de l'équipe de Subsurface.", 79 "0.11 : Nouveau dans Planification, Décompression : (1) Plans enregistrés : donner un nom à un plan, le rouvrir, le dupliquer, le renommer ; ils partent dans la sauvegarde iCloud. (2) Imprimer ou partager : une page PDF avec la table des temps, les gaz, le gaz minimum et le profil, par la feuille de partage (AirPrint, Fichiers...). (3) Les plans enregistrés dans le carnet portent une étiquette Plan et ne comptent plus dans les statistiques ni dans les plongées précédentes. Corrigé : le remplissage du profil du plan."], 80 "en-CA" => ["Your dive log on iPhone: profiles, offline editing, dive computer over Bluetooth, optional sync with Subsurface cloud storage, iCloud backup. Independent from the Subsurface team.", 81 "0.11: New in Planning, Decompression: (1) Saved plans: name a plan, reopen it, duplicate it, rename it; they go to the iCloud backup. (2) Print or share: a PDF page with the run time table, the gases, the minimum gas and the profile, through the share sheet (AirPrint, Files...). (3) Plans saved in the logbook carry a Plan tag and no longer count in the statistics or as earlier dives. Fixed: the fill of the plan profile."], 82 } 83 _, locs = asc(:get, "/v1/apps/#{app.id}/betaAppLocalizations") 84 texts.each do |locale, (description, _)| 85 existing = locs["data"].find { |l| l["attributes"]["locale"] == locale } 86 attrs = { description: description, feedbackEmail: email } 87 c, r = if existing 88 asc(:patch, "/v1/betaAppLocalizations/#{existing["id"]}", { data: { type: "betaAppLocalizations", id: existing["id"], attributes: attrs } }) 89 else 90 asc(:post, "/v1/betaAppLocalizations", { data: { type: "betaAppLocalizations", attributes: attrs.merge(locale: locale), 91 relationships: { app: { data: { type: "apps", id: app.id } } } } }) 92 end 93 UI.message("BETA #{locale} -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}") 94 end 95 _, builds = asc(:get, "/v1/builds?filter[app]=#{app.id}&sort=-uploadedDate&limit=1") 96 build = builds["data"].first 97 UI.user_error!("No build visible yet") unless build 98 UI.message("BUILD #{build["attributes"]["version"]} #{build["attributes"]["processingState"]}") 99 _, blocs = asc(:get, "/v1/builds/#{build["id"]}/betaBuildLocalizations") 100 texts.each do |locale, (_, what)| 101 existing = blocs["data"].find { |l| l["attributes"]["locale"] == locale } 102 c, r = if existing 103 asc(:patch, "/v1/betaBuildLocalizations/#{existing["id"]}", { data: { type: "betaBuildLocalizations", id: existing["id"], attributes: { whatsNew: what } } }) 104 else 105 asc(:post, "/v1/betaBuildLocalizations", { data: { type: "betaBuildLocalizations", attributes: { locale: locale, whatsNew: what }, 106 relationships: { build: { data: { type: "builds", id: build["id"] } } } } }) 107 end 108 UI.message("WHAT TO TEST #{locale} -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}") 109 end 110 end 111 end