关于在travis-ci以及appveyor条件构建遇到的坑

5,162次阅读
11 条评论

共计 2366 个字符,预计需要花费 6 分钟才能阅读完成。

前言

在上篇 《基于 Electron-Vue 开发了一款美图搜罗器》 文章中有提到过关于在自动化构建的方面花费了很长的时间,实际上这是一个相对比较头痛的问题,之前每次 commit 到 github 之后,travis-ci 以及 appveyor 都会进行 build,不过有时候我们就是修改了与业务无关的东西,比如 readme 之类的,不需要重新 build,这个时候我们就需要使用条件构建,这里最好的办法就是通过推送 tag 来进行触发构建。
关于在 travis-ci 以及 appveyor 条件构建遇到的坑

travis-ci

关于在 travis-ci 中,我在官方的文档中并没有找到关于通过 tag 来进行触发构建的说明,可以或许会有遗漏,后面在官方 github 仓库的 issue 中发现了有人曾经提出来过,具体可以参考:https://github.com/travis-ci/travis-ci/issues/6893,于是参考着改了之后我的 .travis.yml 就是如下所示:

osx_image: xcode8.3
sudo: required
dist: trusty
language: c
matrix:
  include:
  - os: osx
if: tag IS present # 这里是添加的之后的部分
cache:
  directories:
  - node_modules
  - "$HOME/.electron"
  - "$HOME/.cache"
addons:
  apt:
    packages:
    - libgnome-keyring-dev
    - icnsutils
    #- xvfb
before_install:
- mkdir -p /tmp/git-lfs && curl -L https://github.com/github/git-lfs/releases/download/v1.2.1/git-lfs-$(["$TRAVIS_OS_NAME" == "linux"] && echo "linux" || echo "darwin")-amd64-1.2.1.tar.gz
  | tar -xz -C /tmp/git-lfs --strip-components 1 && /tmp/git-lfs/git-lfs pull
- if [["$TRAVIS_OS_NAME" == "linux"]]; then sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils; fi
install:
#- export DISPLAY=':99.0'
#- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- nvm install 10
- curl -o- -L https://yarnpkg.com/install.sh | bash
- source ~/.bashrc
- npm install -g xvfb-maybe
- yarn
script:
#- xvfb-maybe node_modules/.bin/karma start test/unit/karma.conf.js
#- yarn run pack && xvfb-maybe node_modules/.bin/mocha test/e2e
- npm run release
branches:
  only:
  - master

appveyor

appveyor 的可以参考官方的 https://www.appveyor.com/docs/appveyor-yml/ 中可以看出,在 appveyor.yml 中添加 skip_non_tags: true 即可使用 tag 来触发构建,于是改了之后我的 appveyor.yml 为:

# Commented sections below can be used to run tests on the CI server
# https://simulatedgreg.gitbooks.io/electron-vue/content/en/testing.html#on-the-subject-of-ci-testing
version: 0.1.{build}

branches:
  only:
    - master

skip_non_tags: true

image: Visual Studio 2017
platform:
  - x64

cache:
  - node_modules
  - '%APPDATA%\npm-cache'
  - '%USERPROFILE%\.electron'
  - '%USERPROFILE%\AppData\Local\Yarn\cache'

init:
  - git config --global core.autocrlf input

install:
  - ps: Install-Product node 8 x64
  - git reset --hard HEAD
  - npm install
  - node --version

build_script:
  - npm run release

test: off

当上面的配置好了之后,我以为到此我就可以愉快的使用 git push --tags 来触发构建了,但是实际情况并不是那么如意,当我试过多次之后并没有触发构建,而是像一只死鱼一般寂静 关于在 travis-ci 以及 appveyor 条件构建遇到的坑
后来终于看到一篇文章 《更简单地用 Travis 自动发布 GitHub Releases》 中提到:

要注意,如果此前设置过 CI 的分支限制,tags: true 不会生效。因为,对 Travis 来说,Tag 也算是一种 branch。

branches:
  only:
    - master

去掉以上代码块,否则自动发布将不会执行。

于是乎,我将 travis-ci 以及 appveyor 配置文件中的相关配置移除,再执行了一次git push --tags,果不其然,成功了!
关于在 travis-ci 以及 appveyor 条件构建遇到的坑

后记

关于持续构建是对于现在的软件编译发布必要的东西,它可以减少大量的重复性的工作而减少我们的工作量,所以未来我会将线上可以进行自动化构建服务全部都完成此操作,加油!关于在 travis-ci 以及 appveyor 条件构建遇到的坑

正文完
使用官方微信小程序体验更多功能
post-qrcode
 12
憧憬Licoy
版权声明:本站原创文章,由 憧憬Licoy 2019-09-14发表,共计2366字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(11 条评论)
木子溯 评论达人 LV.1
2019-11-21 23:53:25 回复

从知乎过来围观一下!

 Windows  Chrome  中国河南省南阳市移动
广东羊城技工学校 评论达人 LV.1
2019-11-07 11:42:45 回复

博主的网站还是很不错的,不过更新要有节奏。还有就是博主,我建议你,网站的界面可以适当修整一下,例如,块的边框可以去掉,这样整站看起来才不会花,才会大气。今天看了你一篇文章解决了一些问题,谢谢。

 Windows  Chrome  中国湖南省株洲市电信
内蒙古股吧 评论达人 LV.1
2019-10-11 15:47:00 回复

能否换个友情链接

 Windows  Chrome  中国内蒙古呼和浩特市电信
头条新闻 评论达人 LV.1
2019-10-04 23:46:36 回复

文章不错非常喜欢

 Windows  Chrome  中国广西贺州市联通
230个网赚博客 评论达人 LV.1
2019-09-22 16:07:32 回复

可以参考官方的

 Windows  Chrome  中国四川省成都市四川广电
repostone 评论达人 LV.1
2019-09-19 16:35:49 回复

非技术的路过。

 Windows  Chrome  中国湖南省永州市移动
托管中心加盟 评论达人 LV.1
2019-09-19 11:58:57 回复

加油!

 Windows  Firefox  中国山东省淄博市电信