How to sync GitHub Actions across repositories

Adrian Jost
2 min readMay 13, 2020
Screenshot of “Files Sync Action” Marketplace Entry

Let’s start with the why…

I am a lazy person… A really lazy person and I hate doing monotonus tasks. That’s why I love beeing a developer and can automate all those tasks. One of these boring tasks is copying files.

To keep my GitHub repositories organized, I have a couple of GitHub Actions that I want to have in almost all my repos. Some of these read all the ToDos from the source code and create & connect Github Issues, another auto assigns the author of a PR to the PR and so on. But managing those workflows across multiple repositories is tidious. That’s why I developed the GitHub Action “Files Sync Action” which you can find in the Marketplace. It was heavily inspired by the great “Secrets Sync Action” which I can highly recommend to set common secrets for multiple repositories.

I knew there are other solutions out there, like the “Copycat Action” but those haven’t worked well for me with multiple repositories and they can not delete files. So if I would ever rename or remove a synced file, I would had to remove it manually from all the synced repositories. This brings us back to the beginning of this article: I am a lazy person…

So let’s sync files!

Syncing files with the “Files Sync Action” should be pretty simple. At first, we should create a source repository where all the files to sync will be located.
Then we can create a simple action at .github/workflows/sync.yml.

In the following example, this new workflow is triggered every night at 3AM and whenever you push something on the master branch.
The files we want to sync can be selected using regular expressions with the FILES_PATTERNS input and you can define all the target repos as a simple list below the input TARGET_REPOS.
Lastly you need to set a GITHUB_TOKEN which has write access to all the synced repositories. You can create a GITHUB_TOKEN on your personal profile page and then you can add it as a secret to your sync source repository: https://github.com/[your/sync-repo]/settings/secrets

Of course, this is just a super simple example. If needed you can set another repository than the workflows repository as a sync source, you can skip steps, customize the commit author and some more things. You can find all the options in the Marketplace README entry.
And if there is something that you want to customize that is not supported yet, please let me know by opening an issue at the Actions Repository.

Happy Syncing 😊

--

--