雖然golang的工程工具已經很是完善了,好比測試、代碼格式化等等。可是若是開發library開源到github的話,這些東西是能夠使用自動化工具完成的,那就是 travisgit
1.開發好須要集成的library以及測試用例
2.在項目根目錄新建.travis.yml
文件github
language: go go: - 1.x - '1.8' - '1.9' - 1.10.x script: - go test -v ./... env: global: secure: kr5JHNTYsh/jezvk88qP91arb+UD/op/5CyOFY7uNYpJ6ZSsJY5fDKyZHjf0VSFmaYqJFMPl6uCASE9baiepeGvBFcy8aI9CNsbLzj2uBNjqqYPmvYGnBjpzp8yknVJKRTitF/kkWtzZcWImHnpvNGHuzXxp/EIBeJtNwjcCRoP/qfGhlZKbLsYFvlWkmRYb0dr8RM5mlmGXPZi8q7m+soVRO8Zjr4QQccybgmhonxlcUrHr6ro+yjjQefoJXRufqoRX0sGyecGYucC4nUpWl5hkDPkQE+Mekhz+rF657SwNsn8nXOFnnUuwsPXE26ak5xF1roEcFk2CpwGZuT7smJZPtw1inXFdIaW+4qllbyxMJkylvFZa5IcvLT3+/eKaQc8Fg6PoxJH0PF3RdtoQVB31cQiPWNm1SecQ6wC64WA/5qN4T5OoRfpt60BFDAITdS62dQGu5LSepcXMWXhxCdQPeDm5Qce6wjJXURubJMpBm0mPWwCNZhJyRw1G5TTyO25NckXQRlObrjltvwAd+7OEUcsYXqhdPtUTIVy6w3XOwT2eC/hP0Yi7qqUMMlJTHUW7Lb9zsEc4UB5BVwgeZ5Y9bVbknJfpt3ygcXAJeeDYxwV9g16KoS7HMFPzwrqlHbiBytIahqarBd4enwqR5RYQPEyetiIDLaJA4SyQ0cE= notifications: email: recipients: - 1065890063@qq.com on_success: always
3.提交到github
4.打開https://www.travis-ci.org/並使用github帳號登陸
5.登陸以後點擊左邊 "My Repositories" 旁邊的 "+" 號添加項目(點擊項目前面的滑塊便可)
6.更改項目文件,push一次到github,此時travis會自動運行測試腳本golang
若是你的測試用例須要使用到敏感數據(如一些密鑰等等),那須要用travis將你的敏感數據加密(以Mac爲例)工具
sudo gem install travis
travis encrypt AMAP_KEY="xxxx" --add
AMAP_KEY是環境變量名稱,程序讀取環境變量能夠獲得真實的key,xxxx是敏感數據執行完畢後,.travis.yml 會發生更改, 會添加以下內容(secure可能不一致)測試
env: global: secure: kr5JHNTYsh/jezvk88qP91arb+UD/op/5CyOFY7uNYpJ6ZSsJY5fDKyZHjf0VSFmaYqJFMPl6uCASE9baiepeGvBFcy8aI9CNsbLzj2uBNjqqYPmvYGnBjpzp8yknVJKRTitF/kkWtzZcWImHnpvNGHuzXxp/EIBeJtNwjcCRoP/qfGhlZKbLsYFvlWkmRYb0dr8RM5mlmGXPZi8q7m+soVRO8Zjr4QQccybgmhonxlcUrHr6ro+yjjQefoJXRufqoRX0sGyecGYucC4nUpWl5hkDPkQE+Mekhz+rF657SwNsn8nXOFnnUuwsPXE26ak5xF1roEcFk2CpwGZuT7smJZPtw1inXFdIaW+4qllbyxMJkylvFZa5IcvLT3+/eKaQc8Fg6PoxJH0PF3RdtoQVB31cQiPWNm1SecQ6wC64WA/5qN4T5OoRfpt60BFDAITdS62dQGu5LSepcXMWXhxCdQPeDm5Qce6wjJXURubJMpBm0mPWwCNZhJyRw1G5TTyO25NckXQRlObrjltvwAd+7OEUcsYXqhdPtUTIVy6w3XOwT2eC/hP0Yi7qqUMMlJTHUW7Lb9zsEc4UB5BVwgeZ5Y9bVbknJfpt3ygcXAJeeDYxwV9g16KoS7HMFPzwrqlHbiBytIahqarBd4enwqR5RYQPEyetiIDLaJA4SyQ0cE=
若是你須要獲取travis執行結果通知的話,能夠添加郵箱配置,travis執行完畢後會通知到該郵箱。加密
1.打開 .travis.yml
2.添加如下內容:code
notifications: email: recipients: - 郵箱地址 on_success: change on_failure: always
3.提交到githubip