Last active
November 8, 2018 15:16
-
-
Save prinsss/42e8781ed3adadbcc6ecac01904a32f6 to your computer and use it in GitHub Desktop.
Travis CI config for Hexo blog automatic deployment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: node_js | |
node_js: stable | |
# 只监听 source 分支的改动 | |
branches: | |
only: | |
- source | |
# 缓存依赖,节省持续集成时间 | |
cache: | |
yarn: true | |
directories: | |
- node_modules | |
- themes | |
before_install: | |
# 解密 RSA 私钥并设置为本机 ssh 私钥 | |
- openssl aes-256-cbc -K $encrypted_1fc90f464345_key -iv $encrypted_1fc90f464345_iv -in .travis/travis.key.enc -out ~/.ssh/id_rsa -d | |
- chmod 600 ~/.ssh/id_rsa | |
# 修改本机 ssh 配置,防止秘钥认证过程影响自动部署 | |
- mv -fv .travis/ssh-config ~/.ssh/config | |
- git config --global user.name "printempw" | |
- git config --global user.email "h@prinzeugen.net" | |
# 赋予自动部署脚本可执行权限 | |
- chmod +x .travis/deploy.sh | |
install: | |
# 安装 Hexo 及其依赖 | |
- yarn | |
# 当 Travis 文件缓存不存在时,从 Gitee 私有仓库 clone 主题 | |
- if [ ! -d "themes/seventeen" ]; then git clone git@gitee.com:printempw/hexo-theme-seventeen.git themes/seventeen; fi | |
script: | |
# 生成静态页面 | |
- hexo clean | |
- hexo generate | |
after_success: | |
# 部署到 GitHub Pages 和 VPS | |
# 我把这一部分的操作直接分离到另外的脚本里去了 | |
- .travis/deploy.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ev | |
export TZ='Asia/Shanghai' | |
# 先 clone 再 commit,避免直接 force commit | |
# 不然整个 branch 就总是只有一个 commit,不好看 | |
git clone -b master git@github.com:printempw/printempw.github.io.git .deploy_git | |
cd .deploy_git | |
git checkout master | |
mv .git/ ../public/ | |
cd ../public | |
git add . | |
git commit -m "Site updated: `date +"%Y-%m-%d %H:%M:%S"`" | |
# 同时 push 一份到自己的服务器上 | |
git remote add vps git@prinzeugen.net:hexo.git | |
git push vps master:master --force --quiet | |
git push origin master:master --force --quiet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment