diff --git a/ios/.env.example b/ios/.env.example new file mode 100644 index 0000000..51ccba4 --- /dev/null +++ b/ios/.env.example @@ -0,0 +1,20 @@ +FASTLANE_APP_IDENTIFIER=net.buzzert.sybil2 +FASTLANE_TEAM_ID=DQQH5H6GBD +FASTLANE_USER=you@example.com +FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=xxxx-xxxx-xxxx-xxxx +FASTLANE_SKIP_UPDATE_CHECK=1 +FASTLANE_HIDE_CHANGELOG=1 +SYBIL_APP_STORE_APPLE_ID=6759442828 +SYBIL_PROVIDER_PUBLIC_ID=c043d167-ad88-4036-84ea-76c223f1b1b2 + +# Optional App Store Connect API key settings for non-interactive upload and +# TestFlight build-number lookup. +APP_STORE_CONNECT_API_KEY_ID= +APP_STORE_CONNECT_API_ISSUER_ID= +APP_STORE_CONNECT_API_KEY_PATH= +APP_STORE_CONNECT_API_KEY_CONTENT= +APP_STORE_CONNECT_API_KEY_CONTENT_BASE64=false + +# Optional deployment overrides. +SYBIL_BUILD_NUMBER= +SYBIL_VERSION_TAG= diff --git a/ios/.gitignore b/ios/.gitignore index 574a5ff..c25f023 100644 --- a/ios/.gitignore +++ b/ios/.gitignore @@ -1,2 +1,11 @@ *.xcodeproj - +.env +.env.* +!.env.example +build/ +*.ipa +*.dSYM.zip +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/ +fastlane/test_output/ diff --git a/ios/Apps/Sybil/project.yml b/ios/Apps/Sybil/project.yml index 29cd8e0..4bfc36b 100644 --- a/ios/Apps/Sybil/project.yml +++ b/ios/Apps/Sybil/project.yml @@ -24,8 +24,8 @@ targets: GENERATE_INFOPLIST_FILE: YES INFOPLIST_FILE: Apps/Sybil/Info.plist ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon - MARKETING_VERSION: 1.9 - CURRENT_PROJECT_VERSION: 10 + MARKETING_VERSION: "1.10" + CURRENT_PROJECT_VERSION: 11 INFOPLIST_KEY_CFBundleDisplayName: Sybil INFOPLIST_KEY_ITSAppUsesNonExemptEncryption: NO INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents: YES diff --git a/ios/Gemfile b/ios/Gemfile new file mode 100644 index 0000000..81a4d85 --- /dev/null +++ b/ios/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gem "fastlane", "~> 2.227" diff --git a/ios/fastlane/Appfile b/ios/fastlane/Appfile new file mode 100644 index 0000000..6941f1b --- /dev/null +++ b/ios/fastlane/Appfile @@ -0,0 +1,9 @@ +require "dotenv" + +Dotenv.load(File.expand_path("../.env", __dir__)) + +app_identifier(ENV.fetch("FASTLANE_APP_IDENTIFIER", "net.buzzert.sybil2")) +team_id(ENV.fetch("FASTLANE_TEAM_ID", "DQQH5H6GBD")) + +apple_id(ENV["FASTLANE_USER"]) if ENV["FASTLANE_USER"].to_s.strip.length.positive? +itc_team_id(ENV["FASTLANE_ITC_TEAM_ID"]) if ENV["FASTLANE_ITC_TEAM_ID"].to_s.strip.length.positive? diff --git a/ios/fastlane/Fastfile b/ios/fastlane/Fastfile new file mode 100644 index 0000000..9e87fbc --- /dev/null +++ b/ios/fastlane/Fastfile @@ -0,0 +1,177 @@ +require "dotenv" +require "open3" +require "shellwords" +require "yaml" + +Dotenv.load(File.expand_path("../.env", __dir__)) + +default_platform(:ios) + +APP_IDENTIFIER = ENV.fetch("FASTLANE_APP_IDENTIFIER", "net.buzzert.sybil2") +TEAM_ID = ENV.fetch("FASTLANE_TEAM_ID", "DQQH5H6GBD") +APP_STORE_APPLE_ID = ENV.fetch("SYBIL_APP_STORE_APPLE_ID", "6759442828") +PROVIDER_PUBLIC_ID = ENV.fetch("SYBIL_PROVIDER_PUBLIC_ID", "c043d167-ad88-4036-84ea-76c223f1b1b2") +IOS_ROOT = File.expand_path("..", __dir__) +PROJECT_FILE = File.join(IOS_ROOT, "Sybil.xcodeproj") +PROJECT_SPEC = File.join(IOS_ROOT, "project.yml") +APP_SPEC = File.join(IOS_ROOT, "Apps/Sybil/project.yml") +SCHEME = "Sybil" +TARGET = "SybilApp" + +def present?(value) + !value.to_s.strip.empty? +end + +def capture(command) + stdout, stderr, status = Open3.capture3(command) + return stdout.strip if status.success? + + UI.user_error!("Command failed: #{command}\n#{stderr.strip}") +end + +def app_project_settings + YAML.safe_load(File.read(APP_SPEC)).fetch("targets").fetch(TARGET).fetch("settings").fetch("base") +end + +def local_marketing_version + app_project_settings.fetch("MARKETING_VERSION").to_s +end + +def local_build_number + app_project_settings.fetch("CURRENT_PROJECT_VERSION").to_i +end + +def normalize_version_tag(tag) + version = tag.to_s.strip.sub(/\Av/, "") + unless version.match?(/\A\d+\.\d+(\.\d+)?\z/) + UI.user_error!("Release tag #{tag.inspect} must look like v1.10 or v1.10.0") + end + version +end + +def release_version + tag = ENV["SYBIL_VERSION_TAG"] + tag = capture("git describe --tags --abbrev=0") unless present?(tag) + normalize_version_tag(tag) +end + +def xcode_build_setting(key, value) + "#{key}=#{value.to_s.shellescape}" +end + +def app_store_connect_key_options + key_id = ENV["APP_STORE_CONNECT_API_KEY_ID"] + issuer_id = ENV["APP_STORE_CONNECT_API_ISSUER_ID"] + return nil unless present?(key_id) && present?(issuer_id) + + key_path = ENV["APP_STORE_CONNECT_API_KEY_PATH"] + key_content = ENV["APP_STORE_CONNECT_API_KEY_CONTENT"] + if present?(key_path) + { + key_id: key_id, + issuer_id: issuer_id, + key_filepath: key_path + } + elsif present?(key_content) + { + key_id: key_id, + issuer_id: issuer_id, + key_content: key_content, + is_key_content_base64: ENV["APP_STORE_CONNECT_API_KEY_CONTENT_BASE64"].to_s == "true" + } + end +end + +platform :ios do + desc "Show the version Fastlane will stamp into the next TestFlight archive" + lane :version do + UI.message("Git tag version: #{release_version}") + UI.message("Checked-in app version: #{local_marketing_version}") + UI.message("Checked-in build number: #{local_build_number}") + end + + desc "Build Sybil and upload it to TestFlight" + lane :beta do + version = release_version + build_number = ENV["SYBIL_BUILD_NUMBER"].to_s + api_key = nil + + if app_store_connect_key_options + api_key = app_store_connect_api_key(app_store_connect_key_options) + end + + unless present?(build_number) + build_number = (local_build_number + 1).to_s + + if api_key + begin + latest = latest_testflight_build_number( + app_identifier: APP_IDENTIFIER, + version: version, + api_key: api_key, + initial_build_number: local_build_number + ).to_i + build_number = [latest + 1, local_build_number + 1].max.to_s + rescue StandardError => e + UI.important("Could not look up TestFlight build number: #{e.message}") + UI.important("Using checked-in build number + 1: #{build_number}") + end + end + end + + UI.user_error!("Build number must be a positive integer") unless build_number.match?(/\A[1-9]\d*\z/) + + sh("xcodegen --spec #{PROJECT_SPEC.shellescape}") + + xcode_args = [ + "-allowProvisioningUpdates", + xcode_build_setting("MARKETING_VERSION", version), + xcode_build_setting("CURRENT_PROJECT_VERSION", build_number) + ].join(" ") + + ipa_path = build_app( + project: PROJECT_FILE, + scheme: SCHEME, + clean: true, + sdk: "iphoneos", + export_method: "app-store", + output_directory: File.join(IOS_ROOT, "build/fastlane"), + output_name: "Sybil-#{version}-#{build_number}.ipa", + xcargs: xcode_args, + export_xcargs: "-allowProvisioningUpdates", + export_options: { + method: "app-store-connect", + destination: "export", + signingStyle: "automatic", + teamID: TEAM_ID, + manageAppVersionAndBuildNumber: false, + uploadSymbols: true, + stripSwiftSymbols: true + } + ) + + ipa_path ||= lane_context[SharedValues::IPA_OUTPUT_PATH] + UI.user_error!("IPA export failed; no IPA path was returned") unless present?(ipa_path) && File.exist?(ipa_path) + + password = ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] + UI.user_error!("FASTLANE_USER is required for altool upload") unless present?(ENV["FASTLANE_USER"]) + UI.user_error!("FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD is required for altool upload") unless present?(password) + UI.user_error!("SYBIL_APP_STORE_APPLE_ID is required for altool upload") unless present?(APP_STORE_APPLE_ID) + UI.user_error!("SYBIL_PROVIDER_PUBLIC_ID is required for altool upload") unless present?(PROVIDER_PUBLIC_ID) + + ENV["ITMS_TRANSPORTER_PASSWORD"] = password + sh([ + "xcrun altool", + "--upload-package #{ipa_path.shellescape}", + "--platform ios", + "--apple-id #{APP_STORE_APPLE_ID.shellescape}", + "--bundle-id #{APP_IDENTIFIER.shellescape}", + "--bundle-version #{build_number.shellescape}", + "--bundle-short-version-string #{version.shellescape}", + "--provider-public-id #{PROVIDER_PUBLIC_ID.shellescape}", + "--username #{ENV.fetch("FASTLANE_USER").shellescape}", + "--password @env:ITMS_TRANSPORTER_PASSWORD", + "--show-progress" + ].join(" ")) + end +end diff --git a/ios/fastlane/README.md b/ios/fastlane/README.md new file mode 100644 index 0000000..3679069 --- /dev/null +++ b/ios/fastlane/README.md @@ -0,0 +1,40 @@ +fastlane documentation +---- + +# Installation + +Make sure you have the latest version of the Xcode command line tools installed: + +```sh +xcode-select --install +``` + +For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane) + +# Available Actions + +## iOS + +### ios version + +```sh +[bundle exec] fastlane ios version +``` + +Show the version Fastlane will stamp into the next TestFlight archive + +### ios beta + +```sh +[bundle exec] fastlane ios beta +``` + +Build Sybil and upload it to TestFlight + +---- + +This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run. + +More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools). + +The documentation of _fastlane_ can be found on [docs.fastlane.tools](https://docs.fastlane.tools). diff --git a/ios/justfile b/ios/justfile index 8575b62..6e07e09 100644 --- a/ios/justfile +++ b/ios/justfile @@ -5,8 +5,10 @@ derived_data := "build/DerivedData" default: @just build -build: - if [ ! -d "Sybil.xcodeproj" ]; then xcodegen --spec project.yml; fi +generate: + xcodegen --spec project.yml + +build: generate if command -v xcbeautify >/dev/null 2>&1; then \ xcodebuild -scheme Sybil -destination '{{simulator}}' | xcbeautify; \ else \ @@ -16,13 +18,15 @@ build: test: cd Packages/Sybil && xcodebuild test -scheme Sybil -destination '{{simulator}}' -parallel-testing-enabled NO -run: - if [ ! -d "Sybil.xcodeproj" ]; then xcodegen --spec project.yml; fi +run: generate xcrun simctl boot '{{simulator_name}}' 2>/dev/null || true xcodebuild -scheme Sybil -destination '{{simulator}}' -derivedDataPath '{{derived_data}}' xcrun simctl install booted '{{derived_data}}/Build/Products/Debug-iphonesimulator/Sybil.app' xcrun simctl launch booted net.buzzert.sybil2 +beta: + fastlane ios beta + screenshot path="build/sybil-screenshot.png": mkdir -p "$(dirname '{{path}}')" xcrun simctl io booted screenshot '{{path}}'