前言
在上篇《基于Electron-Vue开发了一款美图搜罗器》文章中有提到过关于在自动化构建的方面花费了很长的时间,实际上这是一个相对比较头痛的问题,之前每次commit到github之后,travis-ci以及appveyor都会进行build,不过有时候我们就是修改了与业务无关的东西,比如readme之类的,不需要重新build,这个时候我们就需要使用条件构建,这里最好的办法就是通过推送tag来进行触发构建。
travis-ci
关于在travis-ci中,我在官方的文档中并没有找到关于通过tag来进行触发构建的说明,可以或许会有遗漏,后面在官方github仓库的issue中发现了有人曾经提出来过,具体可以参考:https://github.com/travis-ci/travis-ci/issues/6893,于是参考着改了之后我的.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 34 35 36 37 38 39 | 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
为:
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 | # 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自动发布GitHub Releases》中提到:
要注意,如果此前设置过CI的分支限制,tags: true不会生效。 因为,对Travis来说,Tag也算是一种branch。
123 branches:only:- master去掉以上代码块,否则自动发布将不会执行。
于是乎,我将travis-ci以及appveyor配置文件中的相关配置移除,再执行了一次git push --tags
,果不其然,成功了!
后记
关于持续构建是对于现在的软件编译发布必要的东西,它可以减少大量的重复性的工作而减少我们的工作量,所以未来我会将线上可以进行自动化构建服务全部都完成此操作,加油!
2019年09月19日 下午4:35 11楼
非技术的路过。
2019年09月19日 上午11:58 12楼
加油!
2019年09月20日 下午7:07 1层
@托管中心加盟 好的谢谢