Travis IC realization Hexo blog use automated deployment

1.Hexo blog pros and cons

Hexo Chinese

I see people default to have a better understanding of this article Hexo blog, you are also able to successfully deploy it manually. So the first part of two articles recommend a passing, let us quickly into the focus of this article. Really do not know and do not look side to recommend the following two articles.

Taught you how to use Hexo + Github Pages set up independent personal blog - Linghu green onions

Hexo + github to build personal blog --zdy0_2004

There is also a column:
HEXO / total 13 - cold water

Thanks to the original author of the above article to share, recommend pure water. After reading these two articles did not feel their own hands Hexo blog very magical, very easy to use it? In fact, I would say that this time Hexo just a disability, please? You think about playing this blog system you must love toss off technology, such as Xiao Ming has eight computers, he would have eight computers on the installation environment, and deployment really is a little weary of the fairies, it is likely to weird problem occur. For example, I have done this a pure thing, profile new to Hexo soon when _conffig.ymlthere is a piece of code like this:

language: cn
timezone: Asia/Shanghai

I unrequited love to the time zone change Beijing, and then there is a problem can not be deployed. After a long time a chance to see someone else's article came to understand that the time zone is not changed, the drunk is, after mistakes novice really hard to know cause of the error. So if you can not write cross-terminal, automatic deployment, what Hexo the blog function count it? Considered disabled, yes!

To solve these problems, we use today to share what Travis IC Hexo blog implement automated deployment, so dry is finally realize the benefits of multi-terminal publishing blog articles without change once the computer once installed environment.

2.Travis IC solve the problem

Here we will temporarily introduce Travis IC, and interested can go to look at later in this article, we use it to solve the problem directly.

Backup 2.1

Hexo blog source files and file repository Github Pages (static pages generated by the Web site files). If you replace the computer, you must first copy the source files to the new computer, and then clone the GitHub Page to a local warehouse.

The final is to be formed so that both local folder

2.2 Backup uploads

Upload files backed up to GitHub. Since Github Pages warehouse so that we just copied down, so do not ignore it, focusing on the source file. This time you use two options:
The first is a common practice: direct new branch in Github Pages warehouses, upload source files to branch them.
The second article is to introduce to the method: direct new warehouse, upload source files to the new warehouse them.
In fact, on these two methods of operation can be said almost exactly the same, except that the second method can create private warehouse, other people can not see your source file.

Do not hurry to make a choice, select the second method you want to know, Travis CI has two sites, travis-ci.org specifically for open-source projects, all of the public on Github repository can be free; travis-ci.com for private and commercial projects, construction of the first 100 new users are free, we must back the charges.

In other words, if you are not GitHub Pro, it chose the first method or second method is to set public warehouses, and to operate in travis-ci.org in.

2.3 Log Travis CI website,

Access travis-ci.org or travis-ci.com "Sign up with Github" Github account using their own login. Then you can go to the Applications github to find Travis CI.

Click congigure, we give it access to a good source backup file repository.

2.4Travis CI Basic Configuration

In order to enable the code push Github, need to Persional access tokens Travis CI Github in settings- Developer settings may generate a.

Give permission to repo

Note: The generated token just once, so be sure to save in time down, otherwise, they can re-create deleted.

Travis item and then enter the setting interface may be provided to a specific code libraries, such as increasing environmental variables: number of values can be passed (the password is not easy to write in the configuration file provided by the environment variable in Travis CI, the key class), where we set the environment variables are used to pass GH_TOKGH GitHub Personal Access Token.
Note: If you are here to set the environment variable name is not two, when .travis.yml below corresponds to the configuration of your variable names.

Finally Travis warehouse configuration interface is also more option - ssetting inside environment variables Environment Variables configure token ease of reference in the build file, NAME named GH_TOKGH, as shown below

2.5 Configuration .travis.yml

Add .travis, yml configuration file in the source file blog branches, decide how to execute build tasks.

Here's what .travis, yml of:

language: node_js
node_js: stable

cache:
    apt: true
    directories:
        - node_modules

notifications:
    email:
        recipients:
            - [email protected] #你的邮箱地址
        on_success: change
        on_failure: always

# turn off the clone of submodules for change the SSH to HTTPS in .gitmodules to avoid the error
git:
  submodules: false
        
before_install:
    - export TZ='Asia/Shanghai'
    - npm install hexo-cli -g

install:
    - npm install

script:
    - hexo clean
    - hexo g

after_script:
  - cd ./public
  - git init
  - git config user.name "xxx"
  - git config user.email "[email protected]"
  - git add .
  - git commit -m "Update blog content by Travis CI"
  - git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:master

branches:
    only:
        - master

env:
    global:
        # Github Pages
        - GH_REF: github.com/xxxr/xxx.github.io.git
        # Coding Pages
        - CD_REF: git.coding.net/xxxr/xxx.git

Code in another environment variable name GH_REF to Github Pages warehouse address envhas a value.
Note: xxx is your GitHub user name, xxx @ gmail.com replace your registered email address in the GitHub

2.5 Test

Online spread a very common .travis.yml configuration code, you can easily search, many people use, but it does not work with me. Push through native code to GitHub so on more than 30 seconds to see Travis CI reaction, this process is always an error if that is true, then ...... it was great!


Pleated thousand back, slowly try, also made reference to a lot of heavyweights in the ultimate success of the code with the code given above

18 times! Properly properly 18 times, if you step on the pit, do not hurry, try to modify, adjust 18 times.

3. Experience

3.1 After the SSH key for the computer to re-apply

3.1.1 generate new SSH Key

$ ssh-keygen -t rsa -C "邮件地址@youremail.com"

as the picture shows:

Then to enter a password, do not enter if the project submitted is empty words. This setting is to prevent others to submit content to your project.

Enter passphrase (empty for no passphrase):<输入加密串>
Enter same passphrase again:<再次输入加密串>

After the key generation in your C:\Users\你的用户名\.sshcan see the following files

and then you can copy id_rsa.pubthe contents, or continue to execute code in the Git Bash in the same secret key can be copied to the clipboard.

clip < ~/.ssh/id_rsa.pub

3.1.2 Adding key settings on GitHub

GitHub landing system. Click on the top right corner of the Account Settings ---> SSH Public keys ---> add another public keys

3.1.3 Paste keys and save

Copy the generated key to your local inside (key text box), click on add key

3.1.4 Testing

ssh -T [email protected]

When prompted shown below, demonstrate successful configuration keys!

Backup uploads blog source files for the computer after 3.2

Performing step 2.2备份上传, because of I was new for the computer, pull down from the warehouse to warehouse but could not push up.


The reason is not to Git files or folders to affirm, or to Git not familiar with the cause, in fact, quite a sense, summarize these three tricks step is first git initinitialized environment and then select the range of files to be executed, git add .meaning that all options, then affirm that the final choice of push and pull. DETAILED DESCRIPTION See below.

push success is like this:,

3.3Travis IC Introduction

Travis IC = Travis Continuous Integration means that, in a project, any person for any changes to the code base will trigger CI server automatically build the project, the automatic test run, automatic compilation, and even automatically deployed to the test environment. The advantage of this is that identify problems at any time, at any time repair. Because the cost of fixing the problem grows over time, the earlier found that the lower repair costs. CI Travis CI is a hosted online service, to carry out continuous integration with Travis, you do not need to take the server itself. In addition, GitHub official launch of the project is compiled automatically - GitHub Actions , please refer to the following understanding of these two articles:

GitHub Actions Started - Ruan Yifeng

Github Actions: software development changed again - to compile youth

4. Reference article

Github using Travis CI achieve Hexo blog automatic deployment --Michael Xiang

Travis CI achieve Hexo blog using automated deployment - old Yuhi (local section of this article there is an error, to self-identify).

CI using the automatic deployment hexo blog - step

Use Travis CI automatically deploy blog to github pages and coding pages - Akkuman

Well, here we exchange this article is over. Rookie learning article, inadequacies also hope you Great God treatise.

Guess you like

Origin www.cnblogs.com/g00gle/p/11701295.html