Skip to content

Commit 37b1eba

Browse files
[CI] Correctly retrieve a git branch on CI (#567)
1 parent 9eb77e6 commit 37b1eba

File tree

8 files changed

+30
-39
lines changed

8 files changed

+30
-39
lines changed

.github/workflows/cron-checks.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ concurrency:
1313

1414
env:
1515
HOMEBREW_NO_INSTALL_CLEANUP: 1 # Disable cleanup for homebrew, we don't need it on CI
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1617

1718
jobs:
1819
build-test-app-and-frameworks:
@@ -54,7 +55,6 @@ jobs:
5455
runs-on: ${{ matrix.os }}
5556
env:
5657
GITHUB_EVENT: ${{ toJson(github.event) }}
57-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5858
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
5959
XCODE_VERSION: ${{ matrix.xcode }}
6060
steps:
@@ -149,6 +149,10 @@ jobs:
149149
env:
150150
XCODE_VERSION: "15.0.1"
151151
steps:
152+
- name: Connect iOS Bot
153+
uses: webfactory/ssh-agent@v0.7.0
154+
with:
155+
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
152156
- uses: actions/checkout@v3.1.0
153157
- uses: ./.github/actions/ruby-cache
154158
- name: List Xcode versions
@@ -157,10 +161,6 @@ jobs:
157161
- name: Build SwiftUI
158162
run: bundle exec fastlane test_ui device:"iPhone 15" build_for_testing:true
159163
timeout-minutes: 25
160-
- name: Install Bot SSH Key
161-
uses: webfactory/ssh-agent@v0.7.0
162-
with:
163-
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
164164
- name: Build XCFrameworks
165165
run: bundle exec fastlane build_xcframeworks
166166
timeout-minutes: 25

.github/workflows/publish-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: macos-13
1414
if: github.event.pull_request.merged == true # only merged pull requests must trigger this job
1515
steps:
16-
- name: Install Bot SSH Key
16+
- name: Connect iOS Bot
1717
uses: webfactory/ssh-agent@v0.7.0
1818
with:
1919
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}

.github/workflows/sdk-size-metrics.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
env:
2020
GITHUB_TOKEN: '${{ secrets.CI_BOT_GITHUB_TOKEN }}'
2121
steps:
22-
- name: Install Bot SSH Key
22+
- name: Connect iOS Bot
2323
uses: webfactory/ssh-agent@v0.7.0
2424
with:
2525
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
@@ -28,16 +28,10 @@ jobs:
2828

2929
- uses: ./.github/actions/bootstrap
3030

31-
- name: Get branch name
32-
id: get_branch_name
33-
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
34-
3531
- name: Run SDK Size Metrics
3632
run: bundle exec fastlane show_frameworks_sizes
3733
timeout-minutes: 30
3834
env:
39-
BRANCH_NAME: ${{ steps.get_branch_name.outputs.branch }}
4035
GITHUB_PR_NUM: ${{ github.event.pull_request.number }}
41-
GITHUB_EVENT_NAME: ${{ github.event_name }}
4236
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
4337
APPSTORE_API_KEY: ${{ secrets.APPSTORE_API_KEY }}

.github/workflows/smoke-checks.yml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ concurrency:
2020
env:
2121
HOMEBREW_NO_INSTALL_CLEANUP: 1 # Disable cleanup for homebrew, we don't need it on CI
2222
IOS_SIMULATOR_DEVICE: "iPhone 15 Pro (17.4)"
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
GITHUB_PR_NUM: ${{ github.event.pull_request.number }}
2325

2426
jobs:
2527
build-test-app-and-frameworks:
@@ -48,8 +50,6 @@ jobs:
4850
name: Automated Code Review
4951
runs-on: macos-13
5052
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
GITHUB_PR_NUM: ${{ github.event.number }}
5353
XCODE_VERSION: "15.0.1"
5454
if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }}
5555
steps:
@@ -72,6 +72,10 @@ jobs:
7272
env:
7373
XCODE_VERSION: "15.0.1"
7474
steps:
75+
- name: Connect iOS Bot
76+
uses: webfactory/ssh-agent@v0.7.0
77+
with:
78+
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
7579
- uses: actions/checkout@v3.1.0
7680
- uses: ./.github/actions/ruby-cache
7781
- name: List Xcode versions
@@ -80,10 +84,6 @@ jobs:
8084
- name: Build SwiftUI
8185
run: bundle exec fastlane test_ui device:"iPhone 15" build_for_testing:true
8286
timeout-minutes: 25
83-
- name: Install Bot SSH Key
84-
uses: webfactory/ssh-agent@v0.7.0
85-
with:
86-
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}
8787
- name: Build XCFrameworks
8888
run: bundle exec fastlane build_xcframeworks
8989
timeout-minutes: 25
@@ -110,19 +110,12 @@ jobs:
110110
timeout-minutes: 60
111111
env:
112112
GITHUB_TOKEN: ${{ secrets.CI_BOT_GITHUB_TOKEN }} # to open a PR
113-
GITHUB_PR_NUM: ${{ github.event.number }}
114-
- name: Get branch name
115-
id: get_branch_name
116-
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
117113
- name: Run Sonar analysis
118114
if: ${{ github.event.inputs.snapshots != 'true' }}
119115
run: bundle exec fastlane sonar_upload
120116
env:
121-
BRANCH_NAME: ${{ steps.get_branch_name.outputs.branch }}
122117
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
123-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124118
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
125-
PR_NUMBER: ${{ github.event.number }}
126119
- uses: 8398a7/action-slack@v3
127120
with:
128121
status: ${{ job.status }}
@@ -164,8 +157,6 @@ jobs:
164157
run: bundle exec fastlane allure_launch
165158
env:
166159
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
167-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168-
GITHUB_PR_NUM: ${{ github.event.number }}
169160
GITHUB_EVENT: ${{ toJson(github.event) }}
170161
- id: get_launch_id
171162
run: echo "launch_id=${{env.LAUNCH_ID}}" >> $GITHUB_OUTPUT
@@ -203,14 +194,11 @@ jobs:
203194
env:
204195
XCODE_VERSION: "15.2" # the most stable pair of Xcode
205196
IOS_SIMULATOR_DEVICE: "iPhone 15 Pro (17.2)" # and iOS
206-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
207-
GITHUB_PR_NUM: ${{ github.event.number }}
208197
MATRIX_SIZE: ${{ strategy.job-total }}
209198
- name: Allure TestOps Upload
210199
if: env.LAUNCH_ID != '' && (success() || failure())
211200
run: bundle exec fastlane allure_upload launch_id:$LAUNCH_ID
212201
env:
213-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
214202
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
215203
- name: Allure TestOps Launch Removal
216204
if: env.LAUNCH_ID != '' && cancelled()

.github/workflows/start-new-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: Start new release
1414
runs-on: macos-14
1515
steps:
16-
- name: Install Bot SSH Key
16+
- name: Connect iOS Bot
1717
uses: webfactory/ssh-agent@v0.7.0
1818
with:
1919
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}

fastlane/Allurefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ allure_results_path = 'allure-results'
88

99
desc 'Upload test results to Allure TestOps'
1010
lane :allure_upload do |options|
11-
branch = github_run_details['head_branch']
1211
allure_args = "-e #{allure_url} --project-id #{allure_project_id} --launch-id #{options[:launch_id]}"
1312
sh("./xcresults export test_output/StreamChatSwiftUITestsApp.xcresult #{allure_results_path} || true")
1413
sh("./allurectl launch reopen #{options[:launch_id]} || true") # to prevent allure from uploading results to a closed launch
15-
sh("env BRANCH_NAME='#{branch}' ./allurectl upload #{allure_args} #{allure_results_path} || true")
14+
sh("env BRANCH_NAME='#{current_branch}' ./allurectl upload #{allure_args} #{allure_results_path} || true")
1615
UI.success("Check out test results in Allure TestOps: #{allure_url}/launch/#{options[:launch_id]} 🎉")
1716
end
1817

@@ -54,6 +53,6 @@ def github_run_details
5453
return nil unless is_ci
5554

5655
github_path = "#{ENV.fetch('GITHUB_API_URL', nil)}/repos/#{ENV.fetch('GITHUB_REPOSITORY', nil)}/actions/runs/#{ENV.fetch('GITHUB_RUN_ID', nil)}"
57-
output = sh(command: "curl -s -H 'authorization: Bearer #{ENV.fetch('GITHUB_TOKEN', nil)}' -X GET -G #{github_path}", log: false)
56+
output = sh(command: "curl -s -H 'authorization: Bearer #{ENV.fetch('GITHUB_TOKEN', nil)}' -X GET -G #{github_path}")
5857
JSON.parse(output)
5958
end

fastlane/Fastfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ lane :sources_matrix do
474474
ui: ['Sources', 'StreamChatSwiftUITests', xcode_project],
475475
sample_apps: ['Sources', 'DemoAppSwiftUI', xcode_project],
476476
ruby: ['fastlane', 'Gemfile', 'Gemfile.lock'],
477-
size: ['Sources', xcode_project]
477+
size: ['Sources', xcode_project],
478+
sonar: ['Sources']
478479
}
479480
end
480481

@@ -625,8 +626,15 @@ private_lane :create_pr_comment do |options|
625626
end
626627
end
627628

628-
private_lane :current_branch do
629-
ENV['BRANCH_NAME'].to_s.empty? ? git_branch : ENV.fetch('BRANCH_NAME')
629+
lane :current_branch do
630+
branch = if ENV['GITHUB_PR_NUM'].to_s.empty?
631+
git_branch
632+
else
633+
sh("gh pr view #{ENV.fetch('GITHUB_PR_NUM')} --json headRefName -q .headRefName").strip
634+
end
635+
636+
UI.important("Current branch: #{branch} 🕊️")
637+
branch
630638
end
631639

632640
private_lane :git_status do |options|

fastlane/Sonarfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
desc 'Get code coverage report and run complexity analysis for Sonar'
44
lane :sonar_upload do
5+
next unless is_check_required(sources: sources_matrix[:sonar], force_check: @force_check)
6+
57
sonar_args = ''
68
version_number = get_version_number(
79
xcodeproj: 'StreamChatSwiftUI.xcodeproj',
@@ -35,7 +37,7 @@ private_lane :sonar_options do |options|
3537
if ENV['GITHUB_EVENT_NAME'] == 'pull_request'
3638
default_options.merge(pull_request_branch: ENV.fetch('GITHUB_HEAD_REF', nil),
3739
pull_request_base: ENV.fetch('GITHUB_BASE_REF', nil),
38-
pull_request_key: ENV.fetch('PR_NUMBER', nil))
40+
pull_request_key: ENV.fetch('GITHUB_PR_NUM', nil))
3941
else
4042
default_options.merge(branch_name: current_branch, project_version: options[:version_number])
4143
end

0 commit comments

Comments
 (0)