How to sync GitHub Actions across repositories

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 😊

--

--

--

https://adrianjost.dev

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Managing the software development team

Creating an OpenWhisk Alexa skill

Frontend Mentor July 2021 review

All about METAVERSE.

How to make an offline copy of a website

The Ultimate Google Analytics Audit Template Sheet — Review 9/12

CS371p Spring 2020: Yuki Kameyama

6 Ways You Can Get Keys From a Python Dictionary

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Jost

Adrian Jost

https://adrianjost.dev

More from Medium

Lighthouse CI — Web incremental change with confidence

Installing APEX+ORDS on On-Prem Oracle Database

Are Sitecore Containers optimized for disk space?

How to make a project into gitlab and upload your existing code into gitlab