From a762fdbc69dd3edcd747022c724747062adc4327 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 11 May 2023 13:34:37 +0300 Subject: [PATCH] Tag nightlies after a successful build (#871) * Tag nightlies after a successful build * Tweaks and fixes after code review --- ci_scripts/ci_post_xcodebuild.sh | 2 ++ fastlane/Fastfile | 48 ++++++++++++++++++++++++++------ fastlane/README.md | 8 ++++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/ci_scripts/ci_post_xcodebuild.sh b/ci_scripts/ci_post_xcodebuild.sh index efb5d663f..28ada53d8 100755 --- a/ci_scripts/ci_post_xcodebuild.sh +++ b/ci_scripts/ci_post_xcodebuild.sh @@ -9,6 +9,8 @@ if [ "$CI_WORKFLOW" = "Release" ]; then bundle exec fastlane release_to_github bundle exec fastlane prepare_next_release +elif [ "$CI_WORKFLOW" = "Nightly" ]; then + bundle exec fastlane tag_nightly build_number:"$CI_BUILD_NUMBER" fi # Upload dsyms no matter the workflow diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 8b1b43c95..bf2fd6539 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -222,9 +222,6 @@ lane :release_to_github do end lane :prepare_next_release do - api_token = ENV["GITHUB_TOKEN"] - UI.user_error!("Invalid GitHub API token.") unless !api_token.to_s.empty? - target_file_path = "../project.yml" xcode_project_file_path = "../ElementX.xcodeproj" @@ -238,17 +235,52 @@ lane :prepare_next_release do xcodegen(spec: "project.yml") - sh("git config --global user.name 'Element CI'") - sh("git config --global user.email 'ci@element.io'") + setup_git() sh("git add #{target_file_path} #{xcode_project_file_path}") sh("git commit -m 'Prepare next release'") - # Get repo url path, without `http` or `git@` prefixes - repo_url = sh("git ls-remote --get-url origin | sed 's#http://##g' | sed 's#https:\/\/##g' | sed 's#git@##g\'") + git_push() +end - # Use the access token for write access +lane :tag_nightly do |options| + build_number = options[:build_number] + UI.user_error!("Invalid build number.") unless !build_number.to_s.empty? + + xcodegen_project_file_path = "../project.yml" + data = YAML.load_file xcodegen_project_file_path + current_version = data["settings"]["MARKETING_VERSION"] + + setup_git() + + tag_name = "nightly/#{current_version}.#{build_number}" + sh("git tag #{tag_name}") + + git_push(tag_name: tag_name) +end + +private_lane :setup_git + sh("git config --global user.name 'Element CI'") + sh("git config --global user.email 'ci@element.io'") +end + +private_lane :git_push do |options| + # Use the Github API token for repo write access + api_token = ENV["GITHUB_TOKEN"] + UI.user_error!("Invalid GitHub API token.") unless !api_token.to_s.empty? + + # Get repo url path, without `http`, `https` or `git@` prefixes or `.git` suffix + repo_url = sh("git ls-remote --get-url origin | sed 's#http://##g' | sed 's#https:\/\/##g' | sed 's#git@##g' | sed 's#.git##g'") + + # This sometimes has a trailing newline + repo_url = repo_url.strip + + # Push the tag separately if available + if options[:tag_name] + sh("git push https://#{api_token}@#{repo_url} #{options[:tag_name]}") + end + sh("git push https://#{api_token}@#{repo_url}") end diff --git a/fastlane/README.md b/fastlane/README.md index 92c4eafa8..abcda903f 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -93,6 +93,14 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do +### tag_nightly + +```sh +[bundle exec] fastlane tag_nightly +``` + + + ---- This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run.