Skip to content

Commit

Permalink
[CI] Comment SDK size on every commit (#3339)
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple authored Jul 29, 2024
1 parent ead44a7 commit 69b3382
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 38 deletions.
1 change: 0 additions & 1 deletion .github/workflows/cron-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ jobs:
fail-fast: false
runs-on: ${{ matrix.os }}
env:
GITHUB_EVENT: ${{ toJson(github.event) }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
STREAM_DEMO_APP_SECRET: ${{ secrets.STREAM_DEMO_APP_SECRET }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Metrics
name: SDK Performance

on:
schedule:
Expand All @@ -17,7 +17,7 @@ env:

jobs:
performance:
name: Performance
name: Metrics
runs-on: macos-14
env:
GITHUB_TOKEN: '${{ secrets.CI_BOT_GITHUB_TOKEN }}'
Expand Down
13 changes: 3 additions & 10 deletions .github/workflows/sdk-size-metrics.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: Metrics
name: SDK Size

on:
pull_request:
types:
- opened
- ready_for_review

workflow_dispatch:

Expand All @@ -17,29 +14,25 @@ env:

jobs:
sdk_size:
name: SDK Size
name: Metrics
runs-on: macos-14
env:
GITHUB_TOKEN: '${{ secrets.CI_BOT_GITHUB_TOKEN }}'
steps:
- name: Install Bot SSH Key
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }}

- uses: actions/[email protected]
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}

- uses: ./.github/actions/bootstrap
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}

- name: Run SDK Size Metrics
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
run: bundle exec fastlane show_frameworks_sizes
timeout-minutes: 30
env:
GITHUB_PR_NUM: ${{ github.event.pull_request.number }}
EVENT_NAME: ${{ github.event_name }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
APPSTORE_API_KEY: ${{ secrets.APPSTORE_API_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/smoke-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ jobs:
env:
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_EVENT: ${{ toJson(github.event) }}
GITHUB_PR_NUM: ${{ github.event.number }}
- id: get_launch_id
run: echo "launch_id=${{env.LAUNCH_ID}}" >> $GITHUB_OUTPUT
if: env.LAUNCH_ID != ''
Expand Down
41 changes: 17 additions & 24 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ lane :xcmetrics do |options|
expected_performance = performance_benchmarks['benchmark']
actual_performance = xcmetrics_log_parser(log: xcodebuild_output)

markdown_table = "## StreamChat XCMetrics\n| `target` | `metric` | `benchmark` | `branch` | `performance` | `status` |\n| - | - | - | - | - | - |\n"
table_header = '## SDK Performance'
markdown_table = "#{table_header}\n| `target` | `metric` | `benchmark` | `branch` | `performance` | `status` |\n| - | - | - | - | - | - |\n"
['testMessageListScrollTime', 'testChannelListScrollTime'].each do |test_name|
index = 0
['hitches_total_duration', 'duration', 'hitch_time_ratio', 'frame_rate', 'number_of_hitches'].each do |metric|
Expand Down Expand Up @@ -479,26 +480,9 @@ lane :xcmetrics do |options|

UI.user_error!("See Firebase error above ☝️") unless firebase_error.to_s.empty?

if is_ci
pr_comment_required = !ENV['GITHUB_PR_NUM'].to_s.empty?
performance_benchmarks[current_branch] = actual_performance
File.write(xcmetrics_path, JSON.pretty_generate(performance_benchmarks))

Dir.chdir(File.dirname(xcmetrics_path)) do
if sh('git status -s', log: false).to_s.empty?
pr_comment_required = false
UI.important('No changes in performance benchmarks. Skipping commit and comment.')
else
sh('git add -A')
sh("git commit -m 'Update #{xcmetrics_path}: #{current_branch}'")
sh('git push')
end
end
create_pr_comment(pr_num: ENV.fetch('GITHUB_PR_NUM'), text: markdown_table, edit_last_comment_with_text: table_header)

sh("gh pr comment #{ENV.fetch('GITHUB_PR_NUM')} -b '#{markdown_table}'") if pr_comment_required
end

UI.user_error!('Performance benchmark failed.') if markdown_table.include?(fail_status)
UI.user_error!("#{table_header} benchmark failed.") if markdown_table.include?(fail_status)
end

private_lane :xcmetrics_log_parser do |options|
Expand Down Expand Up @@ -860,7 +844,8 @@ lane :show_frameworks_sizes do |options|
develop_sizes = JSON.parse(File.read(sdk_size_path))
branch_sizes = options[:sizes] || frameworks_sizes

markdown_table = "## SDK Size\n| `title` | `develop` | `branch` | `diff` | `status` |\n| - | - | - | - | - |\n"
table_header = '## SDK Size'
markdown_table = "#{table_header}\n| `title` | `develop` | `branch` | `diff` | `status` |\n| - | - | - | - | - |\n"
sdk_names.each do |title|
benchmark_value = develop_sizes[title]
branch_value = branch_sizes[title.to_sym]
Expand All @@ -887,7 +872,7 @@ lane :show_frameworks_sizes do |options|
FastlaneCore::PrintTable.print_values(title: 'SDK Size', config: branch_sizes)

if is_ci
if ENV['EVENT_NAME'].to_s == 'push'
if ENV['GITHUB_EVENT_NAME'].to_s == 'push'
File.write(sdk_size_path, JSON.pretty_generate(branch_sizes))
Dir.chdir(File.dirname(sdk_size_path)) do
if sh('git status -s', log: false).to_s.empty?
Expand All @@ -900,10 +885,10 @@ lane :show_frameworks_sizes do |options|
end
end

sh("gh pr comment #{ENV.fetch('GITHUB_PR_NUM')} -b '#{markdown_table}'") unless ENV['GITHUB_PR_NUM'].to_s.empty?
create_pr_comment(pr_num: ENV.fetch('GITHUB_PR_NUM'), text: markdown_table, edit_last_comment_with_text: table_header)
end

UI.user_error!('SDK sizes benchmark failed.') if markdown_table.include?(fail_status)
UI.user_error!("#{table_header} benchmark failed.") if markdown_table.include?(fail_status)
end

desc 'Update img shields SDK size labels'
Expand Down Expand Up @@ -947,6 +932,14 @@ private_lane :create_pr do |options|
)
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' : ''
sh("gh pr comment #{options[:pr_num]} #{edit_last_comment} -b '#{options[:text]}'")
end
end

private_lane :current_branch do
github_pr_branch_name = ENV['BRANCH_NAME'].to_s
github_ref_branch_name = ENV['GITHUB_REF'].to_s.sub('refs/heads/', '')
Expand Down

0 comments on commit 69b3382

Please sign in to comment.