diff --git a/.circleci/config.yml b/.circleci/config.yml index b504cc3588..455ed3dbc8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -345,7 +345,7 @@ jobs: steps: - run: name: Run create_snapshot_pr - command: bundle exec fastlane create_snapshot_pr version:"revenuecatui-15" + command: bundle exec fastlane create_snapshots_repo_pr version:"revenuecatui-15" - compress_result_bundle: directory: fastlane/test_output bundle_name: revenuecatui @@ -375,7 +375,7 @@ jobs: steps: - run: name: Run create_snapshot_pr - command: bundle exec fastlane create_snapshot_pr version:"revenuecatui-16" + command: bundle exec fastlane create_snapshots_repo_pr version:"revenuecatui-16" - compress_result_bundle: directory: fastlane/test_output bundle_name: revenuecatui @@ -404,7 +404,7 @@ jobs: steps: - run: name: Run create_snapshot_pr - command: bundle exec fastlane create_snapshot_pr version:"revenuecatui-17" + command: bundle exec fastlane create_snapshots_repo_pr version:"revenuecatui-17" - compress_result_bundle: directory: fastlane/test_output bundle_name: revenuecatui diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 28e378c5ed..170ea94174 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -427,42 +427,63 @@ platform :ios do # Make request headers = {"Circle-Token": circle_token, "Content-Type": "application/json", "Accept": "application/json"} data = {parameters: {options[:pipeline] => true}, branch: branch} - url = "https://circleci.com/api/v2/project/github/RevenueCat/purchases-ios/pipeline" + url = "https://circleci.com/api/v2/project/github/RevenueCat/#{repo_name}/pipeline" resp = RestClient.post url, data.to_json, headers # Print workflow url number = JSON.parse(resp.body)["number"] - workflow_url = "https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/#{number}" + workflow_url = "https://app.circleci.com/pipelines/github/RevenueCat/#{repo_name}/#{number}" UI.important "Workflow: #{workflow_url}" end desc "Creates a new PR after new snapshot files were generated" lane :create_snapshot_pr do |options| - version = options[:version] - base_branch = ENV["CIRCLE_BRANCH"] + push_snapshot_pr( + version: options[:version], + repo: "revenuecat/#{repo_name}", + base_branch: ENV["CIRCLE_BRANCH"], + files_to_add: "../*/__Snapshots__/*" + ) + end + + desc "Creates a new PR on purchases-ios-snapshots after new snapshot files were generated" + lane :create_snapshots_repo_pr do |options| + Dir.chdir("../Tests/#{snapshots_repo_name}") { |dir| + push_snapshot_pr( + version: options[:version], + repo: "revenuecat/#{snapshots_repo_name}", + base_branch: "main", + files_to_add: "." + ) + } + end + private_lane :push_snapshot_pr do |options| + version = options[:version] + base_branch = options[:base_branch] build_number = ENV["CIRCLE_BUILD_NUM"] branch_name = "generated_snapshots/#{base_branch}-#{build_number}-#{version}" - sh("git", "checkout", "-b", branch_name) - sh("git", "add", "../*/__Snapshots__/*") + sh("git", "checkout", "-b", branch_name) + sh("git", "add", options[:files_to_add]) + file_count = sh("git diff --cached --numstat | wc -l").strip.to_i if file_count == 0 UI.important("No files to be committed") else sh("git", "commit", "-m", "[skip ci] Generating new test snapshots") - push_to_git_remote + sh("git", "push", "origin", branch_name) circle_user = ENV["CIRCLE_USERNAME"] branch_link = "https://github.com/RevenueCat/purchases-ios/tree/#{base_branch}" body = "Requested by @#{circle_user} for [#{base_branch}](#{branch_link})" create_pull_request( - repo: "revenuecat/purchases-ios", + repo: options[:repo], title: "Generating new test snapshots for `#{base_branch}` - #{version}", body: body, base: base_branch, diff --git a/fastlane/README.md b/fastlane/README.md index c3393a9d61..9f6bc3f63a 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -250,6 +250,14 @@ Trigger CircleCI job to generate snapshots for RevenueCatUI Creates a new PR after new snapshot files were generated +### ios create_snapshots_repo_pr + +```sh +[bundle exec] fastlane ios create_snapshots_repo_pr +``` + +Creates a new PR on purchases-ios-snapshots after new snapshot files were generated + ### ios compile_autogenerated_header ```sh