From 69b3382ddf26f2c23fdfa21d9a2448640213586b Mon Sep 17 00:00:00 2001 From: Alexey Alter-Pesotskiy Date: Mon, 29 Jul 2024 15:18:08 +0100 Subject: [PATCH] [CI] Comment SDK size on every commit (#3339) --- .github/workflows/cron-checks.yml | 1 - ...etrics.yml => sdk-performance-metrics.yml} | 4 +- .github/workflows/sdk-size-metrics.yml | 13 ++---- .github/workflows/smoke-checks.yml | 2 +- fastlane/Fastfile | 41 ++++++++----------- 5 files changed, 23 insertions(+), 38 deletions(-) rename .github/workflows/{performance-metrics.yml => sdk-performance-metrics.yml} (97%) diff --git a/.github/workflows/cron-checks.yml b/.github/workflows/cron-checks.yml index a25fd149a05..8f93dbb6d88 100644 --- a/.github/workflows/cron-checks.yml +++ b/.github/workflows/cron-checks.yml @@ -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 }} diff --git a/.github/workflows/performance-metrics.yml b/.github/workflows/sdk-performance-metrics.yml similarity index 97% rename from .github/workflows/performance-metrics.yml rename to .github/workflows/sdk-performance-metrics.yml index ae59214d082..e9ac86a6076 100644 --- a/.github/workflows/performance-metrics.yml +++ b/.github/workflows/sdk-performance-metrics.yml @@ -1,4 +1,4 @@ -name: Metrics +name: SDK Performance on: schedule: @@ -17,7 +17,7 @@ env: jobs: performance: - name: Performance + name: Metrics runs-on: macos-14 env: GITHUB_TOKEN: '${{ secrets.CI_BOT_GITHUB_TOKEN }}' diff --git a/.github/workflows/sdk-size-metrics.yml b/.github/workflows/sdk-size-metrics.yml index 4bc8e8bba49..50745c71220 100644 --- a/.github/workflows/sdk-size-metrics.yml +++ b/.github/workflows/sdk-size-metrics.yml @@ -1,10 +1,7 @@ -name: Metrics +name: SDK Size on: pull_request: - types: - - opened - - ready_for_review workflow_dispatch: @@ -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/ssh-agent@v0.7.0 with: ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }} - uses: actions/checkout@v3.1.0 - 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 }} diff --git a/.github/workflows/smoke-checks.yml b/.github/workflows/smoke-checks.yml index 490899d6c84..7d0ef74a258 100644 --- a/.github/workflows/smoke-checks.yml +++ b/.github/workflows/smoke-checks.yml @@ -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 != '' diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 327d29c842d..5aaadd0911e 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -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| @@ -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| @@ -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] @@ -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? @@ -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' @@ -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/', '')