CI is introduced

GitLab CI is a built-in tool for continuous integration of GitLab. You only need to create a. GitLab -ci.yml file in the root directory of the warehouse and configure GitLab Runner. Gitlab will automatically recognize the.gitlab-ci.yml file every time it is submitted and use GitLab Runner to execute the script.

In short, the steps required to have a valid configuration item can be summarized as follows:

Add.gitlab-ci.yml to the root of your repository

Every time you push to Git repository, Runner automatically launches Pipelines and the Pipelines will be displayed under project Pipelines page.

Gitlab – ci configuration

GitLab CI uses YAML files (.gitlab-ci.yml) to manage project configuration. This file is stored at the root of the project repository and contains statements describing how your project is compiled. The YAML file uses a set of constraint statements to define what to do when a Job is started.

.gitlab-ci.ymlfile

CI configuration details

stages:
  - build
  - test
  - deploy

job 1:
  stage: build
  script: xxxx

job 2:
  stage: build
  script: xxxx

job 3:
  stage: test
  script: xxxx

job 4:
  stage: deploy
  script: xxxx
Copy the code

“Stages” indicates that the jobs can be executed concurrently. If the stages are the same, the jobs can be executed according to the stages specified in “Stages”. Script is a shell command that can be executed.

Install Runner to server on GitLab

https://docs.gitlab.com/runner/install/osx.html
Copy the code

The project repository configures the Runner interface

Find the Runner configuration for the current project

The token required by the Runner is configured successfully

Runner is configured, the following can write the corresponding CI script for iOS [script].

IOS CI scenario

Branch merge alert

Dev-2.0 (feature/2.0-room) : dev-2.0 (feature/2.0-room) : dev-2.0 (feature/2.0-room) : dev-2.0 (feature/2.0-room) : dev-2.0 (feature/2.0-room) : dev-2.0 (feature/2.0-room) : dev-2.0 (feature/2.0-room) The tests verify these issues when feature/2.0-room is packaged.

.gitlab-ci.yml

before_script:
    - echo 'this is before script'
    - git version
    - uname -a
    - xcodebuild -version
    - sw_vers

stages:
  - check
  - build
  - test
  - deploy

merge_check:
  stage: check
  tags:
    - check
  script:
    - echo "Merge Check..."
    - pwd
    - python3 -u ci/merge_check.py $CI_COMMIT_REF_NAME
  only:
    - /^feature.*$/
Copy the code

*$/ indicates that merge_check is performed only if my branch name matches /^feature.*$/. Tags represent which tag of the Runner service I need to dispatch.

Main branch code check

before_script:
    - echo 'this is before script'
    - git version
    - uname -a
    - xcodebuild -version
    - sw_vers

stages:
  - check
  - build
  - test
  - deploy

code_style_check:
  stage: check
  tags: 
    - check
  script:
    - echo "Code Style Check..."
    - pwd
    - git fetch
    - echo "Source Branch " $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
    - echo "Target Branch " $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
    - git diff origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME. origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME -- '*.h' '*.m' -U0 | grep '^' [+] | grep -Ev '^(--- a/|\+\+\+ b/)' | sed 's/^+//' > ./tmp.diff || echo 'nothing to diff' > ./tmp.diff
    - python3 code_style_check.py $CI_MERGE_REQUEST_TARGET_BRANCH_NAME $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
  only:
    - merge_requests
Copy the code

Merge_requests triggers code_STYle_check only when feature services are merged into dev. GIF diff: dev/feature/TMP. Diff: dev/feature/TMP.

def rule_else(line):
    if '}else' in line or 'else{' in line:
        print("❌ else need Spaces:} else {", flush=True)
        stop(line, 'spaces around else')


def rule_if(line):
    if 'if(' in line:
        print("❌ if(need space in between", flush=True)
        stop(line, 'spaces after if')


def rule_space(line):
    if ') {' in line:
        print("❌ requires space){->){", flush=True)
        stop(line, 'space between ){')


def rule_string_define_copy(line):
    if 'NSString' in line and '@property' in line and 'copy' not in line and '<' not in line:
        print("❌ NSString needs to be decorated with copy.", flush=True)
        stop(line, 'NSString need copy')


def rule_comma(line):
    if ', ' in line and ',\n' not in line and ', ' not in line and ', "' not in line:
        print("❌ comma with Spaces to the right", flush=True)
        stop(line, 'space after comma')
Copy the code

As part of the script for code inspection, tmp.diff is scanned for each line to check whether it conforms to iOS development specifications.