Pain points

On Github, I set up my own blog with Hexo. I used two warehouses, one for Hexo source code, so that I could seamlessly blog after changing devices, and the other warehouse for displaying the blog website, which contained the source code of published articles.

The question is, after I write a blog, I have to synchronize the hexo code to the GitHub repository and post the latest posts to the blog page. It takes a lot of time and I have to work two jobs. Of course, use the official Github Actions.

When we push the Hexo code to the remote repository, we trigger the GitHub Actions Workflow, which then creates a runtime environment, takes the Hexo source code, builds and deploits it, and finally publishes it to the blog repository. That means we just push the hexo code and github Actions does the rest automatically.

The following is the specific configuration:

configuration

Generate the deploy keys

The blog repository ends with.gihub.io and the hexo repository ends with the hexo code. It is important to distinguish between the two repositories.

To generate the key, type the following command

ssh-keygen -f github-deploy-key
Copy the code

Github deploy-key and github deploy-key.pub are two files in the current directory. You can also use Github to configure the SSH key, but you can create the two files separately to distinguish between them.

Configure the blog repository deploy Keys

Open the blog repository, ending with.gihub. IO, open Settings, and follow the steps shown below

Copy all keys stored in github deploy-key.pub to the key. The title can be customized. The deploy keys above are previously configured by me, so leave them alone.

Configure Hexo warehouse Secrets

Open Hexo repository Settings and find Secrets as shown in the following figure

Copy all the contents of github deploy-key into Value. Name is my own Name, and the above two are also configured by me. Don’t panic.

Write dead simple Actions

Creating a Configuration File

Click on Actions to create workflows

You can choose a NodeJS template, or you can skip it and just copy the template I’ve given below

According to the following configuration template, paste into the created YML file selectively, or paste all, try the effect, and then change

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - name: Checkout source
        uses: actions/checkout@v1
        with:
            ref: main

      - name: Setup Node.js
        uses: actions/setup-node@v1
        with:
              node-version: '12'


      - name: Setup Hexo
        env[HEXO_DEPLOY_PRI_XIAOXIN_WINDOW] # HEXO_DEPLOY_PRI_XIAOXIN_WINDOWACTION_DEPLOY_KEY: ${{ secrets.HEXO_DEPLOY_PRI_XIAOXIN_WINDOW }}
        run: |
                    mkdir -p ~/.ssh/
                    echo "$ACTION_DEPLOY_KEY"> ~/.ssh/id_rsa
                    chmod 700 ~/.ssh
                    chmod 600 ~/.ssh/id_rsa
                    ssh-keyscan github.com >> ~/.ssh/known_hosts
                    git config --globalGit config --globalUser. name Your GitHub name NPM install hexo-cli -g NPM install-name: Deployrun: |
            hexo clean
            hexo deploy

Copy the code

Briefly, this Workflow is triggered when we push content to the remote Main branch.

Use the latest Ubuntu as the hexo deploy system.

First checkout the source code, then set up to use the latest Node.js V12 LTS as the Node interpreter.

HEXO_DEPLOY_PRI_XIAOXIN_WINDOW. This name must correspond to the configuration of Hexo warehouse secrets

Git config name and email address should be used by everyone.

Finally, it’s time to install the Hexo CLI, dependency modules, and deployment.

Verify the effect of

Here are the results of the successful run, and the successful ones are checked

If it fails, you can open it to see where the error is reported, and then carefully check where the configuration is wrong, and then modify it. Success, the blog repository update has a little time delay, just wait a few minutes.

Finally, I posted my own blog site:xiaoborao.github.io/