6
头图

Gitee Pages

In the previous article "A Teach You Code Synchronization GitHub and Gitee" , we used GitHub Actions to solve the problem of GitHub code automatic synchronization Gitee, but after our blog warehouse code is synchronized to Gitee, it cannot be automatically deployed like GitHub. Pages, if you don't use the paid Gitee Pages Pro service, how can we implement Gitee to automatically deploy Pages?

GitHub Actions

The answer is to continue using GitHub Actions! You might be thinking, does Gitee also have a GitHub Actions service? Gitee will also detect .github/workflows/ directory like GitHub, and then execute it?

This is of course impossible. Gitee does not support GitHub's approach, but why do we have to borrow the capabilities of Gitee? In GitHub Actions, we simulate logging in to Gitee and clicking the deployment button of the project. Isn’t that also a way to achieve it?

Search for Actions

Let's find some suitable GitHub Actions. We can go to official market on GitHub, or awesome actions warehouse, or directly search for keywords gitee pages actions

In the end, we decided to use Gitee Pages Action . Check out the sample code on the homepage:

name: Sync

on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Sync to Gitee
        uses: wearerequired/git-mirror-action@master
        env:
          # 注意在 Settings->Secrets 配置 GITEE_RSA_PRIVATE_KEY
          SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
        with:
          # 注意替换为你的 GitHub 源仓库地址
          source-repo: git@github.com:doocs/leetcode.git
          # 注意替换为你的 Gitee 目标仓库地址
          destination-repo: git@gitee.com:Doocs/leetcode.git

      - name: Build Gitee Pages
        uses: yanglbme/gitee-pages-action@main
        with:
          # 注意替换为你的 Gitee 用户名
          gitee-username: yanglbme
          # 注意在 Settings->Secrets 配置 GITEE_PASSWORD
          gitee-password: ${{ secrets.GITEE_PASSWORD }}
          # 注意替换为你的 Gitee 仓库,仓库名严格区分大小写,请准确填写,否则会出错
          gitee-repo: doocs/leetcode
          # 要部署的分支,默认是 master,若是其他分支,则需要指定(指定的分支必须存在)
          branch: main

We have previously implemented GitHub code synchronization Gitee, here we directly use the second half of the automatic deployment actions, combined with the YAML file code in the previous article, the final modification is as follows:

name: syncToGitee
on:
  push:
    branches:
      - gh-pages
jobs:
  repo-sync:
    runs-on: ubuntu-latest
    steps:
      - name: Mirror the Github organization repos to Gitee.
        uses: Yikun/hub-mirror-action@master
        with:
          src: 'github/mqyqingfeng'
          dst: 'gitee/mqyqingfeng'
          dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
          dst_token:  ${{ secrets.GITEE_TOKEN }}
          static_list: "learn-typescript"
          force_update: true
          debug: true
          
      - name: Build Gitee Pages
        uses: yanglbme/gitee-pages-action@main
        with:
          # 注意替换为你的 Gitee 用户名
          gitee-username: mqyqingfeng
          # 注意在 Settings->Secrets 配置 GITEE_PASSWORD
          gitee-password: ${{ secrets.GITEE_PASSWORD }}
          # 注意替换为你的 Gitee 仓库,仓库名严格区分大小写,请准确填写,否则会出错
          gitee-repo: mqyqingfeng/learn-typescript
          # 要部署的分支,默认是 master,若是其他分支,则需要指定(指定的分支必须存在)
          branch: gh-pages

Be careful not to forget to add Secrets in the warehouse settings, enter the login password of Gitee, and save the name as GITEE_PASSWORD

YAML file syntax error

If Actions fails to run with this kind of error:

This is because there is a problem with your YAML grammar, which may be misaligned. You can the website , or you can take a look at the YAML language tutorial .

Run again

After modifying the code, we can execute sh deploy.sh again, and then check the operation on GitHub:

When the operation is successful, we check the address of Gitee again, and we will find that it has been deployed as the latest version.

So far, the synchronization and automatic deployment of GitHub and Gitee code have been realized.

Series of articles

Series article directory address: https://github.com/mqyqingfeng/Blog

WeChat: "mqyqingfeng", add me to the only reader group in Kongyu.

If there are mistakes or not rigorous, please correct me, thank you very much. If you like or have some inspiration, star is welcome, which is also an encouragement to the author.


冴羽
9.3k 声望6.3k 粉丝