require "json" default_platform(:android) platform :android do aab_file = "./apps/readest-app/src-tauri/gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab" # Listing text and imagery live in fastlane/metadata-play, NOT fastlane/metadata: # metadata/android is F-Droid's (plain screenshots, app name "Readest"), while # Play gets the captioned composites and the keyword title. # NB: supply's metadata_path is the directory that CONTAINS the locale folders # (its default is ./fastlane/metadata/android), so the "android" level belongs # in the path. Pointing at metadata-play alone makes supply read "android" as a # locale and Google rejects the edit with "Invalid request". play_metadata_path = "./fastlane/metadata-play/android" desc "Upload AAB to Google Play Production" lane :upload_production do upload_to_play_store( aab: aab_file, track: "production", metadata_path: play_metadata_path, skip_upload_apk: true, skip_upload_metadata: false, skip_upload_images: false, skip_upload_screenshots: false, skip_upload_changelogs: false, # Without this supply ADDS images instead of replacing them, so a release # would leave the previous set on the listing alongside the new one and # push the phone screenshots past Play's limit of 8. With it, whatever is # in metadata-play is exactly what the listing ends up with. sync_image_upload: true ) end # The internal and beta lanes deliberately keep skip_upload_metadata/images/ # screenshots on. Play's listing text and imagery are store-level, not # track-level, so uploading them from a test track would rewrite the live # production listing. Only upload_production may touch the listing. desc "Upload AAB to Google Play Internal Testing" lane :upload_internal do upload_to_play_store( aab: aab_file, track: "internal", skip_upload_apk: true, skip_upload_metadata: true, skip_upload_images: true, skip_upload_screenshots: true, skip_upload_changelogs: true ) end desc "Upload AAB to Google Play Beta" lane :upload_beta do upload_to_play_store( aab: aab_file, track: "beta", skip_upload_apk: true, skip_upload_metadata: true, skip_upload_images: true, skip_upload_screenshots: true, skip_upload_changelogs: true ) end end # fastlane executes lanes from the ./fastlane folder, so paths are anchored to the # repo root (its parent) to stay independent of the caller's working directory. def repo_path(relative) File.expand_path(relative, File.expand_path("..", __dir__)) end def asc_api_key key_id = ENV["APPLE_API_KEY"] # Every Apple lane is normally invoked through a dotenv wrapper (see the # submit-appstore-* scripts). Called bare, key_id is nil and the derived path # becomes "AuthKey_.p8", which fails with a confusing missing-file error. if key_id.to_s.empty? || ENV["APPLE_API_ISSUER"].to_s.empty? UI.user_error!("APPLE_API_KEY / APPLE_API_ISSUER are not set. Load them first:\n" \ " set -a && source apps/readest-app/.env.apple-appstore.local && set +a") end # APPLE_API_KEY_PATH is deliberately kept OUT of the App Store build env: with the # full key_id/issuer/path trio present, `tauri build` notarizes the App Store binary, # which fails (App Store apps use an Apple Distribution cert, not Developer ID). # Derive the .p8 path from the key id (same convention altool uses); honor an # explicit APPLE_API_KEY_PATH when set (e.g. the iOS build env). app_store_connect_api_key( key_id: key_id, issuer_id: ENV["APPLE_API_ISSUER"], key_filepath: ENV["APPLE_API_KEY_PATH"] || repo_path("apps/readest-app/private_keys/AuthKey_#{key_id}.p8"), ) end # Release notes from the latest version in release-notes.json, excluding notes # that mention Android, Windows, or Linux. Used for both the TestFlight changelog # and the App Store "What's New" text. def release_notes_text releases = JSON.parse(File.read(repo_path("apps/readest-app/release-notes.json")))["releases"] latest = releases.keys.max_by { |version| Gem::Version.new(version) } releases[latest]["notes"] .reject { |note| note =~ /\b(?:Android|Windows|Linux)\b/i } .map { |note| "– #{note}" } .join("\n") end # App Store "Promotional Text" (editable without a review). Passed inline, so it # wins over any promotional_text.txt in the metadata folder. PROMOTIONAL_TEXT = "Experience the Ultimate Ebook Reader Across All Your Devices for Avid Readers" PROMOTIONAL_TEXT_MACOS = "Every Book You Own, Open on Your Mac. Read, Annotate, Listen and Sync Across Devices" # iOS and macOS are one App Store Connect app (com.bilingify.readest), built from # separate binaries and submitted independently. Each lane acts only on a build # already uploaded by altool (skip_binary_upload / distribute_only) — it never # builds or uploads a binary. For its platform it submits the build for App Store # review AND distributes it to TestFlight. The App Store submit runs first because # it waits for build processing, which the TestFlight distribute then relies on. # pnpm run submit-appstore-ios # iOS # pnpm run submit-appstore-macos # macOS def submit_apple_build(deliver_opts, testflight_opts) api_key = asc_api_key upload_to_app_store({ api_key: api_key, app_identifier: "com.bilingify.readest", skip_binary_upload: true, # use the altool-uploaded build; read version from the binary submit_for_review: true, automatic_release: true, force: true, # skip the HTML metadata preview prompt # App Store screenshots (iOS and macOS) are uploaded by hand in App Store # Connect, so no lane touches them. The masters live in fastlane/screenshots # for reference only. Note if this is ever automated: iOS and macOS share one # App Store Connect record but NOT one screenshot set, and deliver types a # screenshot purely by pixel size — so a single screenshots_path would try to # attach iPhone images to the Mac listing. skip_screenshots: true, # Uploads everything in the lane's metadata folder — name, subtitle, keywords # and description — plus the inline What's New and Promotional Text below. # (Before fastlane/metadata/en-US existed this only sent the two inline # fields and left the rest of App Store Connect untouched.) skip_metadata: false, release_notes: { "en-US" => release_notes_text }, promotional_text: { "en-US" => PROMOTIONAL_TEXT }, precheck_include_in_app_purchases: false, submission_information: { add_id_info_uses_idfa: false }, }.merge(deliver_opts)) upload_to_testflight({ api_key: api_key, app_identifier: "com.bilingify.readest", distribute_only: true, # use the already-uploaded build; do not upload distribute_external: true, groups: ["Beta Testers"], changelog: release_notes_text, }.merge(testflight_opts)) end desc "Submit the uploaded iOS build for App Store review and to TestFlight" lane :release_ios do submit_apple_build( { platform: "ios", ipa: repo_path("apps/readest-app/src-tauri/gen/apple/build/arm64/Readest.ipa") }, { app_platform: "ios" } ) end desc "Submit the uploaded macOS build for App Store review and to TestFlight" lane :release_macos do submit_apple_build( { platform: "osx", pkg: repo_path("target/universal-apple-darwin/release/bundle/macos/Readest.pkg"), # deliver's metadata_path has no platform dimension, so iOS and macOS would # otherwise receive identical text. The Mac listing leads with what only the # Mac has: multiple windows, keyboard shortcuts, the system dictionary. metadata_path: "./fastlane/metadata-macos", promotional_text: { "en-US" => PROMOTIONAL_TEXT_MACOS }, }, { app_platform: "osx" } ) end # Read-only: pull the CURRENTLY LIVE App Store screenshots into # fastlane/screenshots/. Nothing is uploaded. App Store screenshots are # managed by hand in App Store Connect, so this exists to compare the local # masters against what is actually published. # fastlane download_store_screenshots platform:osx # fastlane download_store_screenshots platform:ios desc "Download the live App Store screenshots for a platform (read-only)" lane :download_store_screenshots do |options| require "deliver" platform = (options[:platform] || "osx").to_s asc_api_key # also sets Spaceship::ConnectAPI.token Deliver.cache[:app] = Spaceship::ConnectAPI::App.find("com.bilingify.readest") dest = repo_path("fastlane/screenshots/#{platform}") FileUtils.mkdir_p(dest) Deliver::DownloadScreenshots.run({ platform: platform, use_live_version: true }, dest) end