Cocoapods 与 Travis-CI

Cocoapod 与 Travis-CI

Travis-CI 是一个专门为开源项目打造的持续集成环境,与Github高度集成.支持iOS/macOS构建服务.

1. 使用Github账号登录travis

1
- 会自动同步gitbub下仓库目录

2. 配置.travis.yml文件

Routable开源库为例

默认.travis.yml文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# references:
# * http://www.objc.io/issue-6/travis-ci.html
# * https://github.com/supermarin/xcpretty#usage

osx_image: xcode7.3
language: objective-c
# cache: cocoapods
# podfile: Example/Podfile
# before_install:
# - gem install cocoapods # Since Travis is not always on latest version
# - pod install --project-directory=Example
script:
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace Example/Routable.xcworkspace -scheme Routable-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
- pod lib lint

.travis.yml修改版:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 采用新版xcode9编译[主要是swift语法版本问题]
osx_image: xcode9
# objective-c/swift 都采用 objective-c 配置
language: objective-c

cache: cocoapods
podfile: Example/Podfile

env:
global:
- LANG=en_US.UTF-8
- LC_ALL=en_US.UTF-8
# 项目路径
- XCODE_WORKSPACE=Example/Routable.xcworkspace
matrix:
# 项目名
- SCHEME="Routable-Example"

before_install:
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
- gem install cocoapods --pre --no-rdoc --no-ri --no-document --quiet
# 如果依赖其他库,最好加上
- pod repo update
- pod install --project-directory=Example

script:
- set -o pipefail
- xcodebuild -workspace "$XCODE_WORKSPACE" -scheme "$SCHEME" -configuration Debug clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty -c
- xcodebuild -workspace "$XCODE_WORKSPACE" -scheme "$SCHEME" -configuration Release clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty -c
- pod lib lint --allow-warnings

after_success:
- sleep 3

3. 开启CI服务

  • 登录travis

  • 之后后我们 GitHub 项目 Setting 中的 Integrations & services 已经添加了 Travis CI 服务.

4. 触发构建服务

Git push会触发构建服务,同时在github上也有所指示.

github:

travis:

5.错误日志

构建失败时,在job log会输出相应日志.

6.构建徽章 Get!

在项目readme.md中插入:

1
[![build](https://travis-ci.org/[user]/[repo].svg?branch=master)](https://travis-ci.org/[user]/[repo])

🌰:

1
[![build](https://travis-ci.org/linhay/Routable.svg?branch=master)](https://travis-ci.org/linhay/Routable)