我的博客应用GitHub上的pages性能公布的基于Hugo生成的动态网站,根本无奈失常拜访,所以想要同步一份到gitee上公布,当初应用GitHub Actions提供的计算机资源就能够间接在GitHub上进行动态网站的生成,公布,近程刷新gitee pages,触发条件能够是push或者定时等等,堪称非常好用,之后看到能够间接同步到gitee仓库,就实现一下试试,以下就是实现步骤,以及踩坑,当然强烈建议看开源代码的官网阐明文档。

生成公钥和私钥并填入仓库

输出ssh-keygen -t rsa -C "user@email.com",而后回车几次,会生成 id_rsa.pub 文件和 id_rsa 文件,别离寄存公钥和私钥:

Gitee仓库填入公钥

将公钥 id_rsa.pub 中的数据填入到gitee待备份仓库界面下 settings→Deploy keys→add personal public key

这里留神:要选右上增加personal public key才有写入权限

GitHub仓库填入私钥

Settings→Secret→New repository secre 用于之后的程序环境配置拜访,命名为GITEE_RSA_PRIVATE_KEY

生成GitHub账号的 personal access token

将仓库权限选上就行了,而后将生成的token,配到私钥配置的中央 仓库→Settings→Secret→New repository secre,命名为ACCESS_TOKEN

在仓库secret处增加GITEE_PASSWORD,放入gitee账号密码用于刷新gitee pages

同之前步骤雷同,之后用于环境变量的配置,就是以下3条secret,OSS的是主动部署到阿里OSS的脚本应用的,我是放在一个脚本里运行,须要理解能够看我另一篇文章。

在GitHub仓库创立并编写Actions脚本!!!

文件名随便从这点开就行,上面有模板,点开后批改也行,创立的文件默认放在.github/workflows/

也能够用命令创立mkdir -p .github/workflows && touch .github/workflows/name.yml

将代码拷入,批改具体变量,比方仓库名等,如果不须要deploy间接去掉就行了,不影响:

name: deploy blog to gitee on:  push:    branches:      - main    # master 分支 push 的时候触发      jobs:  deploy: #执行部署Hugo生成动态代码,默认放在gh-pages分支    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 #不须要extended版本就能够正文      - name: Build        run: hugo --minify      - name: Deploypage        uses: peaceiris/actions-gh-pages@v3        with:          personal_token: ${{ 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: ${{ secrets.ACCESS_TOKEN }}          publish_dir: ./public                    sync: #同步到gitee仓库    needs: deploy    runs-on: ubuntu-latest    steps:    - name: Sync to Gitee      uses: wearerequired/git-mirror-action@master      env:        SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}      with:        # 起源仓库        source-repo: "git@github.com:JohntunLiu/myblog.git"        # 指标仓库        destination-repo: "git@gitee.com:JohntunLiu/JohntunLiu.git"          reload-pages:    needs: sync    runs-on: ubuntu-latest    steps:      - name: Build Gitee Pages        uses: yanglbme/gitee-pages-action@main        with:          # 留神替换为你的 Gitee 用户名          gitee-username: JohntunLiu          # 留神在 Settings->Secrets 配置 GITEE_PASSWORD          gitee-password: ${{ secrets.GITEE_PASSWORD }}          # 留神替换为你的 Gitee 仓库,仓库名严格辨别大小写,请精确填写,否则会出错          gitee-repo: JohntunLiu/JohntunLiu          # 要部署的分支,默认是 master,若是其余分支,则须要指定(指定的分支必须存在)          branch: gh-pages

点击commit changes 提交运行,之后就看失去运行流程了

实际效果和流程

如果是部署其余动态网站,批改deploy的代码块就行了,我顺便把部署到GitHub pages放在了外面:name: Deploypage

如果是hugo的话开源人员还提供了缓存机制,能够进步部署速度,能够去开源局部看,具体怎么看就是复制- uses: peaceiris/actions-hugo@v2 前面的局部搜寻到GitHub中看,比方:https://github.com/peaceiris/actions-hugo,readme.md文档写得相当详实,也会更新阐明

更多精彩能够关注我的博客或微信公众号LiuJohntun,记录并分享我的所见、所学、所想...