There are many operations that need to be performed during the first componentization. These operations can be described in “iOS Componentization development (I) : Basic Use of Remote private Libraries”, which will not be described here. The repetitive operation after componentization is the upgrade, and the upgrade process is exactly the same. So, what can we do to simplify this process and save a lot of time?

1. Mandatory upgrade operations

After modifying the core code, there are a total of the following steps: Modify the spec file (s.sion, s.description, etc.). Download pod install (pod install). And to a private index library

Second, the Fastlane

1, the introduction of

Fastlane is a collection of Ruby scripts that do what we want to do at a given location, along a path we specify. We call such a route a “lane” and such an operation an “Action”

Action is the smallest execution unit in the Fastlane automation process, which is used to execute commands in Fastlane scripts. For more information, you can refer to the Actions – Fastlane Docs, which also describes the common Actions. This source code is used for reference in the following customization

2, installation,

  • Make sure Ruby is up to date
brew update
brew install ruby
Copy the code
  • Install the fastlane
sudo gem install -n /usr/local/bin fastlane
Copy the code
  • View the current fastlane version
fastlane --version
Copy the code
  • View all actions
fastlane actions
Copy the code

Fastlane initialization

CD to the root directory of your local component repository

  • Initialize the fastlane fastlane init But for us, we can skip that step and just say init and prompt you to type in some stuff, including the APPLE ID that you need to upload and all that stuff, and since we’re not going to do that, we’re going to do it in a more convenient way, okay
Create a Fastlane folder
Enter the Fastlane directory
Create a Fastfile file
mkdir fastlane
cd fastlane
touch Fastfile
Copy the code

1. Modify Fastfile

desc 'Describing hydrographic action'Lane: indicates the name of a shipping channeldo| options | / / options can be used to pass parameters / / example: varName = options [: name] / / channel needs to perform operations on the endCopy the code

The Actions to be scanned on the channel can be searched by Actions and keywords, as shown in the figure below

Attached here is my Fastfile:

desc 'LXFUpdatePodTool channel for automatic upgrade and maintenance of private libraries'
lane : LXFUpdatePodTool do |options|

tagNum = options[:tag]
podspecName = options[:specName]

# Operations to be performed on fairway
# concrete action to https://docs.fastlane.tools/actions search
The path here is the root directory of the warehouse

# 1 modify the spec file (modify S.sion, S.description, etc.)
# 2, pod install
cocoapods(
  clean: true,
  podfile: "./Example/Podfile"
)


Commit the local repository code to the remote repository
git_add(path: ".")
git_commit(path: ".", message: "upgrade repo")
push_to_git_remote


# 4. Tag and submit to remote
add_git_tag(
  tag: tagNum
)
push_git_tags


Validate the spec and bring it to the private index library
pod_lib_lint(allow_warnings: true)
Since the name of the local index library repo is basically unchangeable, LXFSpecs is dead here
The podSpec name needs to be passed in
pod_push(path: "#{podspecName}.podspec", repo: "LXFSpecs")


end
Copy the code

2. Validate Fastfile

fastlane lanes
Copy the code

3. Implement Fastlane

It needs to be executed in the root directory of the component repository

Fastlane LXFUpdatePodTool tag: while specName: LXFMainCopy the code

The entire execution takes no more than 30 seconds

4. Customize actions

The above process can be finished a whole automatic update, but it should be noted that the input of the tag may face a problem, that is local and remote may already exists, namely the conflict, at this time we can choose to automatically delete local and remote conflict that tag, upload again the current tag

Create a new action

fastlane new_action
Copy the code

Enter the Action name as required

Once you’re done, you’ll have a new folder in your Fastlane directory called Actions, which will hold your custom actions

2. Edit custom actions

Open remove_git_tag.rb and start customizing our actions. What? What if you don’t know grammar? You can refer to the source address of the action, such as pod_push. Here I’ll just post the main code I’ve done

You can use fastlane Action remove_git_tag to see the detailed description

def self.run(params)
  Write the operation to be performed here
  # params[: parameter name] The parameter name is the same as in self.available_options below
  tagNum = params[:tagNum]
  rmLocalTag = params[:rmLocalTag]
  rmRemoteTag = params[:rmRemoteTag]

  command = []
  if rmLocalTag
    Delete local tags
    Git tag -d git tag
    command << "git tag -d #{tagNum}"
  end
  if rmRemoteTag
    Delete the remote tag
    Git push origin
    command << "git push origin :#{tagNum}"
  end

  result = Actions.sh(command.join('&'))
  UI.success("Successfully remove tag 🚀")
  return result

end

def self.description
  A brief description of the current script
  "Remove the tag"
end

def self.details
  # A detailed description of the current script
  Use current action to remove conflicting local and remote tags
end

def self.available_options
  # is used to pass arguments
  [ 
    FastlaneCore::ConfigItem.new(key: :tagNum,
                                  description: "Enter the tag to be deleted",
                                  is_string: true),
    FastlaneCore::ConfigItem.new(key: :rmLocalTag,
                                  description: "Delete local tag",
                                  optional:true,
                                  is_string: false,
                                  default_value: true),
    FastlaneCore::ConfigItem.new(key: :rmRemoteTag,
                                  description: "Delete remote tag",
                                  optional:true,
                                  is_string: false,
                                  default_value: true)
  ]
end

def self.authors
  # Author name
  ["LinXunFeng"]
end
Copy the code

3. View the action description

Again, this is done in the root directory of the component library. The reason is that this custom action exists only in the fastlane directory of the current root directory. Other non-custom Fastlane actions do not need to operate in the current root directory

fastlane action remove_git_tag
Copy the code

4. Test execution

Let’s start by looking at the tags that already exist in the current component library

git tag
Copy the code

As you can see, I already have a 0.1.1 version. At this point, we will execute the LXFUpdatePodTool channel again

Fastlane LXFUpdatePodTool tag: while specName: LXFMainCopy the code

Five, tools away

LXFUpdatePodTool has been uploaded to my GitHub. If you need it, please take it and give it to Star Orz