actions-template-sync

actions-template-sync

高效自动化工具实现多Git仓库同步

actions-template-sync是一款强大的GitHub Action工具,可自动同步来自GitHub、GitLab等不同Git提供商的仓库。支持公私有仓库同步、文件忽略、多种配置选项和生命周期钩子。通过创建包含最新变更的pull request,保持目标仓库与源仓库同步,简化模板仓库更新、仓库迁移和镜像过程。

GitHub Actions模板同步代码仓库自动化版本控制Github开源项目

actions-template-sync

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

All Contributors

<!-- ALL-CONTRIBUTORS-BADGE:END -->

actions-template-sync

Lint

shellcheck

test

test-hooks

test-ssh

test-ssh-gitlab

push-docker

gh-pages-mk-docs

abstract

Synchronise git repositories in an automated manner. Different git providers like GitHub (enterprise), GitLab,.. are supported as the source provider. This can help you e.g. for migration from another git provider to GitHub or if you want to mirror git repositories.

History

It is possible to create repositories within Github with GitHub templates. This is a nice approach to have some boilerplate within your repository. Over time, the template repository will get some code changes. The problem is that the already created repositories won't know about those changes. This GitHub action will help you to keep track of the template changes. The initial author of this repository faced that issue several times and decided to write a GitHub action to face that issue. Because of the nice community, several feature requests helped to go on with the development of the action. Now several other features are supported.

Features

This action is creating a pull request with the latest changes within the target repo whenever it runs with following exceptions

  • there is already an open PR created with the latest changes of the source repository.
    • if there are new changes and a PR is already open, a new PR will be created (option to clean up older PRs)
  • related new changes are ignored within the .templatesyncignore file
  • the source repository is fully included within the target repository
flowchart LR github_source("fa:fa-github <b>GitHub</b> source repository <b>[private|public]</b>") gitlab_source("fa:fa-gitlab <b>GitLab</b> source repository <b>[private|public]</b>") any_source("fa:fa-git <b>Any</b> git provider <b>[private|public]</b>") github_target{{"fa:fa-github <b>GitHub</b> target repository <b>[private|public]</b>"}} github_source --> |"<b>ssh | PAT | github app</b>"| github_target gitlab_source --> |"<b>ssh</b>"| github_target any_source --> |"<b>ssh</b>"| github_target
  • Sync other public or private repository (e.g. template repositories) with the current repository
  • Ignore files and folders from syncing using a .templatesyncignore file
  • many configuration options
  • different lifecycle hooks are supported. This opens the possibility to inject custom code into the workflow with a yaml definition file.
  • different git provider like GitLab, Gittea,.. as source are supported (with ssh). See .github/workflows/test_ssh_gitlab.yml for an example.
  • It is not necessarily needed that source and target repository have the same base history. Because of that reason, it is possible to merge 2 totally different repositories with the help of the action.

Usage

Usage changes depending on whether the template repository is public or private, regardless of the visibility of the current repository.

Public template repository

Add this configuration to a GitHub action in the current repository:

# File: .github/workflows/template-sync.yml on: # cronjob trigger schedule: - cron: "0 0 1 * *" # manual trigger workflow_dispatch: jobs: repo-sync: runs-on: ubuntu-latest # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs permissions: contents: write pull-requests: write steps: # To use this repository's private action, you must check out the repository - name: Checkout uses: actions/checkout@v4 # https://github.com/actions/checkout#usage # uncomment if you use submodules within the repository # with: # submodules: true - name: actions-template-sync uses: AndreasAugustin/actions-template-sync@v2 with: source_repo_path: <owner/repo> upstream_branch: <target_branch> # defaults to main pr_labels: <label1>,<label2>[,...] # defaults to template_sync

You will receive a pull request within your repository if there are some changes available in the template.

Private template repository

If your current repository was created from a private template, there are several possibilities.

1. Using a GitHub app

You can create and use a [GitHub App][github-app] to handle access to the private template repository. To generate a token for your app you can use a separate action like [tibdex/github-app-token][github-app-token]. You have to set up the checkout step with the generated token as well.

jobs: repo-sync: runs-on: ubuntu-latest steps: - name: Generate token to read from source repo # see: https://github.com/tibdex/github-app-token id: generate_token # https://github.com/tibdex/github-app-token uses: tibdex/github-app-token@v2 with: app_id: ${{ secrets.APP_ID }} private_key: ${{ secrets.PRIVATE_KEY }} - name: Checkout # https://github.com/actions/checkout#usage uses: actions/checkout@v4 with: # submodules: true token: ${{ steps.generate_token.outputs.token }} - name: actions-template-sync uses: AndreasAugustin/actions-template-sync@v2 with: github_token: ${{ steps.generate_token.outputs.token }} source_repo_path: <owner/repo> upstream_branch: <target_branch> # defaults to main pr_labels: <label1>,<label2>[,...] # defaults to template_sync

2. Using SSH

You have various options to use ssh keys with GitHub. An example is [deployment keys][deployment-keys]. For our use case, write permissions are not needed. Within the current repository, where the GitHub action is enabled, add a secret (e.q. SOURCE_REPO_SSH_PRIVATE_KEY) with the content of your private SSH key. Make sure that the read permissions of that secret fulfill your use case. Set the optional source_repo_ssh_private_key input parameter. It is also possible to use a different git provider, e.g. GitLab.

jobs: repo-sync: runs-on: ubuntu-latest # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs permissions: contents: write pull-requests: write steps: # To use this repository's private action, you must check out the repository - name: Checkout # https://github.com/actions/checkout#usage uses: actions/checkout@v4 with: # submodules: true token: ${{ secrets.GITHUB_TOKEN }} - name: actions-template-sync uses: AndreasAugustin/actions-template-sync@v2 with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: ${{ secrets.SOURCE_REPO_PATH }} # <owner/repo>, should be within secrets upstream_branch: ${{ secrets.TARGET_BRANCH }} #<target_branch> # defaults to main pr_labels: <label1>,<label2>[,...] # defaults to template_sync source_repo_ssh_private_key: ${{ secrets.SOURCE_REPO_SSH_PRIVATE_KEY }} # contains the private ssh key of the private repository

3. Using a PAT

:warning: when the source repository is private using PATs, also the target repository must be private. Else it won't work.

[Personal access token][github-pat] is an alternative to using passwords for authentication to GitHub. You can add a kind of password to your GitHub account. You need to set the scopes.

  • repo -> all
  • read:org

pat-scopes

Furthermore, you need to set the access within the source repository to allow GitHub actions within the target repository. As mentioned before (you can see the note in the image) you need to set the target repository to private. settings -> actions -> general.

pat-source-repo-access

example workflow definition

name: actions-template-sync on: # cronjob trigger At 00:00 on day-of-month 1. https://crontab.guru/every-month schedule: - cron: "0 0 1 * *" # manual trigger workflow_dispatch: jobs: test-implementation-job: runs-on: ubuntu-latest steps: # To use this repository's private action, you must check out the repository - name: Checkout uses: actions/checkout@v4 with: # submodules: true token: ${{ secrets.CUSTOM_GITHUB_PAT }} - name: Test action step PAT uses: AndreasAugustin/actions-template-sync@v2 with: github_token: ${{ secrets.CUSTOM_GITHUB_PAT }} source_repo_path: ${{ secrets.SOURCE_REPO_PATH }} # <owner/repo>, should be within secrets

Action Inputs

VariableDescriptionRequiredDefault
github_tokenToken for the repo. Can be passed in using ${{ secrets.GITHUB_TOKEN }}true${{ github.token }}
source_repo_pathRepository path of the templatetrue
upstream_branchThe target branchfalseThe remote's default (usually main)
source_repo_ssh_private_key[optional] private ssh key for the source repository. seefalse
pr_branch_name_prefix[optional] the prefix of branches created by this actionfalsechore/template_sync
pr_title[optional] the title of PRs opened by this action. Must be already created.falseupstream merge template repository
pr_body[optional] the body of PRs opened by this action.falseMerge ${SOURCE_REPO} ${TEMPLATE_GIT_HASH}
pr_labels[optional] comma separated list. [pull request labels][pr-labels].falsesync_template
pr_reviewers[optional] comma separated list of pull request reviewers.false
pr_commit_msg[optional] commit message in the created pull requestfalsechore(template): merge template changes :up:
hostname[optional] the hostname of the repositoryfalsegithub.com
is_git_lfs[optional] set to true if you want to enalbe git lfsfalsefalse
is_dry_run[optional] set to true if you do not want to push the changes and not want to create a PRfalse
is_allow_hooks[optional] set to true if you want to enable lifecycle hooks. Use this with caution!falsefalse
hooks[optional] please check the lifecycle hooks section belowfalse
is_force_push_pr[optional] set to true if you want to force push and pr update. Needs further permissions (see below)falsefalse
is_pr_cleanup[optional] set to true if you want to cleanup older PRs targeting the same branch. Use this with caution!falsefalse
is_keep_branch_on_pr_cleanup[optional] set to true if you want to keep the branch when pr is cleanup. Only makes sense together with is_pr_cleanupfalsefalse
is_not_source_github[optional] set to true if the source git provider is not GitHubfalsefalse
is_force_deletion[optional] set to true if you want to force delete files which are deleted within the source repository even if they contain changes. You need to also adjust git_remote_pull_params (see below for details)falsefalse
git_user_name[optional] set the committer git user.namefalse${GITHUB_ACTOR}
git_user_email[optional] set the committer git user.emailfalsegithub-action@actions-template-sync.noreply.${SOURCE_REPO_HOSTNAME}
git_remote_pull_params[optional] set remote pull parametersfalse--allow-unrelated-histories --squash --strategy=recursive -X theirs
gpg_private_key[optional] set if you want to sign commitsfalse
gpg_passphrase[optional] set if your optionial gpg private key has a passphrasefalse
steps[optional] add the steps you want to execute within the actionfalseall steps will be executed

Action Outputs

Properties that are available after the action executed.

outputdescription
pr_branchThe name of the branch used for the pull request
template_git_hashThe template source repository git hash

Remarks Please consider following edge cases

  • pr_branch
    • If PR branch already exists (e.g. after a 2nd run) the action won't update the branch but will still output the branch name
    • If the remote repository already contains the source repository changes the action will exit and the output variable will be undefined
    • If there are no changes the action will exit and the output variable will be undefined

Docker

There are docker images available. Please checkout How to use docker for details.

  • [dockerhub andyaugustin/actions-template-sync][dockerhub-repo]
  • [github andreasaugustin/actions-template-sync][github-repo]

Example

This repo uses this [template][template] and this action from the [marketplace][marketplace]. See the definition [here][self-usage].

If you look for a more detailed guide you can have a look at

  • [Dev.to][devto-example]
  • [GitHub][github-example]
  • :heart: [nice blog post][dotdc-blog]

Trigger

You can use all [triggers][action-triggers] which are supported for GitHub actions

Ignore Files

Create a .templatesyncignore file. Just like writing a .gitignore file, follow the [glob pattern][glob-pattern] in defining the files and folders that should be excluded from syncing with the template repository.

It can also be stored inside .github folder.

Note: It is not possible to sync also the .templatesyncignore itself. Any changes from the template repository will be restored automatically.

Remark reading the [gitglossary][git-glossary] (pathspec section) you see a slight difference to the .gitignore file when you like to disable files you need to use :!. E.g. when you like to disable the sync for all files with exceptions, you need to do smth like

:!newfile-1.txt *

Force Push and PR

If you set the input is_force_push_pr to true you are able to react to e.g. metadata changes within the workflow definition file. Please note that you need to add permissions for repository-projects: read. Compare the needed scope with [gh

编辑推荐精选

Trae

Trae

字节跳动发布的AI编程神器IDE

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

下拉加载更多