Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Automate the merge of the release branches #3350

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/release-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Merge release"

on:
issue_comment:
types: [created]

jobs:
merge-comment:
name: Merge release to main
runs-on: macos-14
if: github.event.issue.pull_request && github.event.issue.state == 'open' && github.event.comment.body == '/merge release'
steps:
- name: Connect iOS 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: Merge
run: bundle exec fastlane merge_release_to_main author:"${{ github.event.comment.user.login }}" --verbose
env:
GITHUB_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
GITHUB_PR_NUM: ${{ github.event.issue.number }}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ jobs:
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}

- uses: actions/[email protected]

- name: Extract version from branch name (for release branches)
if: 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/')
env:
Expand Down
45 changes: 30 additions & 15 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,52 @@ lane :publish_release do |options|
merge_main_to_develop
end

lane :merge_release_to_main do
ensure_git_status_clean
sh('git checkout main')
sh('git pull')
lane :merge_release_to_main do |options|
release_branch =
if is_ci
sh('git config --global user.name "Stream Bot"')
sh('git reset --hard')
ios_team = sh('gh api "orgs/GetStream/teams/ios-developers/members" --jq ".[].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
ensure_git_status_clean
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

# Grep all remote release branches and ensure there's only one
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_branches.first} --ff-only")
UI.user_error!('Not pushing changes') unless prompt(text: 'Will push changes. All looking good?', boolean: true)
sh('git push')
UI.important('Please, wait for the `Publish new release` workflow to pass on GitHub Actions: ' \
"https://github.com/#{github_repo}/actions/workflows/publish-release.yml")
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)
create_pr_comment(pr_num: ENV.fetch('GITHUB_PR_NUM'), text: comment)
end

lane :merge_main_to_develop do
if is_ci
sh('git config --global user.name "Stream Bot"')
sh('git reset --hard')
else
ensure_git_status_clean
end

sh('git checkout main')
sh('git pull origin main')
sh('git checkout develop')
sh('git checkout origin/develop')
sh('git pull origin develop')
sh('git log develop..main')
sh('git merge main')
sh('git push')
sh('git push origin develop')
end

desc 'Compresses the XCFrameworks into zip files'
Expand Down Expand Up @@ -939,7 +954,7 @@ end
private_lane :create_pr_comment do |options|
if is_ci && !options[:pr_num].to_s.empty?
last_comment = sh("gh pr view #{options[:pr_num]} --json comments --jq '.comments | map(select(.author.login == \"Stream-iOS-Bot\")) | last'")
edit_last_comment = last_comment.include?(options[:edit_last_comment_with_text]) ? '--edit-last' : ''
edit_last_comment = options[:edit_last_comment_with_text] && last_comment.include?(options[:edit_last_comment_with_text]) ? '--edit-last' : ''
sh("gh pr comment #{options[:pr_num]} #{edit_last_comment} -b '#{options[:text]}'")
end
end
Expand Down
Loading