require 'json' PODSPEC_PATH = "AmplifyUtilsNotifications.podspec" CHANGELOG_PATH = "CHANGELOG.md" platform :ios do desc "Run all the tests on iOS" lane :tests do run_tests( clean: true, result_bundle: true, scheme: "AmplifyUtilsNotifications", package_path: ".", sdk: "iphonesimulator", device: "iPhone 14", ) end desc "Run integration test on iOS simulator" lane :integration_tests do run_tests( clean: true, include_simulator_logs: false, project: "./IntegrationTestApp/IntegrationTestApp.xcodeproj", scheme: "IntegrationTestApp", sdk: "iphonesimulator", device: "iPhone 14", ) end desc "Publish to Cocoapods whenever a new version tag is created" lane :release do sh('git', 'config', '--global', 'user.email', ENV['GITHUB_EMAIL']) sh('git', 'config', '--global', 'user.name', ENV['GITHUB_USER']) next_version, commits = calculate_next_release_version generate_version_bump_commit(version: next_version) generate_changelog_commit(version: next_version, commits: commits) create_new_version_tag(version: next_version) publish_to_cocoapod_trunk sync_up_main_release_branch end desc "Generate and publish documentaion for new version" lane :publish_doc do new_version = generate_doc git_add(path: "docs/*") git_commit(path: "docs/*", message: "chore: update API document for #{new_version} [skip ci]") push_to_git_remote( local_branch: "release", remote_branch: "gh-pages", tags: true, force: true, ) end desc "Generate jazzy documentaion" private_lane :generate_doc do pod_version = version_get_podspec(path: PODSPEC_PATH) jazzy(config: ".jazzy.yaml", module_version: pod_version) Dir.chdir('..') do sh('ln', '-s', '../readme-images', 'docs') end pod_version end desc "Generate commit for version bump" private_lane :generate_version_bump_commit do |options| next_version = options[:version] UI.user_error!("version shouldn't be nil") if next_version.nil? version_bump_podspec(path: PODSPEC_PATH, version_number: next_version) UI.message "Set version to: #{next_version}" git_add(path: PODSPEC_PATH) git_commit(path: PODSPEC_PATH, message: "chore: bump version to #{next_version} [skip ci]") end desc "Generate commit for changelog" private_lane :generate_changelog_commit do |options| next_version = options[:version] UI.user_error!("version shouldn't be nil") if next_version.nil? commits = options[:commits] UI.user_error!("commits shouldn't be nil") if commits.nil? changelog = build_changelog(version: next_version, commits: commits) write_changelog(changelog: changelog, path: CHANGELOG_PATH) git_add(path: CHANGELOG_PATH) git_commit(path: CHANGELOG_PATH, message: "changelog: update changelog for #{next_version} [skip ci]") end desc "Create new version tag after bump up version" private_lane :create_new_version_tag do |options| next_version = options[:version] UI.user_error!("version shouldn't be nil") if next_version.nil? add_git_tag(tag: next_version, grouping: nil, force: true) push_git_tags(tag: next_version, force: true) end desc "Publish new version to cocoapod trunck" private_lane :publish_to_cocoapod_trunk do # Define `COCOAPODS_TRUNK_TOKEN` env var for trunk authentication # https://github.com/CocoaPods/cocoapods-trunk/commit/9e6ec1c1faf96fa837dc2ed70b5f54006b181ed6 secret = sh( command: 'aws secretsmanager get-secret-value --secret-id ${COCOAPODS_SECRET_ARN}', log: false ) ENV['COCOAPODS_TRUNK_TOKEN'] = JSON.parse(secret)["SecretString"] pod_push( use_bundle_exec: true, allow_warnings: true, path: PODSPEC_PATH, ) end desc "Push commits and tags to remote branches" private_lane :sync_up_main_release_branch do push_to_git_remote( local_branch: "release", remote_branch: "release", ) # update main branch with release branch push_to_git_remote( local_branch: "release", remote_branch: "main", ) end end platform :mac do desc "Run all the tests on macOS" lane :tests do run_tests( clean: true, result_bundle: true, include_simulator_logs: false, scheme: "AmplifyUtilsNotifications", package_path: ".", sdk: "macosx", destination: "platform=macOS", ) end end platform :tvos do desc "Run all the tests on tvOS" lane :tests do run_tests( clean: true, result_bundle: true, include_simulator_logs: false, scheme: "AmplifyUtilsNotifications", package_path: ".", sdk: "appletvsimulator", destination: "platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest", ) end end platform :watchos do desc "Run all the tests on watchOS" lane :tests do run_tests( clean: true, result_bundle: true, include_simulator_logs: false, scheme: "AmplifyUtilsNotifications", package_path: ".", sdk: "watchsimulator", destination: "platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest", ) end end