From 05d98a272503746394bd4865cb2c9a0aded89d69 Mon Sep 17 00:00:00 2001 From: Alexey Alter-Pesotskiy Date: Wed, 31 Jul 2024 10:20:34 +0100 Subject: [PATCH] [CI] Correctly retrieve a git branch on CI --- .github/workflows/cron-checks.yml | 12 ++++----- .github/workflows/publish-release.yml | 2 +- .github/workflows/sdk-performance-metrics.yml | 3 +-- .github/workflows/sdk-size-metrics.yml | 8 +----- .github/workflows/smoke-checks.yml | 25 ++----------------- .github/workflows/start-new-release.yml | 2 +- .github/workflows/testflight.yml | 2 +- fastlane/Allurefile | 5 ++-- fastlane/Fastfile | 24 +++++++----------- 9 files changed, 23 insertions(+), 60 deletions(-) diff --git a/.github/workflows/cron-checks.yml b/.github/workflows/cron-checks.yml index a25fd149a05..a741f5028d0 100644 --- a/.github/workflows/cron-checks.yml +++ b/.github/workflows/cron-checks.yml @@ -13,6 +13,7 @@ concurrency: env: HOMEBREW_NO_INSTALL_CLEANUP: 1 # Disable cleanup for homebrew, we don't need it on CI + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: build-test-app-and-frameworks: @@ -59,7 +60,6 @@ jobs: 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 }} XCODE_VERSION: ${{ matrix.xcode }} @@ -151,7 +151,6 @@ jobs: fail-fast: false runs-on: ${{ matrix.os }} env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} XCODE_VERSION: ${{ matrix.xcode }} steps: - uses: actions/checkout@v4.1.1 @@ -195,8 +194,11 @@ jobs: runs-on: macos-12 env: XCODE_VERSION: "14.0.1" - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: + - name: Connect iOS Bot + uses: webfactory/ssh-agent@v0.7.0 + with: + ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }} - uses: actions/checkout@v4.1.1 - uses: ./.github/actions/ruby-cache - name: List Xcode versions @@ -207,10 +209,6 @@ jobs: - name: Build UI run: bundle exec fastlane test_ui device:"iPhone 8" build_for_testing:true timeout-minutes: 25 - - name: Install Bot SSH Key - uses: webfactory/ssh-agent@v0.7.0 - with: - ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }} - name: Build XCFrameworks run: bundle exec fastlane build_xcframeworks timeout-minutes: 25 diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 6dc80144948..32523418978 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -13,7 +13,7 @@ jobs: runs-on: macos-12 if: github.event.pull_request.merged == true # only merged pull requests must trigger this job steps: - - name: Install Bot SSH Key + - name: Connect iOS Bot uses: webfactory/ssh-agent@v0.7.0 with: ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }} diff --git a/.github/workflows/sdk-performance-metrics.yml b/.github/workflows/sdk-performance-metrics.yml index e9ac86a6076..f7b566cadb5 100644 --- a/.github/workflows/sdk-performance-metrics.yml +++ b/.github/workflows/sdk-performance-metrics.yml @@ -22,7 +22,7 @@ jobs: env: GITHUB_TOKEN: '${{ secrets.CI_BOT_GITHUB_TOKEN }}' steps: - - name: Install Bot SSH Key + - name: Connect iOS Bot if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }} uses: webfactory/ssh-agent@v0.7.0 with: @@ -45,7 +45,6 @@ jobs: timeout-minutes: 120 env: GITHUB_PR_NUM: ${{ github.event.pull_request.number }} - BRANCH_NAME: ${{ github.event.pull_request.head.ref }} MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} APPSTORE_API_KEY: ${{ secrets.APPSTORE_API_KEY }} diff --git a/.github/workflows/sdk-size-metrics.yml b/.github/workflows/sdk-size-metrics.yml index e88d63c6738..16e1d1e1c96 100644 --- a/.github/workflows/sdk-size-metrics.yml +++ b/.github/workflows/sdk-size-metrics.yml @@ -19,7 +19,7 @@ jobs: env: GITHUB_TOKEN: '${{ secrets.CI_BOT_GITHUB_TOKEN }}' steps: - - name: Install Bot SSH Key + - name: Connect iOS Bot uses: webfactory/ssh-agent@v0.7.0 with: ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }} @@ -28,16 +28,10 @@ jobs: - uses: ./.github/actions/bootstrap - - name: Get branch name - id: get_branch_name - run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT - - name: Run SDK Size Metrics run: bundle exec fastlane show_frameworks_sizes timeout-minutes: 30 env: - BRANCH_NAME: ${{ steps.get_branch_name.outputs.branch }} GITHUB_PR_NUM: ${{ github.event.pull_request.number }} - 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 44e7a7b905e..0dc31813bcb 100644 --- a/.github/workflows/smoke-checks.yml +++ b/.github/workflows/smoke-checks.yml @@ -20,6 +20,8 @@ concurrency: env: HOMEBREW_NO_INSTALL_CLEANUP: 1 # Disable cleanup for homebrew, we don't need it on CI IOS_SIMULATOR_DEVICE: "iPhone 15 Pro (17.4)" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PR_NUM: ${{ github.event.pull_request.number }} jobs: build-test-app-and-frameworks: @@ -48,8 +50,6 @@ jobs: name: Automated Code Review runs-on: macos-12 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_NUM: ${{ github.event.number }} XCODE_VERSION: "14.0.1" if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }} steps: @@ -73,8 +73,6 @@ jobs: if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }} env: XCODE_VERSION: "14.0.1" - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_NUM: ${{ github.event.number }} steps: - uses: actions/checkout@v4.1.1 - uses: ./.github/actions/ruby-cache @@ -92,9 +90,6 @@ jobs: runs-on: macos-14 if: ${{ github.event.inputs.snapshots != 'true' }} needs: build-test-app-and-frameworks - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_NUM: ${{ github.event.number }} steps: - uses: actions/checkout@v4.1.1 with: @@ -110,13 +105,9 @@ jobs: - name: Run LLC Tests (Debug) run: bundle exec fastlane test device:"${{ env.IOS_SIMULATOR_DEVICE }}" skip_build:true timeout-minutes: 60 - - name: Get branch name - id: get_branch_name - run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT - name: Run Sonar analysis run: bundle exec fastlane sonar_upload env: - BRANCH_NAME: ${{ steps.get_branch_name.outputs.branch }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} PR_NUMBER: ${{ github.event.number }} @@ -165,7 +156,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }} # to open a PR GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # to use github cli - GITHUB_PR_NUM: ${{ github.event.number }} - name: Parse xcresult if: failure() run: | @@ -192,8 +182,6 @@ jobs: run: bundle exec fastlane allure_launch env: ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_NUM: ${{ github.event.number }} GITHUB_EVENT: ${{ toJson(github.event) }} - id: get_launch_id run: echo "launch_id=${{env.LAUNCH_ID}}" >> $GITHUB_OUTPUT @@ -230,15 +218,12 @@ jobs: env: XCODE_VERSION: "15.0.1" # the most stable pair of Xcode IOS_SIMULATOR_DEVICE: "iPhone 15 Pro (17.0)" # and iOS - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_NUM: ${{ github.event.number }} MATRIX_SIZE: ${{ strategy.job-total }} STREAM_DEMO_APP_SECRET: ${{ secrets.STREAM_DEMO_APP_SECRET }} - name: Allure TestOps Upload if: env.LAUNCH_ID != '' && (success() || failure()) run: bundle exec fastlane allure_upload launch_id:$LAUNCH_ID env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }} - name: Allure TestOps Launch Removal if: env.LAUNCH_ID != '' && cancelled() @@ -265,9 +250,6 @@ jobs: runs-on: macos-14 needs: build-test-app-and-frameworks if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_NUM: ${{ github.event.number }} steps: - uses: actions/checkout@v4.1.1 - uses: actions/download-artifact@v4 @@ -297,9 +279,6 @@ jobs: runs-on: macos-14 needs: build-test-app-and-frameworks if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_NUM: ${{ github.event.number }} steps: - uses: actions/checkout@v4.1.1 - uses: actions/download-artifact@v4 diff --git a/.github/workflows/start-new-release.yml b/.github/workflows/start-new-release.yml index c6b49fbf27c..ba75277cd3d 100644 --- a/.github/workflows/start-new-release.yml +++ b/.github/workflows/start-new-release.yml @@ -13,7 +13,7 @@ jobs: name: Start new release runs-on: macos-14 steps: - - name: Install Bot SSH Key + - name: Connect iOS Bot uses: webfactory/ssh-agent@v0.7.0 with: ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }} diff --git a/.github/workflows/testflight.yml b/.github/workflows/testflight.yml index 098250d93ca..cb256f8feac 100644 --- a/.github/workflows/testflight.yml +++ b/.github/workflows/testflight.yml @@ -17,7 +17,7 @@ jobs: deploy: runs-on: macos-14 steps: - - name: Install Bot SSH Key + - name: Connect iOS Bot uses: webfactory/ssh-agent@v0.7.0 with: ssh-private-key: ${{ secrets.BOT_SSH_PRIVATE_KEY }} diff --git a/fastlane/Allurefile b/fastlane/Allurefile index c929082e861..d034f2b49c3 100755 --- a/fastlane/Allurefile +++ b/fastlane/Allurefile @@ -8,11 +8,10 @@ allure_results_path = 'allure-results' desc 'Upload test results to Allure TestOps' lane :allure_upload do |options| - branch = github_run_details['head_branch'] allure_args = "-e #{allure_url} --project-id #{allure_project_id} --launch-id #{options[:launch_id]}" sh("./xcresults export test_output/StreamChatUITestsApp.xcresult #{allure_results_path} || true") sh("./allurectl launch reopen #{options[:launch_id]} || true") # to prevent allure from uploading results to a closed launch - sh("env BRANCH_NAME='#{branch}' ./allurectl upload #{allure_args} #{allure_results_path} || true") + sh("env BRANCH_NAME='#{current_branch}' ./allurectl upload #{allure_args} #{allure_results_path} || true") UI.success("Check out test results in Allure TestOps: #{allure_url}/launch/#{options[:launch_id]} 🎉") end @@ -54,6 +53,6 @@ def github_run_details return nil unless is_ci github_path = "#{ENV.fetch('GITHUB_API_URL', nil)}/repos/#{ENV.fetch('GITHUB_REPOSITORY', nil)}/actions/runs/#{ENV.fetch('GITHUB_RUN_ID', nil)}" - output = sh(command: "curl -s -H 'authorization: Bearer #{ENV.fetch('GITHUB_TOKEN', nil)}' -X GET -G #{github_path}", log: false) + output = sh(command: "curl -s -H 'authorization: Bearer #{ENV.fetch('GITHUB_TOKEN', nil)}' -X GET -G #{github_path}") JSON.parse(output) end diff --git a/fastlane/Fastfile b/fastlane/Fastfile index d433459d75e..ce82c9279cd 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -944,21 +944,15 @@ private_lane :create_pr_comment do |options| 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/', '') - fastlane_branch_name = git_branch - - branch_name = if !github_pr_branch_name.empty? - github_pr_branch_name - elsif !fastlane_branch_name.empty? - fastlane_branch_name - elsif !github_ref_branch_name.empty? - github_ref_branch_name - end - - UI.important("Current branch: #{branch_name} 🕊️") - branch_name +lane :current_branch do + branch = if ENV['GITHUB_PR_NUM'].to_s.empty? + git_branch + else + sh("gh pr view #{ENV.fetch('GITHUB_PR_NUM')} --json headRefName -q .headRefName").strip + end + + UI.important("Current branch: #{branch} 🕊️") + branch end private_lane :git_status do |options|