基於Travis CI實現 Gitbook在 Github 和 Coding 的同步部署

hanyajun發表於2019-05-18

前言

最近發現自己的部落格在使用vpn的情況下開啟很慢,百度站點也抓取失敗,於是將自己的部落格藉助hexo-deploy 外掛很容易同步部署到了coding上。只需要在你的hexo配置檔案_config.yml的deploy配上coding的coding page專案url(注意將ssh key 設定好)

deploy:
- type: git
  repository: 
    - git@github.com:Han-Ya-Jun/Han-Ya-Jun.github.io.git
    - git@git.dev.tencent.com:hanyajun0123/hanyajun0123.git
  branch: master
  message: update
- type: baidu_url_submitter

配置後於是在阿里雲的域名解析上新增兩條CNAME記錄指向 hanyajun0123.coding.me,選擇預設解析,原來github的解析換成國外的dns解析路線,這樣國內的就指向coding,國外的指向github.io 訪問的時候出現了下面的這種異常(您的連結不是私密連結) 看了下coding的證書申請情況也是一直失敗 後來查了下資料發現得先暫停掉原先指向github.io的解析,這個會對與coding page進行校驗。後來停掉再次申請ssl證書就成功了,本來以為完美解決了,誰知自己部署在github page的gitbook的專案訪問不了,翻牆之後就可以訪問了,這個很好解釋,不翻牆就解析到了coding上。於是自己又琢磨了下如何基於travis ci實現gitbook在github和coding的自動化ci。如果之前沒有嘗試過使用travis ci來部署gitbo的可以參考下我之前寫的一篇部落格《如何使用travis-ci自動化構建部署GitHub Pages(gitbook)》

CI流程

獲取coding訪問令牌

travis新增coding token環境變數

在Travis上原來github部署ci的gitbook專案裡面新增訪問coding token。

修改.travis.yaml 檔案

after_script:
   - cd ./_book
   - git init
   - git config user.name "*****" 
   - git config user.email "******"
   - git add .
   - git commit -m "Update Gitbook By TravisCI With Build $TRAVIS_BUILD_NUMBER"
   - git push --force --quiet "https://hanyajun0123:${CODING_TOKEN}@${CO_REF}" master:master
   - git tag v0.0.$TRAVIS_BUILD_NUMBER -a -m "Auto Taged By TravisCI With Build $TRAVIS_BUILD_NUMBER"
   - git push --quiet "https://hanyajun0123:${CODING_TOKEN}@${CO_REF}" master:master --tags

# git@git.dev.tencent.com:hanyajun0123/coding_basis_review.git
env:
 global:
   # Coding Pages
   - CO_REF: git.dev.tencent.com/hanyajun0123/coding_basis_review.git

完整.travis.yaml檔案

觸發ci

修改本地gitbook專案,推送到github上去,就可以粗發ci了。

Creating a brand new local repo from scratch in dir /tmp/d20190517-7047-qvpbfn/work...
dpl.2
Preparing deploy
dpl.3
Deploying application
Initialized empty Git repository in /tmp/d20190517-7047-qvpbfn/work/.git/
Repo created successfully
Switched to a new branch 'gh-pages'
An orphan branch gh-pages created successfully
cd -
cd /tmp/d20190517-7047-qvpbfn/work
Copying /home/travis/build/Han-Ya-Jun/coding_basis_review/_book contents to /tmp/d20190517-7047-qvpbfn/work (workdir: /tmp/d20190517-7047-qvpbfn/work)...
Configuring git committer to be Deployment Bot (from Travis CI) <deploy@travis-ci.org> (workdir: /tmp/d20190517-7047-qvpbfn/work)
Preparing to deploy gh-pages branch to gh-pages (workdir: /tmp/d20190517-7047-qvpbfn/work)
commit 76413d48b1f036c4b9c9b4e3fbad583fa24aa87a
Author: Deployment Bot (from Travis CI) <deploy@travis-ci.org>
Date:   Fri May 17 01:15:08 2019 +0800
    Deploy Han-Ya-Jun/coding_basis_review to github.com/Han-Ya-Jun/coding_basis_review.git:gh-pages
 .travis.yml                                        |  49 ++
 generation                                         |   0
 gitbook/fonts/fontawesome/FontAwesome.otf          | Bin 0 -> 124988 bytes
 gitbook/fonts/fontawesome/fontawesome-webfont.eot  | Bin 0 -> 76518 bytes
 gitbook/fonts/fontawesome/fontawesome-webfont.svg  | 685 +++++++++++++++++++++
 gitbook/fonts/fontawesome/fontawesome-webfont.ttf  | Bin 0 -> 152796 bytes
 gitbook/fonts/fontawesome/fontawesome-webfont.woff | Bin 0 -> 90412 bytes
 .../fonts/fontawesome/fontawesome-webfont.woff2    | Bin 0 -> 71896 bytes
 gitbook/gitbook-plugin-3-ba/plugin.js              |  20 +
 .../gitbook-plugin-back-to-top-button/plugin.css   |  55 ++
 ...
 51 files changed, 6434 insertions(+)
Doing the git push (workdir: /tmp/d20190517-7047-qvpbfn/work)...
On branch gh-pages
nothing to commit, working tree clean
cd -
App has been pushed
after_script.1
0.01s$ cd ./_book
after_script.2
0.01s$ git init
Initialized empty Git repository in /home/travis/build/Han-Ya-Jun/coding_basis_review/_book/.git/
after_script.3
0.01s$ git config user.name "hanyajun0123"
after_script.4
0.01s$ git config user.email "1581532052@qq.com"
after_script.5
0.05s$ git add .
after_script.6
0.02s$ git commit -m "Update Gitbook By TravisCI With Build $TRAVIS_BUILD_NUMBER"
[master (root-commit) 1c86337] Update Gitbook By TravisCI With Build 10
 51 files changed, 6434 insertions(+)
 create mode 100644 .travis.yml
 create mode 100644 generation
 create mode 100644 gitbook/fonts/fontawesome/FontAwesome.otf
 create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.eot
 create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.svg
 create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.ttf
 create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.woff
 create mode 100644 gitbook/fonts/fontawesome/fontawesome-webfont.woff2
 create mode 100644 gitbook/gitbook-plugin-3-ba/plugin.js
 create mode 100644 gitbook/gitbook-plugin-back-to-top-button/plugin.css
 create mode 100644 gitbook/gitbook-plugin-back-to-top-button/plugin.js
 create mode 100644 gitbook/gitbook-plugin-disqus/plugin.css
 create mode 100644 gitbook/gitbook-plugin-disqus/plugin.js
 create mode 100644 gitbook/gitbook-plugin-donate/plugin.css
 create mode 100644 gitbook/gitbook-plugin-donate/plugin.js
 create mode 100644 gitbook/gitbook-plugin-editlink/plugin.js
 create mode 100644 gitbook/gitbook-plugin-fontsettings/fontsettings.js
 create mode 100644 gitbook/gitbook-plugin-fontsettings/website.css
 create mode 100644 gitbook/gitbook-plugin-ga/plugin.js
 create mode 100644 gitbook/gitbook-plugin-github-buttons/plugin.js
 create mode 100644 gitbook/gitbook-plugin-github-buttons/plugin.js.map
 create mode 100644 gitbook/gitbook-plugin-github/plugin.js
 create mode 100644 gitbook/gitbook-plugin-image-captions/image-captions.css
 create mode 100644 gitbook/gitbook-plugin-page-toc-button/plugin.css
 create mode 100644 gitbook/gitbook-plugin-page-toc-button/plugin.js
 create mode 100644 gitbook/gitbook-plugin-prism/prism-coy.css
 create mode 100644 gitbook/gitbook-plugin-prism/prism-dark.css
 create mode 100644 gitbook/gitbook-plugin-prism/prism-funky.css
 create mode 100644 gitbook/gitbook-plugin-prism/prism-okaidia.css
 create mode 100644 gitbook/gitbook-plugin-prism/prism-solarizedlight.css
 create mode 100644 gitbook/gitbook-plugin-prism/prism-tomorrow.css
 create mode 100644 gitbook/gitbook-plugin-prism/prism-twilight.css
 create mode 100644 gitbook/gitbook-plugin-prism/prism.css
 create mode 100644 gitbook/gitbook-plugin-search-plus/jquery.mark.min.js
 create mode 100644 gitbook/gitbook-plugin-search-plus/search.css
 create mode 100644 gitbook/gitbook-plugin-search-plus/search.js
 create mode 100644 gitbook/gitbook-plugin-sharing/buttons.js
 create mode 100644 gitbook/gitbook-plugin-splitter/splitter.css
 create mode 100644 gitbook/gitbook-plugin-splitter/splitter.js
 create mode 100644 gitbook/gitbook-plugin-tbfed-pagefooter/footer.css
 create mode 100644 gitbook/gitbook.js
 create mode 100644 gitbook/images/apple-touch-icon-precomposed-152.png
 create mode 100644 gitbook/images/favicon.ico
 create mode 100644 gitbook/style.css
 create mode 100644 gitbook/theme.js
 create mode 100644 index.html
 create mode 100644 network/TCP_IP.html
 create mode 100644 network/summary.html
 create mode 100644 package-lock.json
 create mode 100644 search_plus_index.json
 create mode 100644 sitemap.xml
after_script.7
3.87s$ git push --force --quiet "https://hanyajun0123:${CODING_TOKEN}@${CO_REF}" master:master
after_script.8
0.01s$ git tag v0.0.$TRAVIS_BUILD_NUMBER -a -m "Auto Taged By TravisCI With Build $TRAVIS_BUILD_NUMBER"
after_script.9
1.65s$ git push --quiet "https://hanyajun0123:${CODING_TOKEN}@${CO_REF}" master:master --tags
Done. Your build exited with 0.

相關文章