When we think of Captain America, we think of a World War II veteran who returns to the real world after 70 years in ice to lead a team of gods and gifted scientists. His charisma, charisma and personality attract the Avengers, and his heart of goodness and justice allows him to pick up Thor’s hammer. If one of the Avengers superheroes has the most perfect qualities, it’s Cap.

There should be a Captain America in every programmer’s heart, who is the embodiment of perfectionism and pursuit of perfection. Programmers write code to pursue no bugs, the pursuit of easy to modify, the pursuit of robust code, the pursuit of rapid release… But sometimes manpower is sometimes poor, we need to rely on external tools, CONTINUOUS integration I believe most of us programmers are familiar, anyone who has used it will say

Of course, there are people who haven’t heard of it, or haven’t used it. Github Action is a new continuous integration tool that allows you to build your own continuous integration stack from scratch.Travis CI got inspired after his research, of course, can also be combined to see, if you can bring a little reference and inspiration, I write the purpose of the article has been achieved.

Continuous Integration (CI) is a software development practice in which team members often integrate their work, usually at least once per day, meaning that integration may occur several times per day. Each integration is verified by an automated build (including compilation, release, and automated testing) to catch integration errors early.” . As a developer, it should be very well understood that even a small change in our code may cause a bug, which may affect the use of the entire product. If the flow is not well monitored to the line, it is really the programmer to heaven 😇😇😇. So we need to monitor the changes and the release of all the links among this, but if done by manpower, neither real nor error-prone, so CI is present, it only need our initial configuration, intermediate inspection link will help us to complete it, or even directly, as iOS developer, we should still a headache for a while this test version to test, Later that test will come and ask for version testing, which will seriously disrupt our own plans and thinking.

Github Actions if you have timeThe official website, some of which are Chinese documents, or relatively easy to read. If you don’t have much time, you can follow the following document to achieve one-click publishing should be no problem.

First we build a new warehouse

We will create a new iOS project in the warehouse and submit it

The GitHub Action has an official workflow script, but it is not available for iOS yet. It is only for languages. So we see that the repository detects that we are swift code and prompts us to install this, although it is not for iOS. But that’s okay, so let’s Set this up, and then we’ll work on it.

Github hook the script when the.github/workflows file was created. Yml was created in the.github/workflows directory. So now the script code is compiled by Swift, which we will change to iOS later. We’ll submit it now and save it for later revision and research.

After submitting, we found that the Action reported error, because the script is not correct, it is normal.

We pull the latest code and look at the local file. We find the swift.yml file, open it and we’re ready to change it.

We don’t have to go into YAML syntax, but of course those who are interested and have time can read Ruan Yifeng’sYAML language tutorialsIf you don’t have time, you can refer to what I wrote to know the general meaning.

# script name
name: iOS Build

# Trigger time
on: [push]

# Workflow
jobs:
  build:
    name: Build phase
    runs-on: macOS-latest
    strategy:
        matrix:
            destination: ['platform = iOS Simulator, OS = 13.2.2, name = iPhone 11']
    steps:
    # Grab code, use someone else's code
    - uses: actions/checkout@master
    Set SSH Keys by writing your own script
    - name: Setup SSH Keys and known_hosts for fastlane match
      PRIVATE_KEY is the environment variable named PRIVATE_KEY in the Secrets directory
      env:
         PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
         PUBLIC_KEY: ${{ secrets.PUBLIC_KEY }}
         HOST: ${{ secrets.HOST }}
           # Copied from https://github.com/maddox/actions/blob/master/ssh/entrypoint.sh
      Set these environment variables to the remote server, so that the remote server has the same permissions as your local computer, otherwise there will be problems with deployment
      run: |
        SSH_PATH="$HOME/.ssh"

        mkdir -p "$SSH_PATH"
        touch "$SSH_PATH/known_hosts"

        echo "$PRIVATE_KEY" > "$SSH_PATH/id_rsa"

        chmod 700 "$SSH_PATH"
        ssh-keyscan github.com >> ~/.ssh/known_hosts
        chmod 600 "$SSH_PATH/known_hosts"
        chmod 600 "$SSH_PATH/id_rsa"

        eval $(ssh-agent)
        ssh-add "$SSH_PATH/id_rsa"

    - name: fastlane build and pgy deploy
      Execute fastlane scripts written by others and configure them as neededUSES: maierj/[email protected] with:Execute the pGY command we wrote
        lane: 'pgy'
        subdirectory: 'fastlane'
      env:
        Use match to automatically manage certificates
        MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}

Copy the code

The Fastlane script is as follows


default_platform(:ios)

platform :ios do

  create_keychain(
      name: "CI",
      password: ENV["MATCH_PASSWORD"],
      default_keychain: true,
      unlock: true,
      timeout: 3600,
      lock_when_sleeps: false
  )
  match(
        git_url: "[email protected]:zhusongyu/certificates.git".type: "adhoc".readonly: true, 
	app_identifier: "com.zsy.actiondemo",
      	keychain_name: "CI",
      	keychain_password: ENV["MATCH_PASSWORD"]
	)
  sh("security list-keychains -d user") 
  sh("security default-keychain -d user")
  sh("security find-identity -v -p codesigning CI")

  lane :pgy do
    xcode_select("/Applications/Xcode.app")
    gym(xcargs: "-UseNewBuildSystem=YES",
        scheme: "GithubActionDemo",
	project: "GithubActionDemo.xcodeproj",
	export_method: "ad-hoc",
      	export_options: {
          compileBitcode: false,
        }  
     )
    pgyer(api_key: "92c0423f53102ddf1f06a92bd0f2fb86", user_key: "4ae6cbc1ef990ff47453be759d93d306",password: "123456", install_type: "2")

    # firim(firim_api_token:"392bc7f0f92622ec086cb47be760b054")
  end
end
Copy the code

Because you are using Fastlane, put the Gemfile file in

The contents of the Gemfile file are as follows

source "https://rubygems.org"

gem "fastlane"
# gem 'cocoapods'

plugins_path = File.join(File.dirname(__FILE__), 'fastlane'.'Pluginfile')
eval_gemfile(plugins_path) ifFile.exist? (plugins_path)Copy the code

SSH, this is a hidden file, need to press CMD + Shift +. Display hidden files and copy the contents of these three files to the corresponding keys

After adding, see the figure below

Since we used Match to automatically manage certificates, we need to create a repository dedicated to managing certificatesMatch uses documentsOr refer to this articleChinese document, briefly summarized as follows

1, create a private repository for Certificates

2. Execute Fastlane Match Init in the project folder

3. Create a Matchfile and execute fastlane match adhoc

4. Generate adhoc certificates

5. Check that the latest certificate has been generated in the warehouse

6, turn off the Xcode automatic management certificate, choose the certificate we just generated, certificate configuration is finished

Since we will create the keystring on the remote server, there will be a keystring password, which we also add to the environment variable and set by ourselves

The configuration should be finished at this point, and the script should be triggered by submitting the code directly to the remote repository. When I submitted the code, the info.plist file was not submitted, so students like me who did not submit the code can make up for it. Finally I deployed to Dandelion and you can see that we have successfully packaged and released.

If you are interested, please try it yourself. I know you are all crawling like maggots at home. 😂😂😂, stay home and explore something interesting while the epidemic is happening

Finally, I hope the epidemic will come to an end soon. Come on, Wuhan, China, 🇨🇳🇨🇳 college