Skip to content

Commit

Permalink
[CI] Update release-related fastlane lanes (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple authored Aug 16, 2024
1 parent 143696d commit aaa67cb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
29 changes: 22 additions & 7 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,47 @@ 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/[email protected]
with:
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}

- uses: actions/[email protected]
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 }}
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
46 changes: 4 additions & 42 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion fastlane/Pluginfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit aaa67cb

Please sign in to comment.