From aaa67cbfb41939417bf159e64c4467441a2bc53d Mon Sep 17 00:00:00 2001 From: Alexey Alter-Pesotskiy Date: Fri, 16 Aug 2024 15:17:35 +0100 Subject: [PATCH] [CI] Update release-related fastlane lanes (#583) --- .github/workflows/release-merge.yml | 2 +- .github/workflows/release-publish.yml | 29 +++++++++++++---- Gemfile.lock | 4 +-- fastlane/Fastfile | 46 +++------------------------ fastlane/Pluginfile | 2 +- 5 files changed, 30 insertions(+), 53 deletions(-) diff --git a/.github/workflows/release-merge.yml b/.github/workflows/release-merge.yml index a100effe..c8c29253 100644 --- a/.github/workflows/release-merge.yml +++ b/.github/workflows/release-merge.yml @@ -24,7 +24,7 @@ jobs: - uses: ./.github/actions/ruby-cache - name: Merge - run: bundle exec fastlane merge_release_to_main author:"$USER_LOGIN" --verbose + run: bundle exec fastlane merge_release author:"$USER_LOGIN" --verbose env: GITHUB_TOKEN: ${{ secrets.ADMIN_API_TOKEN }} # A token with the "admin:org" scope to get the list of the team members on GitHub GITHUB_PR_NUM: ${{ github.event.issue.number }} diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index 712c0fca..e1b18635 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -7,11 +7,18 @@ on: types: - closed + workflow_dispatch: + inputs: + version: + description: 'Release version' + type: string + required: true + jobs: release: name: Publish new release runs-on: macos-13 - if: github.event.pull_request.merged == true # only merged pull requests must trigger this job + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }} # only merged pull requests must trigger this job steps: - name: Connect Bot uses: webfactory/ssh-agent@v0.7.0 @@ -19,20 +26,28 @@ jobs: ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }} - uses: actions/checkout@v4.1.1 - with: - fetch-depth: 0 + + - uses: ./.github/actions/ruby-cache + + - name: Extract version from input (for workflow dispatch) + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) + if [ "$BRANCH_NAME" != "main" ]; then + echo "This workflow can only be run on the main branch." + exit 1 + fi + echo "RELEASE_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV - name: Extract version from branch name (for release branches) - if: startsWith(github.event.pull_request.head.ref, 'release/') + if: ${{ github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'release/') }} run: | BRANCH_NAME="${{ github.event.pull_request.head.ref }}" VERSION=${BRANCH_NAME#release/} echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV - - uses: ./.github/actions/ruby-cache - - name: "Fastlane - Publish Release" - if: startsWith(github.event.pull_request.head.ref, 'release/') + if: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.event.pull_request.head.ref, 'release/') }} env: GITHUB_TOKEN: ${{ secrets.CI_BOT_GITHUB_TOKEN }} COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} diff --git a/Gemfile.lock b/Gemfile.lock index d60d2d7a..f3e3530e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -199,7 +199,7 @@ GEM fastlane pry fastlane-plugin-sonarcloud_metric_kit (0.2.1) - fastlane-plugin-stream_actions (0.3.60) + fastlane-plugin-stream_actions (0.3.61) xctest_list (= 1.2.1) fastlane-plugin-versioning (0.5.2) ffi (1.17.0) @@ -427,7 +427,7 @@ DEPENDENCIES fastlane-plugin-create_xcframework fastlane-plugin-lizard fastlane-plugin-sonarcloud_metric_kit - fastlane-plugin-stream_actions (= 0.3.60) + fastlane-plugin-stream_actions (= 0.3.61) fastlane-plugin-versioning jazzy json diff --git a/fastlane/Fastfile b/fastlane/Fastfile index a2de210e..ace3e489 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -94,6 +94,10 @@ lane :release do |options| ) end +lane :merge_release do |options| + merge_release_to_main(author: options[:author]) +end + desc "Publish a new release to GitHub and CocoaPods" lane :publish_release do |options| xcversion(version: '15.0.1') @@ -117,48 +121,6 @@ lane :publish_release do |options| merge_main_to_develop end -lane :merge_release_to_main do |options| - ensure_git_status_clean - - release_branch = - if is_ci - # This API operation needs the "admin:org" scope. - ios_team = sh('gh api orgs/GetStream/teams/ios-developers/members -q ".[].login"', log: false).split - UI.user_error!("#{options[:author]} is not a member of the iOS Team") unless ios_team.include?(options[:author]) - - current_branch - else - release_branches = sh(command: 'git branch -a', log: false).delete(' ').split("\n").grep(%r(origin/.*release/)) - UI.user_error!("Expected 1 release branch, found #{release_branches.size}") if release_branches.size != 1 - - release_branches.first - end - - UI.user_error!("`#{release_branch}`` branch does not match the release branch pattern: `release/*`") unless release_branch.start_with?('release/') - - sh('git checkout origin/main') - sh('git pull origin main') - - # Merge release branch to main. For more info, read: https://notion.so/iOS-Branching-Strategy-37c10127dc26493e937769d44b1d6d9a - sh("git merge #{release_branch} --ff-only") - sh('git push origin main') - - comment = "[Publication of the release](https://github.com/#{github_repo}/actions/workflows/release-publish.yml) has been launched 👍" - UI.important(comment) - pr_comment(text: comment) -end - -lane :merge_main_to_develop do - ensure_git_status_clean - sh('git checkout main') - sh('git pull origin main') - sh('git checkout origin/develop') - sh('git pull origin develop') - sh('git log develop..main') - sh('git merge main') - sh('git push origin develop') -end - private_lane :appstore_api_key do @appstore_api_key ||= app_store_connect_api_key( key_id: 'MT3PRT8TB7', diff --git a/fastlane/Pluginfile b/fastlane/Pluginfile index e46f5564..2bb8ad94 100644 --- a/fastlane/Pluginfile +++ b/fastlane/Pluginfile @@ -5,4 +5,4 @@ gem 'fastlane-plugin-versioning' gem 'fastlane-plugin-sonarcloud_metric_kit' gem 'fastlane-plugin-create_xcframework' -gem 'fastlane-plugin-stream_actions', '0.3.60' +gem 'fastlane-plugin-stream_actions', '0.3.61'