zoukankan      html  css  js  c++  java
  • 搭建GitHub 自动镜像至 Gitee

    GitHub Actions

      首先简单介绍下 GitHub Actions,其官方介绍页面为:https://github.com/features/actions,介绍语如下:

    Automate your workflow from idea to production. GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

    简而言之就是提供了一个高效易用的 CI/CD 工作流,帮助我们自动构建、测试、部署我们的代码。

      另外它支持三大平台—— Linux、MacOS、Windows,支持任何编程语言,而且官方提供了许许多多的 Actions 库供我们直接使用,帮助我们更快地搭建工作流。
    GitHub Actions 的官方文档可以见:https://help.github.com/en/actions/automating-your-workflow-with-github-actions,如果大家想好好研究下的话,一定要好好看看。

    一、准备工作

    1.生成同步用的ssh密钥

    ssh-keygen

    2.添加公钥文件 id_rsa.pub 的内容至 Github、Gitee的个人配置里,点 Github、 Gitee 。目的是为了可以使用git协议免输入密码。

    3.新建Gitee私人令牌Token,点这里。添加后复制这次的Token内容。

    4.Fork 工程 https://github.com/Yikun/hub-mirror-action 。

    5.添加私钥 id_rsa 内容至刚刚 Fork 的 Github 项目 hub-mirror-action。 点击Settings 。

    然后添加 Secrets

     

    二、导入仓库(可以跳过,主要是为了能使用Gitee提供的强制同步功能)

    1.导入你需要镜像的仓库

     

    三、编写workflow (推荐使用ssh模式)

    1.删除fork项目目录下的 .github/workflows 的所有工作流配置。

    2.添加一个镜像配置 gitee-repos-sync.yml 

    ########################################
    #
    #使用参考
    #https://zhuanlan.zhihu.com/p/102977226
    #http://yikun.github.io/2020/01/17/%E5%B7%A7%E7%94%A8Github-Action%E5%90%8C%E6%AD%A5%E4%BB%A3%E7%A0%81%E5%88%B0Gitee/
    #https://github.com/Yikun/hub-mirror-action/blob/master/README_CN.md
    #https://help.github.com/cn/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
    #
    # 建议先在gitee上先导入github的项目,再编辑此文件增加同步功能。这样就能利用好gitee的强制同步功能了。
    ########################################
    name: Gitee repos mirror periodic sync job
    
    on:
      # push推送时触发
      #push:
      # 定时任务触发
      schedule:
        # 每天北京时间9点跑
        # Runs at 01:00 UTC (9:00 AM Beijing) every day
        - cron:  '0 1 * * *'
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        steps:
        - name: Cache phpdragon src repos
          # 引用发行版的主要版本
          uses: actions/cache@v1
          with:
            path: /home/runner/work/phpdragon/phpdragon-cache
            key: ${{ runner.os }}-phpdragon-repos-cache
    
        - name: Mirror the Github organization repos to Gitee.
          # 引用master分支的脚本支持
          uses: phpdragon/hub-mirror-action@master
          with:
            #  需要被同步的源端账户名,如github/phpdragon,表示Github的phpdragon账户。
            src: github/phpdragon
            # 需要同步到的目的端账户名,如gitee/phpdragon,表示Gitee的phpdragon账户。
            dst: gitee/phpdragon
            # 用于目的端上传代码的SSH key,用于上传代码
            dst_key: ${{ secrets.GITEE_PRIVATE_SSH_KEY }}
            # 创建仓库的API tokens, 用于自动创建不存在的仓库
            dst_token: ${{ secrets.GITEE_PRIVATE_TOKEN }}
            account_type: user
            # 指定目录cache
            cache_path: /github/workspace/phpdragon-cache
            # 白名单,仅同步白名单中的repos,如“repo1,repo2,repo3”
            white_list: "hub-mirror-action,spark-example"
            # 仅同步静态列表,不会再动态获取需同步列表(黑白名单机制依旧生效)
            static_list: "spark-example"
            # 强制更新
            force_update: true
            # clone方式,使用http、ssh方式进行clone
            clone_style: "ssh"

    3. 提交代码。等待定时任务触发即可。

    4.如果要测试,请开启 push 触发。效果如下:

     

    源码地址:https://github.com/phpdragon/hub-mirror-action

    感谢:

    http://yikun.github.io/ 、https://github.com/Yikun

    参考链接:

    巧用Github Action同步代码到Gitee

    GitHub Action使用杂记

    创建和存储加密密码

    Github Action你值得了解的~

    你知道什么是 GitHub Action 么?

    https://blog.csdn.net/cqcre/article/details/103342314

  • 相关阅读:
    深(爆)搜专题整理
    牛客CSP-S提高组赛前集训营1 T2:乃爱与城市拥挤程度
    [BZOJ3743][Coci2015]Kamp 题解
    CSP2019-S,J初赛游记
    指针复习
    二叉树复习
    最短路复习
    数据库关联查询与模型之间的关联
    数据库操作Flask-SQLAlchemy之模型声明及数据库表的生成与删除
    csrf攻击防范
  • 原文地址:https://www.cnblogs.com/phpdragon/p/12787248.html
Copyright © 2011-2022 走看看