【问题标题】:Flutter versioning CI/CD with Fastlane and Github ActionsFlutter 版本控制 CI/CD 与 Fastlane 和 Github Actions
【发布时间】:2022-09-23 18:36:48
【问题描述】:

我已经在我的 iOS 颤振项目中实现了 fastlane 和 github 操作的配置,并带有一些用于增加版本和内部版本号的自定义操作。

default_platform(:ios)

DEVELOPER_APP_ID = ENV[\'DEVELOPER_APP_ID\']
DEVELOPER_APP_IDENTIFIER = ENV[\'DEVELOPER_APP_IDENTIFIER\']
PROVISIONING_PROFILE_SPECIFIER = ENV[\'PROVISIONING_PROFILE_SPECIFIER\']
TEMP_KEYCHAIN_USER = ENV[\'TEMP_KEYCHAIN_USER\']
TEMP_KEYCHAIN_PASSWORD = ENV[\'TEMP_KEYCHAIN_PASSWORD\']
Path = \'/Users/*********\'

def delete_temp_keychain(name)
  if File.exist? File.expand_path(\"~/Library/Keychains/#{name}-db\")
    delete_keychain(
      name: name
    )
  end
end

def create_temp_keychain(name, password)
  print(\'name\', name, \'password\', password)
  create_keychain(
    name: name,
    password: password,
    unlock: false,
    timeout: 0
  )
end

def ensure_temp_keychain(name, password)
  delete_temp_keychain(name)
  create_temp_keychain(name, password)
end

def update_version(type)
  case type
  when \'major\' then increment_version_number_in_xcodeproj(bump_type: \'major\')
  when \'minor\' then increment_version_number_in_xcodeproj(bump_type: \'minor\')
  when \'patch\' then increment_version_number_in_xcodeproj(bump_type: \'patch\')
  else abort(\"Unknown version bump type: #{type}\\nValid options: major, minor, patch.\")
  end
end

platform :ios do
  lane :update_major do
    update_version(\'major\')
    increment_build_number
  end
  lane :update_minor do
    update_version(\'minor\')
    increment_build_number
  end
  lane :update_patch do
    # update_patch(\'patch\')
    # increment_build_number
    
    script = \'perlscript.pl\'
    latest
    exec(\"/usr/bin/perl #{script}\")
    # perl -i -pe \'s/^(version:\\s+\\d+\\.\\d+\\.\\d+\\+)(\\d+)$/$1.($2+1)/e\' /Users/*******/Dev/******/pubspec.yaml\")
 
  end

  
  lane :_release_candidate do
    keychain_name = TEMP_KEYCHAIN_USER
    keychain_password = TEMP_KEYCHAIN_PASSWORD
    # ensure_temp_keychain(\'fastlane_keychain_login\', \'!QA#ED4rf\')
    ensure_temp_keychain(keychain_name, keychain_password)
    add_git_tag(
      grouping: \'fastlane-builds\',
      includes_lane: true,
      prefix: \'v\',
      build_number: get_build_number,
      postfix: \"-RC#{get_build_number}\"
    )

    push_to_git_remote # this will git-push the above newly created local git-tag
    # match(
    #   type: \'appstore\',
    #   app_identifier: \"#{DEVELOPER_APP_IDENTIFIER}\",
    #   git_basic_authorization: Base64.strict_encode64(ENV[\'GIT_AUTHORIZATION\']),
    #   readonly: true,
    #   keychain_name: keychain_name,
    #   keychain_password: keychain_password
    # )

    # gym(
    #   configuration: \'Release\',
    #   workspace: \'Runner.xcworkspace\',
    #   scheme: \'Runner\',
    #   export_method: \'app-store\',
    #   export_options: {
    #     provisioningProfiles: {
    #       DEVELOPER_APP_ID => PROVISIONING_PROFILE_SPECIFIER
    #     }
    #   }
    # )

    # pilot(
    #   apple_id: \"#{DEVELOPER_APP_ID}\",
    #   app_identifier: \"#{DEVELOPER_APP_IDENTIFIER}\",
    #   skip_waiting_for_build_processing: false,
    #   skip_submission: true,
    #   distribute_external: false,
    #   notify_external_testers: false,
    #   ipa: \'./Runner.ipa\'
    # )

    delete_temp_keychain(keychain_name)
  end
end

如上面的 fastfile 所示,我什至尝试使用perl更新 pubspec 但我无法在递增后传递新值。

#!/bin/bash
# set -e

# Find and increment the version number.

perl -i -pe \'s/^(version:\\s+\\d+\\.\\d+\\.\\d+\\+)(\\d+)$/$1.($2+1)/e\' /Users/******/Dev/*******/pubspec.yaml

我在使用 fastlane 中的 increment_build_number 操作更新 xcode 中的递增数字时遇到问题,发布规范.yaml版本并将更改的文件从 github 操作同步到主存储库或我的本地存储库,因为增量是通过在 github 操作中运行通道发生的。

  • 嗨,你知道了吗?你介意分享你的 Github Action
  • 嗨,@Aristidios,实际上我还没有,但我很快就会继续工作。
  • @Aristidios,我在下面的答案中找到了一种方法!

标签: flutter github-actions fastlane


【解决方案1】:

我找到了一种更新增量构建版本的方法,方法是在增量作业之后将此代码添加到 yml 文件以进行 GitHub 操作:

- uses: stefanzweifel/git-auto-commit-action@v4
  with:
    commit_message: Apply php-cs-fixer changes

它自动提交并将更改推送到存储库,然后可以创建拉取请求,瞧,您可以再次在本地进行更改以与之前触发的操作同步。

++编辑++

您可以检查 github yml 文件中的完整代码,我根据提交消息中的关键字从 fastlane 文件中触发脚本:

# cd.yml
name: CD



on:
  push:
    branches:
      - 'main'
      
jobs:
 deploy_ios:
    name: Deploy beta build to TestFlight
    runs-on: macos-latest
    steps:
      - name: Checkout code from ref
        uses: actions/checkout@v2
        with:
          ref: ${{ github.ref }}
      - name: Run Flutter tasks
        uses: subosito/flutter-action@v1
        with:
          flutter-version: '3.0.3'
      - run: flutter pub get
      - run: flutter build ios --release --no-codesign 
      - name: increment major
        if: "contains(github.event.head_commit.message, 'major')"
        uses: maierj/fastlane-action@v1.4.0
        with: 
          lane: update_major
          subdirectory: ios
      - name: increment minor
        if: "contains(github.event.head_commit.message, 'minor')"
        uses: maierj/fastlane-action@v1.4.0
        with: 
          lane: update_minor
          subdirectory: ios
      - name: increment patch
        if: "contains(github.event.head_commit.message, 'patch')"
        uses: maierj/fastlane-action@v1.4.0
        with: 
          lane: update_patch
          subdirectory: ios
      - name: Deploy iOS Beta to TestFlight via Fastlane
        uses: maierj/fastlane-action@v1.4.0
        with:
          lane: _release_candidate
          subdirectory: ios
      - uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Auto Commit

      
        env:
          APP_STORE_CONNECT_TEAM_ID: '${{ secrets.APP_STORE_CONNECT_TEAM_ID }}'
          DEVELOPER_APP_ID: '${{ secrets.DEVELOPER_APP_ID }}'
          DEVELOPER_APP_IDENTIFIER: '${{ secrets.DEVELOPER_APP_IDENTIFIER }}'
          DEVELOPER_PORTAL_TEAM_ID: '${{ secrets.DEVELOPER_PORTAL_TEAM_ID }}'
          FASTLANE_APPLE_ID: '${{ secrets.FASTLANE_APPLE_ID }}'
          FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: '${{ secrets.FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD }}'
          MATCH_PASSWORD: '${{ secrets.MATCH_PASSWORD }}'
          GIT_AUTHORIZATION: '${{ secrets.GIT_AUTHORIZATION }}'
          PROVISIONING_PROFILE_SPECIFIER: '${{ secrets.PROVISIONING_PROFILE_SPECIFIER }}'
          TEMP_KEYCHAIN_PASSWORD: '${{ secrets.TEMP_KEYCHAIN_PASSWORD }}'
          TEMP_KEYCHAIN_USER: '${{ secrets.TEMP_KEYCHAIN_USER }}'

【讨论】:

  • 非常好 !您认为您可以将完整的 Github 操作代码放入您的答案中吗? @hasan :)
  • 我可以这样做,正如您在上面的 fastlane 文件中看到的那样,我正在根据提交消息从 github 操作触发脚本,但我将使用完整代码编辑我的答案
猜你喜欢
  • 2020-07-01
  • 2020-01-08
  • 2021-05-24
  • 2022-10-19
  • 1970-01-01
  • 2019-08-15
  • 2020-07-23
  • 1970-01-01
  • 2019-12-29
相关资源
最近更新 更多