This article first appeared on my blogAutomate publishing Hexo websites to GitHub Pages with GitHub ActionsWelcome to my station for support

Honestly, it’s nice not to have to execute a long list of deployment instructions every time!

Prepare the Hexo website

  1. To set up a Hexo site locally, refer to the official Quick start documentation.
  2. Create two GitHub repositories calledblog(private) andYour GitHub username. GitHub. IO(shared). The former is used to store blog source files and the latter is used to mount GitHub Pages.
  3. Push local blog source files toblogThe warehouse.

Prepare the secret key

To facilitate logging in to GitHub accounts while running GitHub Actions, we used SSH to log in.

Use ssh-keygen to generate a set of public and private key pairs

ssh-keygen -t rsa -b 4096 -f ~/.ssh/github-actions-deploy
Copy the code

Go to Settings->SSH and GPG keys and add the public key you just generated. Add the newly generated private key named ACTION_DEPLOY_KEY in Settings->Secrets of the blog repository.

Configure _config.yml for Hexo

Add deployment configuration.

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
- type: git
  repo: [email protected]:bulabula.git Use the SSH address of the repository
  branch: master
Copy the code

Configuration making Actions

Click New Workflow under the Actions TAB of the Blog repository and write the following configuration.

name: Deploy Blog

on: [push] Run when there is a new push

jobs:
  build: # A task called Build

    runs-on: ubuntu-latest # Run on the latest version of Ubuntu
    
    steps:
    - name: Checkout Download the contents of the master branch from the repository to the working directory
      uses: actions/checkout@v1 # scripts from https://github.com/actions/checkout
      
    - name: Use Node.js 10.x Configure the Node environment
      uses: actions/setup-node@v1 # configuration scripts from https://github.com/actions/setup-node
      with:
        node-version: "10.x"
    
    - name: Setup Hexo env
      env:
        ACTION_DEPLOY_KEY: The ${{ secrets.ACTION_DEPLOY_KEY }}
      run: | # set up private key for the deploy mkdir -p ~ /. SSH/echo "$ACTION_DEPLOY_KEY" | tr -d '\ r > ~ /. SSH/id_rsa secret-key chmod # configuration 600 ~/.ssh/id_rsa ssh-keyscan github.com >> ~/.ssh/known_hosts # set git infomation git config --global user.name Git config --global user.email '[email protected]' # install dependencies NPM Install hexo NPM I    - name: Deploy
      run: # # | publish hexo generate && hexo deploy deployed applicationCopy the code

This article first appeared on my blogAutomate publishing Hexo websites to GitHub Pages with GitHub ActionsWelcome to my station for support