Previously, I used to generate my hexo blog on my computer and then push it to a github repo. Now, I feel that it's a bit troublesome just lazy so I thought about whether I could use travis-ci to automate the building of my blog.
Preparation#
Create branches#
The method I used is to create two branches on the github repository, master
and source
, to store the generated website files and the source files respectively.
Write travis configuration file#
The file content is as follows:
language: node_js
node_js: stable
branches:
only:
- source
cache:
apt: true
yarn: true
directories:
- node_modules
before_install:
- git config --global user.name "johnpoint"
- git config --global user.email "[email protected]"
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
- npm install -g hexo-cli
install:
- yarn
script:
- npm install hexo-renderer-pug --save
- npm install hexo-renderer-sass --save
- npm install hexo-generator-feed --save
- hexo clean
- hexo generate
after_success:
- mkdir push
- cd ./push
- git clone https://github.com/johnpoint/johnpoint.github.io .
- rm * -rf
- cp ../public/* . -r
- git add --all .
- git commit -m "Travis CI Auto Builder"
- git push --quiet https://[email protected]/johnpoint/johnpoint.github.io
master
Configure github key#
Because I had enabled two-factor authentication on github before, I can no longer use the original github username + password method for authentication when pushing.
Add a name called REPO_TOKEN and a value of Personal access tokens at the location shown in the above image.
Waiting for the build to start#
In general, the work to be done has already been completed, and all that is left is to wait quietly for the travis-ci build to finish. This article was generated through automated building.