Skip to content

Commit

Permalink
[CI] Automate the merge of the release branches
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple committed Jul 31, 2024
1 parent 37d5d3b commit 0d9f754
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/release-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Merge release"

on:
issue_comment:
types: [created]

workflow_dispatch:

jobs:
merge-comment:
name: Merge release to main
runs-on: macos-14
if: github.event.issue.pull_request && github.event.comment.body == '/merge' && github.event.issue.state == 'open'
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: Create Release PR
run: bundle exec fastlane merge_release_to_main --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
File renamed without changes.
38 changes: 25 additions & 13 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -115,36 +115,48 @@ lane :publish_release do |options|
end

lane :merge_release_to_main do
ensure_git_status_clean
sh('git checkout main')
sh('git pull')
release_branch =
if is_ci
sh('git config --global user.name "Stream Bot"')
sh('git reset --hard')
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
release_branches.first
end

UI.user_error!("`#{release_branch}`` branch does not match the release branch pattern: `release/*`") unless release_branch.start_with?('release/')

# 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
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 = 'Please, wait for the `Publish new release` workflow to pass on GitHub Actions: ' \
"https://github.com/#{github_repo}/actions/workflows/release-publish.yml"
UI.important(comment)
create_pr_comment(pr_num: ENV.fetch('GITHUB_PR_NUM'), text: comment, edit_last_comment_with_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

0 comments on commit 0d9f754

Please sign in to comment.