赞
踩
由于 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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。