1. travis-ci自动更新gh-pages分支

https方式push

1.1.1. 生成token

https://github.com/settings/tokens > 勾上public_repo > Generate token

1.1.2. Travis添加GITHUB_API_KEY的环境变量

  • 方法一

https://travis-ci.org/<me>/<myrepo>/settings 添加GITHUB_API_KEY=<token>, "Display value in build log" 设置为 "Off".

  • 方法二

进入仓库根目录下运行 travis encrypt -a GITHUB_API_KEY <token> GITHUB_API_KEY会自动加到.travis.yml

.travis.yml

after_success:
- "./scripts/deploy.sh"

deploy.sh

  • 方法一

git push -f 方式直接替换仓库文件

cd ${BLOG_DIRECTORY}/_book
git init
git config user.email "bell@greedlab.com"
git config user.name "Bell"
git add .
git commit -m "Deploy to GitHub Pages by travis"
git push -f -q https://GreedBell:${GITHUB_API_KEY}@${GITHUB_REF} HEAD:gh-pages > /dev/null 2>&1
  • 方法二

git remote add upstream 方式添加远程仓库,更新仓库

cd ${BLOG_DIRECTORY}/_book
git init
git config user.email "bell@greedlab.com"
git config user.name "Bell"
git remote add upstream https://GreedBell:${GITHUB_API_KEY}@${GITHUB_REF}
git fetch upstream
git reset upstream/gh-pages
git add .
git commit -m "Deploy to GitHub Pages by travis"
git push -q upstream HEAD:gh-pages

1.1.3. Reference

results matching ""

    No results matching ""