My blog uses the Pages function on GitHub to publish the static website generated by Hugo, but it cannot be accessed normally. Therefore, I want to synchronize a copy to publish on Gitee. Now I can directly generate and publish the static website on GitHub by using the computer resources provided by GitHub Actions. Remote refresh gitee pages, trigger conditions can be push or timing and so on, it is very easy to use, after seeing can be directly synchronized to the Gitee warehouse, implementation try, the following is the implementation steps, and step on the pit, of course, strongly recommend to read the official documentation of the open source code.

Generate public and private keys and populate the repository

Enter ssh-keygen -t rsa -c “[email protected]” and press Enter several times. The id_rsa.pub and id_rsa files are generated, which store the public and private keys respectively.

The Gitee repository fills in the public key

Add data in id_Rsa. pub to Settings →Deploy Keys → Add Personal public key on the gitee repository to be backed up page

** Add personal public key to write permission

The GitHub repository fills in the private key

Settings→Secret→New Repository secre is used for subsequent application environment configuration access named GITEE_RSA_PRIVATE_KEY

Generate a Personal Access token for a GitHub account

Keystore →Settings→Secret→New Repository secre: ACCESS_TOKEN

Add GITEE_PASSWORD in secret and add the gitee account password to refresh Gitee pages

Same as the previous steps, after the configuration of environment variables, is the following 3 secret, OSS is automatically deployed to ali OSS script used, I am in a script to run, you can see my other article.

Create and write Actions scripts in GitHub repository!!

By default, the created file will be stored under. Github /workflows/

You can also use command to create the mkdir -p. Making/workflows && touch. Making/workflows/name. Yml

Copy the code in and change the specific variable, such as the name of the repository, if you do not need to deploy directly removed, does not affect:

name: deploy blog to gitee
 
on:
  push:
    branches:
      - main    Trigger when the master branch is pushed
      
jobs:
  deploy: # Static code generated by deploying Hugo is placed in the GH-Pages branch by default
    runs-on: Ubuntu 18.04
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: recursive  # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.81.0'
          extended: true You don't need an extended version to annotate

      - name: Build
        run: hugo --minify

      - name: Deploypage
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: The ${{ secrets.ACCESS_TOKEN }}
          external_repository: JohntunLiu/JohntunLiu.github.io
          publish_branch: gh-pages  # default: gh-pages
          publish_dir: ./public
          
      - name: Deploygitee
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: The ${{ secrets.ACCESS_TOKEN }}
          publish_dir: ./public
                
  
  sync: Sync to gitee repository
    needs: deploy
    runs-on: ubuntu-latest
    steps:
    - name: Sync to Gitee
      uses: wearerequired/git-mirror-action@master
      env:
        SSH_PRIVATE_KEY: The ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
      with:
        # Source warehouse
        source-repo: "[email protected]:JohntunLiu/myblog.git"
        # Target warehouse
        destination-repo: "[email protected]:JohntunLiu/JohntunLiu.git"
        
  reload-pages:
    needs: sync
    runs-on: ubuntu-latest
    steps:
      - name: Build Gitee Pages
        uses: yanglbme/gitee-pages-action@main
        with:
          Replace this with your Gitee username
          gitee-username: JohntunLiu
          # Notice in Settings->Secrets configure GITEE_PASSWORD
          gitee-password: The ${{ secrets.GITEE_PASSWORD }}
          The name of your Gitee warehouse is strictly case sensitive, please fill in accurately, otherwise it will be wrong
          gitee-repo: JohntunLiu/JohntunLiu
          The default branch to deploy is master, and the specified branch must exist.
          branch: gh-pages
Copy the code

Click Commit Changes to commit the run, and then you can see the process

Practical effects and processes

For other static sites, just change the deploy block, which I also included in GitHub Pages: name: Deploypage

We also provide a caching mechanism to improve the deployment speed. You can go to the open source section to see how to copy – uses: Peaceiris/actions – Hugo @ v2 the latter part of the search to making, such as: https://github.com/peaceiris/actions-hugo, readme. Md document writes quite detailed, information will be update

More wonderful can follow my blog or wechat public account LiuJohntun, record and share what I see, learn, think…