日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Github pages 同步到Gitee pages 并自動更新Gitee pages

作者:從零開始的數據猿 更新時間: 2022-05-13 編程語言

由于 Gitee Pages 的訪問速度很快,很多朋友會選擇 Gitee Pages 部署項目(如:個人博客、開源項目國內鏡像站點)。但是它不像 GitHub Pages 那樣,一提交代碼就能自動更新 Pages,因為 Gitee 的自動部署屬于 Gitee Pages Pro 的服務。

有大佬開發了自動更新Gitee pages的action,其中也包含了github 同步到gitee 的代碼,詳見:https://github.com/yanglbme/gitee-pages-action

但有時候我想在同步之前對代碼做些處理,比如替換github.io的鏈接,但是保持此github倉庫不變,就需要自己寫同步代碼了,我寫好的代碼如下:
注意:需要在倉庫的settings(不是賬號的settings) => secrets/action ,添加New repository secret ,名字是GITEE_TOKEN, 值就是gitee token

name: Github 同步到 Gitee
# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ master ]
  #pull_request:
   # branches: [ main ]
  #schedule:
    #- cron: '30 0/3 * * *'
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  run:
    name: 把該倉庫同步到 Gitee(使用白名單只同步這個倉庫)
    runs-on: ubuntu-latest
    steps:

    # - name: Mirror Github to Gitee with white list
    #   uses: Yikun/hub-mirror-action@master
    #   with:
    #     src: github/nmy
    #     dst: gitee/nmy
    #     dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    #     dst_token:  ${{ secrets.GITEE_TOKEN }}
    #     mappings: "nmy.github.io=>nmy"
    #     static_list: "nmy.github.io"
    #     force_update: true
    #     debug: true
    - name: Mirror Github to Gitee with white list
      env:
        GITEE_TOKEN: ${{ secrets.GITEE_TOKEN }}
      run: |
        git config --global user.email xxxxxx@qq.com
        git config --global user.name nmy
        git clone https://github.com/nmy/nmy.github.io.git
        ls -al
        mv nmy.github.io nmy && cd nmy
        pwd
        find . -type f | xargs sed -i "s/nmy.github.io/nmy.gitee.io/g"   
        git add .
        git commit -m "update" -a
        git push --force --quiet https://nmy:"$GITEE_TOKEN"@gitee.com/nmy/nmy.git  master:master

原文鏈接:https://nmydt.blog.csdn.net/article/details/124523405

欄目分類
最近更新