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 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 image above.
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 patiently for the Travis CI build to finish. This article was generated through automated building.