1. 程式人生 > >2018年9月21日(週五)

2018年9月21日(週五)

Travis CI

在GitHub上,可以顯示這樣的小圖示 在這裡插入圖片描述

註冊github賬號

進入github註冊賬號後,按照提示,新建一個可用的專案

授權

新增專案

點選頭像進入settings頁面 在這裡插入圖片描述

新增你想要構建的專案 在這裡插入圖片描述

增加 .travis.yml檔案

在專案內新建檔案 .travis.yml,.travis.yml檔案的作用就是在程式碼提交的時候travis-ci會根據該配置檔案執行配置的任務

常用的配置


language: node_js	// 指定程式語言

sudo: false	// 如果指定為false,則運行於預設的Ubuntu14.04上。也可以通過設定 sudo:enable 來自己指定執行環境

branches:	// 指定構建的分支
  only:	// 指定構建的分支
    - master
  except:	// 過濾構建分支
  	- develop

node_js: // 指定node_js的版本
  - '8'
  - '9'

before_install
	- xx

install:	// 下載構建依賴
  - npm i 

before_script
	-xx 

script:	// 執行命令
  - npm run test

after_script:
  - npm install codecov && codecov // 執行codecov,會自動去https://codecov.io測試覆蓋率

展示圖示

在README.md中加入

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]

name:為github賬戶名,使用自己的使用者名稱替代
project:為專案名,使用自己的專案替代

[npm-image]: https://img.shields.io/npm/v/${project}.svg?style=flat-square
[npm-url]: https://npmjs.org/package/${project}
[travis-image]: https://img.shields.io/travis/${name}/${project}.svg
[travis-url]: https://travis-ci.org/${name}/${project}
[codecov-image]: https://img.shields.io/codecov/c/github/${name}/${project}.svg?style=flat-square
[codecov-url]: https://codecov.io/github/${name}/${project}?branch=master