1. File structure

2. Code implementation

Go to the project directory,

  • Deploy the test environment and execute./build_beta.sh
  • Deploy the training environment./build_train.sh
  • Deploy a formal environment./build_prod.sh
# fastlane/build_beta.sh Test environment
#! /bin/bash
# Test environment
# Fastlane ios Custom_Lane buildType:beta notInc:1 # Fastlane ios Custom_lane buildType: Beta notInc:1
# Fastlane ios Custom_Lane buildType:beta
cd /Users/jason_pro/Desktop/app_project/yzs-app-bloombeauty-ios/BloomBeauty/fastlane
fastlane ios custom_lane buildType:beta


# fastlane/build_train.sh Training environment
cd /Users/jason_pro/Desktop/app_project/yzs-app-bloombeauty-ios/BloomBeauty/fastlane
fastlane ios custom_lane buildType:train


# fastlane/build_prod.sh official environment
cd /Users/jason_pro/Desktop/app_project/yzs-app-bloombeauty-ios/BloomBeauty/fastlane
fastlane ios custom_lane buildType:prod

Copy the code

fastlane/Fastfile

Sudo Fastlane add_plugin Fastlane-plugin-versioning

# Execute command
# fastlane ios custom_lane # fastlane

# 
# Fastlane ios Custom_Lane buildType:beta
# FastLane ios Custom_Lane buildType:train
# Fastlane ios Custom_Lane buildType:prod
NotInc = 1 does not automatically increment the number
# Fastlane ios Custom_Lane buildType: Beta notInc:1
# Fastlane ios Custom_lane buildType:prod notInc:1

Note that xcode is not used to edit the general version and title, after modification,
$(CURRENT_PROJECT_VERSION) and $(CURRENT_PROJECT_VERSION)

default_platform(:ios)

platform :ios do
  before_all do
    The company's computers are too slow
    ENV["FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT"] = "120"
    ENV["FASTLANE_XCODEBUILD_SETTINGS_RETRIES"] = "4"
  end
  desc "Description of what the lane does"
  lane :custom_lane do|op|
      projectName = "BloomBeauty" 
      buildType = op[:buildType]
      notInc = op[:notInc]
      
      buildtTarget = ""
      buildTimeName = ""
      if buildType.nil? || buildType.empty?
           buildtTarget = projectName
           buildTimeName = Time.new.strftime("%Y%m%d-%H_%M_%S") + projectName
      else
           buildtTarget = projectName + "_" + buildType
           buildTimeName = Time.new.strftime("%Y%m%d-%H_%M_%S") + "-" + projectName + "_" + buildType
      end
      puts "buildtTarget: " + buildtTarget
      
      puts "buildTimeName: " + buildTimeName 
      Get the current app version
      
      nowVersionBundle = get_build_number_from_plist( target: buildtTarget)
      puts "nowVersionBundle: " + nowVersionBundle  
      if notInc.nil? || notInc.empty? || notInc == 0
          # Default increment
          puts "Start self-increasing version number......."
          newVersion , newVersionBundle = getIOSVersionBundleIncrementArray nowVersionBundle
          setNewIOSVersionBundle buildtTarget , newVersion , newVersionBundle
      else
          puts "No self-incrementing version number......."
      end

      gym( 
        scheme:buildtTarget,
        export_method:"enterprise".#output_directory:".. /.. /yzs-app-bloombeauty-ios-build/build/"+buildTimeName,
        output_directory:"/Users/jason_pro/Desktop/ publish folder /mp.ifashioncloud.com/FTP /centric_"+ buildType +"/",
        archive_path:".. /.. /yzs-app-bloombeauty-ios-build/Archive-"+buildTimeName,
        output_name:'centric',
      )
      
      after_all do
          puts "Start executing shell commands" 
          system './startUpload.sh ' + buildType
          puts "Run the shell command -- End" 
      end
  end
end

Return the version number and the actual bundle version number for the current version information
# App uses the bundle version number to determine the upgrade
def getIOSVersionBundleIncrementArray(nowVersionBundle)
    newArray = nowVersionBundle.split(".")
    lastNum = newArray.pop
    newVersion = newArray.join(".")
    lastNumInt = Integer(lastNum) + 1
    newArray.insert(3,lastNumInt)
    newVersionBundle = newArray.join(".")
    [newVersion , newVersionBundle]
    #puts "newVersion: " + newVersion
    #puts "newVersionBundle: " + newVersionBundle
end

# Encapsulate the method to change the version number
def setNewIOSVersionBundle(target,newVersion,newVersionBundle)
      #
      puts "Start setting newVersion:" + newVersion
      puts "Start setting up newVersionBundle:" + newVersionBundle
      increment_version_number_in_plist(
              target: target,
              version_number: newVersion
      )
      increment_build_number_in_plist(
              target: target,
              build_number: newVersionBundle
      )
    
end
Copy the code

Sh test environment startupload_beta. sh Training environment startupload_train. sh Official environment startupload_prod. sh

# Remember to run with sudo
# test
./startUpload.sh beta
# training
./startUpload.sh train
# formal
./startUpload.sh prod
Copy the code

The startupload. sh file was uploaded in batch

Control the version uploaded by parameter
Note that you need to download and configure qshell and account login in advance
/ startupload. sh beta centric
echo "Shell first argument, buildType:The $1"
Delete the server code first
echo 'Start deleting the server ipa..... '
qshell delete yzs apps/centric_The $1/centric.ipa
Upload the API package
echo 'Start uploading ipA.................... '
qshell fput yzs apps/centric_The $1/centric. Ipa /Users/jason_pro/Desktop/ publish folder /mp.ifashioncloud.com_ftp/centric_The $1/centric.ipa
# Refresh file
echo 'Refresh file ipa.......... '
qshell cdnrefresh -i torefresh.txt
Copy the code