[Hexo build personal blog] (XI) Hexo blog backup source files - using continuous integration service Appveyor

0 Preface

Before using Hexo framework to build a blog ( Mculover666 personal blog ), at Github and Coding dual-platform deployment, but brought some new problems in the course:

  • Question 1: Hexo automatically deployed to Github only the contents of public folders, and other important content how to do? Sites such as hard configuration profiles and theme configuration file;
  • Question 2: If you replace your computer how to do? Such as how computer labs and home computer sync?
  • Question 3: If the hard drive is broken one day, unfortunately, zezheng?

Simpler approach is to create a Github repository , all the content needs to be backed up are uploaded, so simple and crude effective backup operations, but continued when the backup is more complicated, and each needs to be updated, you first need git push, then hexo d, then there is no way to make us a key to complete these operations it?

The answer of course is there! You can use continuous integration services to help us ~

After using a continuous integration service, when there is a new push to change the blog source warehouse, automatic execution CI script, the latest generation of static websites posted.

1. What is Continuous Integration Services

Continuous Integration Services (full name Continuous Integration, referred to as CI), it is actually a cloud automated build and test service, it binds Github above project, as long as the new code, it will automatically crawl. Then, provide a runtime environment, perform testing, finished its construction, but also to deploy to the server.

Well, such a cloud automated build and testing services, why it is called continuous integration?

Github repository code as long as there is a little change, the service will automatically run the build and test run results feedback, to ensure compliance with expected future, then the new code is "integrated" into the trunk, so the service is called "continuous", "Integration . "

Because most users are on Windows, so in this article we use continuous integration service tool appveyor - for Windows and Linux continuous integration solution.

2. Backup Hexo blog source code to a new warehouse

Create a remote repository on Github:

then initialize the local warehouse and associate it with a remote repository ::

git init
git remote add origin https://github.com/Mculover666/Hexo-Blog-Source.git

We do not need to back up all files, create a .gitignorefile to illustrate ignore files and folders, files typically need to back up are:

  • All content source folders
  • All contents scaffolds folder
  • Site configuration file:_config.yml
  • All content themes folder

In summary, the .gitignorecontents of the file are as follows:

.deploy*/
node_modules/
public/
db.json
package.json
package-lock.json
*.log

Then execute the following command to start the git push:

git add .
git commit -m "hexo source"
git push origin master

3. Use AppVeyor establish CI

Access AppVeyor landing page , using the GitHub账号landing can be.

Then create a new project, add Github repository:

then add the appveyor.ymlfile, as follows:

clone_depth: 5
environment:
access_token:
    secure: [Your GitHub Access Token]
install:
- node --version
- npm --version
- npm install
- npm install hexo-cli -g
build_script:
- hexo generate
artifacts:
- path: public
on_success:
- git config --global credential.helper store
- ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:access_token):[email protected]`n"
- git config --global user.email "%GIT_USER_EMAIL%"
- git config --global user.name "%GIT_USER_NAME%"
- git clone --depth 5 -q --branch=%TARGET_BRANCH% %STATIC_SITE_REPO% %TEMP%\static-site
- cd %TEMP%\static-site
- del * /f /q
- for /d %%p IN (*) do rmdir "%%p" /s /q
- SETLOCAL EnableDelayedExpansion & robocopy "%APPVEYOR_BUILD_FOLDER%\public" "%TEMP%\static-site" /e & IF !ERRORLEVEL! EQU 1 (exit 0) ELSE (IF !ERRORLEVEL! EQU 3 (exit 0) ELSE (exit 1))
- git add -A
- if "%APPVEYOR_REPO_BRANCH%"=="master" if not defined APPVEYOR_PULL_REQUEST_NUMBER (git diff --quiet --exit-code --cached || git commit -m "Update Static Site" && git push origin %TARGET_BRANCH% && appveyor AddMessage "Static Site Updated")

Content only need to replace these files Your GitHub Access Token, replace as follows:

Generating first to Github Access Token, generation method can refer to: Creating A token for Personal Access The Command Line .

In GitHub generate good Access Tokenafter, but also in AppVeyor encryption page and then replaced after the Access Token encryption Your GitHub Access Token:

4. Set Appveyor

Add good appveyor.ymlafter, and then Appveyor portal add the following four variables:

  • STATIC_SITE_REPO: Content Repo address;
  • TARGET_BRANCH: Content Repo's branch (the default is the master)
  • GIT_USER_EMAIL: GitHub account information;
  • GIT_USER_NAME: GitHub account information;


At this point the configuration is complete, after only need to do:

git push

After the source code uploaded to the warehouse, it will automatically push and deployment.

Guess you like

Origin blog.csdn.net/Mculover666/article/details/94837390