Gitlab CI 相关
之前工作上主要使用的是私有服务器上搭建的 Gitlab CI 来进行相关的自动化流程,于是也简单介绍一下。以我的理解,Gitlab CI 框架的主要特点是流水线,以及可以通过映像来对运行环境进行预先配置。以下是一个 .gitlab-ci.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 |
image: maven:latest # 运行环境(docker镜像) variables: # 共享的环境变量 MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode" MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" cache: paths: - .m2/repository/ - target/ stages: - build - test - deploy build: # Job1:build stage: build script: - mvn $MAVEN_CLI_OPTS compile test: # Job2:test stage: test script: - mvn $MAVEN_CLI_OPTS test deploy: #Job3:deploy stage: deploy script: - mvn $MAVEN_CLI_OPTS deploy only: - master |
在Appveyor上配置CI
之前与@Genteure的讨论中了解到了这个平台。其优势主要在于可以选择Windows作为运行/测试的环境,对于.Net相关流程的支持也相对更好。出于熟悉的目的,选择了这个平台进行部署。最终的代码如下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 34 35 36 37 38 39 |
version: 1.0.{build} image: Ubuntu1604 environment: github_access_token: secure: ****** branches: except: - gh-pages install: - sh: >- rvm use 2.5.3 # 切换Ruby版本 gem install gepub # docker pull raabf/texstudio-versions:texlive2018 build_script: - sh: >- ruby epub/make_epub.rb for: - branches: only: - master deploy_script: - git config --global user.email "recollectionforgot@gmail.com" - git config --global user.name "Finnite" - git remote rm origin - git remote add origin https://hxdnshx:$github_access_token@github.com/hxdnshx/n8440fe.git - git fetch --all - git checkout gh-pages - git reset @~ - git rebase master - ruby epub/make_epub.rb - sudo chmod +x build_pdf.sh - docker run --rm -v $(pwd):/workdir raabf/texstudio-versions:texlive2018 bash -c /workdir/build_pdf.sh - git add . - git commit -m "update" - git push -f |
build_pdf.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
tlmgr install luatexja mkdir fonts cd fonts wget https://github.com/adobe-fonts/source-han-sans/raw/release/SubsetOTF/SourceHanSansJP.zip wget http://saigetsu.moe/Saigetsu/FZLTXIHK--GBK1-0.TTF unzip SourceHanSansJP.zip mkdir -p /usr/share/fonts/custom cp -r ./SourceHanSansJP/* /usr/share/fonts/custom cp FZLTXIHK--GBK1-0.TTF /usr/share/fonts/custom chmod 744 /usr/share/fonts/custom/* mkfontscale mkfontdir fc-list #下载,安装需要的字体 echo "Finished Font import" cd /workdir latexmk -cd -f -lualatex -interaction=nonstopmode -synctex=1 n8440fe.tex |
通过以上的配置,当自己向 master 分支提交新的变更时,这些变更就会实时通过 CI 反映到pdf上了。不过因为使用的 Tex Live 2018 镜像大小有3.7G,而每次 CI 都要重新进行下载,实测一次 pdf 生成过程需要耗费7分钟左右的时间,可能需要通过 Git Hook 连接到自有的服务器进行生成,才能获得更好的效果了。希望Appveyor之后能提供一些编译环境的缓存机制,避免一下这方面的消耗吧。 注1: