open-remora

Open Remora, a free secondary dive computer for Apple Watch Ultra
git clone https://git.schurger.org/open-remora.git
Log | Files | Refs | README | LICENSE

Fastfile (5910B)


      1 require "tmpdir"
      2 
      3 default_platform(:ios)
      4 
      5 # Personal developer account (team CM5RQKJH56), App Store Connect key read from ~/.zshrc_build on chunga.
      6 APP_ID = "org.schurger.openremora"
      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 "Capabilities of the bundle identifiers (read-only): app group, HealthKit…"
     37   lane :capabilities do
     38     api_key
     39     %w[org.schurger.openremora org.schurger.openremora.watchkitapp org.schurger.subrascasse].each do |id|
     40       b = Spaceship::ConnectAPI::BundleId.find(id)
     41       next UI.message("CAPS #{id}: missing") unless b
     42       UI.message("CAPS #{id} (name \"#{b.name}\"): #{b.get_capabilities.map(&:capability_type).join(", ")}")
     43     end
     44   end
     45 
     46   desc "Internal tester group, TestFlight texts and notes for the latest build"
     47   lane :beta_setup do
     48     api_key
     49     app = Spaceship::ConnectAPI::App.find(APP_ID)
     50     _, groups = asc(:get, "/v1/apps/#{app.id}/betaGroups")
     51     group = groups["data"].find { |g| g["attributes"]["name"] == "Interne" }
     52     unless group
     53       # Raw POST: spaceship sends publicLinkLimitEnabled, which is refused for an internal group.
     54       c, r = asc(:post, "/v1/betaGroups", { data: { type: "betaGroups",
     55         attributes: { name: "Interne", isInternalGroup: true, hasAccessToAllBuilds: true },
     56         relationships: { app: { data: { type: "apps", id: app.id } } } } })
     57       UI.message("GROUP Interne -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}")
     58       group = r["data"]
     59     end
     60     email = ENV["PERSO_APPLE_ID"] || "jean@schurger.org"
     61     _, testers = asc(:get, "/v1/betaTesters?filter[email]=#{email}&filter[apps]=#{app.id}")
     62     if testers["data"].empty?
     63       c, r = asc(:post, "/v1/betaTesters", { data: { type: "betaTesters", attributes: { email: email, firstName: "Jean", lastName: "Schurger" },
     64         relationships: { betaGroups: { data: [{ type: "betaGroups", id: group["id"] }] } } } })
     65       UI.message("TESTER #{email} -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}")
     66     else
     67       UI.message("TESTER #{email} already present")
     68     end
     69     texts = {
     70       "fr-CA" => ["Ordinateur de plongée secondaire, libre et gratuit, pour Apple Watch Ultra. Non certifié : à porter avec un ordinateur principal.",
     71                   "0.3 : le temps sans palier s'appelle NDL à l'écran ; alarme de NDL réglable (Réglages → Alarme de NDL : désactivée, 3, 5, 10 ou 15 min) ; alarme = tout l'écran clignote en rouge et la montre vibre toutes les 2 s ; avertissement = seule la valeur concernée clignote, vibration rappelée toutes les 15 s. À essayer à sec : régler l'alarme de NDL sur 15 min puis lancer la plongée de démonstration."],
     72       "en-CA" => ["Free, open-source backup dive computer for Apple Watch Ultra. Not certified: wear it with a primary dive computer.",
     73                   "0.3: no-stop time is labelled NDL; adjustable NDL alarm (Réglages → Alarme de NDL: off, 3, 5, 10 or 15 min); alarm = the whole screen flashes red and the watch vibrates every 2 s; warning = only the affected value blinks, with a vibration repeated every 15 s. Try it dry: set the NDL alarm to 15 min, then run the demo dive."],
     74     }
     75     _, locs = asc(:get, "/v1/apps/#{app.id}/betaAppLocalizations")
     76     texts.each do |locale, (description, _)|
     77       existing = locs["data"].find { |l| l["attributes"]["locale"] == locale }
     78       attrs = { description: description, feedbackEmail: email }
     79       c, r = if existing
     80         asc(:patch, "/v1/betaAppLocalizations/#{existing["id"]}", { data: { type: "betaAppLocalizations", id: existing["id"], attributes: attrs } })
     81       else
     82         asc(:post, "/v1/betaAppLocalizations", { data: { type: "betaAppLocalizations", attributes: attrs.merge(locale: locale),
     83           relationships: { app: { data: { type: "apps", id: app.id } } } } })
     84       end
     85       UI.message("BETA #{locale} -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}")
     86     end
     87     _, builds = asc(:get, "/v1/builds?filter[app]=#{app.id}&sort=-uploadedDate&limit=1")
     88     build = builds["data"].first
     89     UI.user_error!("No build visible yet") unless build
     90     UI.message("BUILD #{build["attributes"]["version"]} #{build["attributes"]["processingState"]}")
     91     _, build_locs = asc(:get, "/v1/builds/#{build["id"]}/betaBuildLocalizations")
     92     texts.each do |locale, (_, what)|
     93       existing = build_locs["data"].find { |l| l["attributes"]["locale"] == locale }
     94       c, r = if existing
     95         asc(:patch, "/v1/betaBuildLocalizations/#{existing["id"]}", { data: { type: "betaBuildLocalizations", id: existing["id"], attributes: { whatsNew: what } } })
     96       else
     97         asc(:post, "/v1/betaBuildLocalizations", { data: { type: "betaBuildLocalizations", attributes: { locale: locale, whatsNew: what },
     98           relationships: { build: { data: { type: "builds", id: build["id"] } } } } })
     99       end
    100       UI.message("WHAT TO TEST #{locale} -> #{c} #{(r["errors"] || []).map { |e| e["detail"] }.join(" ; ")}")
    101     end
    102   end
    103 end