From e5c85bda516c2aa212d82692d52ed8eed1eba681 Mon Sep 17 00:00:00 2001 From: Alexey Alter-Pesotskiy Date: Thu, 22 Aug 2024 11:33:24 +0100 Subject: [PATCH] [CI] Update publish release flow (#589) --- .github/workflows/release-publish.yml | 30 ++------------------------- fastlane/Fastfile | 12 +++++++---- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index e1b18635..b5986f7b 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -1,24 +1,16 @@ name: "Publish new release" on: - pull_request: + push: branches: - main - types: - - closed workflow_dispatch: - inputs: - version: - description: 'Release version' - type: string - required: true jobs: release: name: Publish new release runs-on: macos-13 - if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }} # only merged pull requests must trigger this job steps: - name: Connect Bot uses: webfactory/ssh-agent@v0.7.0 @@ -29,28 +21,10 @@ jobs: - uses: ./.github/actions/ruby-cache - - name: Extract version from input (for workflow dispatch) - if: ${{ github.event_name == 'workflow_dispatch' }} - run: | - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) - if [ "$BRANCH_NAME" != "main" ]; then - echo "This workflow can only be run on the main branch." - exit 1 - fi - echo "RELEASE_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV - - - name: Extract version from branch name (for release branches) - if: ${{ github.event_name == 'pull_request' && 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 - - name: "Fastlane - Publish Release" - if: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.event.pull_request.head.ref, 'release/') }} env: GITHUB_TOKEN: ${{ secrets.CI_BOT_GITHUB_TOKEN }} COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} APPSTORE_API_KEY: ${{ secrets.APPSTORE_API_KEY }} - run: bundle exec fastlane publish_release version:${{ env.RELEASE_VERSION }} --verbose + run: bundle exec fastlane publish_release --verbose diff --git a/fastlane/Fastfile b/fastlane/Fastfile index ace3e489..c4d53a09 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -16,6 +16,7 @@ source_packages_path = 'spm_cache' buildcache_xcargs = 'CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++' is_localhost = !is_ci project_package_resolved = "#{xcode_project}/project.xcworkspace/xcshareddata/swiftpm/Package.resolved" +swift_environment_path = File.absolute_path('../Sources/StreamChatSwiftUI/Generated/SystemEnvironment+Version.swift') @force_check = false before_all do |lane| @@ -67,7 +68,6 @@ desc 'Release a new version' lane :release do |options| previous_version_number = last_git_tag artifacts_path = File.absolute_path('../StreamChatSwiftUIArtifacts.json') - swift_environment_path = File.absolute_path('../Sources/StreamChatSwiftUI/Generated/SystemEnvironment+Version.swift') extra_changes = lambda do |release_version| # Set the framework version on the artifacts artifacts = JSON.parse(File.read(artifacts_path)) @@ -100,8 +100,12 @@ end desc "Publish a new release to GitHub and CocoaPods" lane :publish_release do |options| - xcversion(version: '15.0.1') + release_version = File.read(swift_environment_path).match(/String\s+=\s+"([\d.]+)"/)[1] + UI.user_error!("Release #{release_version} has already been published.") if git_tag_exists(tag: release_version, remote: true) + UI.user_error!('Release version cannot be empty') if release_version.to_s.empty? + ensure_git_branch(branch: 'main') + xcversion(version: '15.0.1') clean_products build_xcframeworks compress_frameworks @@ -109,14 +113,14 @@ lane :publish_release do |options| publish_ios_sdk( skip_git_status_check: false, - version: options[:version], + version: release_version, sdk_names: sdk_names, podspec_names: ['StreamChatSwiftUI', 'StreamChatSwiftUI-XCFramework'], github_repo: github_repo, upload_assets: ['Products/StreamChatSwiftUI.zip'] ) - update_spm(version: options[:version]) + update_spm(version: release_version) merge_main_to_develop end