首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤振版本CI/CD与Fastlane和Github操作

颤振版本CI/CD与Fastlane和Github操作
EN

Stack Overflow用户
提问于 2022-08-16 13:38:35
回答 1查看 545关注 0票数 2

我已经在iOS的flutter项目中实现了fastlane和github操作的配置,并使用了一些自定义操作来增加版本和版本号。

代码语言:javascript
复制
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

如上面的pass文件所示,我甚至尝试使用perl更新发布规范,但是在增量之后无法传递新的值。

代码语言:javascript
复制
#!/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

我面临一个问题:使用increment_build_number操作从fastlane更新xcode中的递增号,到pubspec.yaml版本,并将更改后的文件从github操作同步到主回购或本地回购,因为增量是通过在github操作中运行来实现的。

EN

回答 1

Stack Overflow用户

发布于 2022-09-19 12:07:53

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

代码语言:javascript
复制
- uses: stefanzweifel/git-auto-commit-action@v4
  with:
    commit_message: Apply php-cs-fixer changes

如果它自动提交并将更改推送到回购,并且从那时起可以创建一个拉请求并查看,您将再次将这些更改与之前触发的操作同步。

++EDIT++

您可以检查github yml文件中的完整代码,在该文件中,我将根据提交消息中的关键字触发快速车道文件中的脚本:

代码语言:javascript
复制
# 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 }}'

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73374931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档