What is the most efficient way of sharing github workflows across several repositories?

Viewed 1617

I am currently setting up a workflow with Github actions for my team. However I have more than a dozen repositories for our different microservices and I do not want to simply clumsily copy the .github/workflows/ directory between each one. If we need to change our workflow I would have to copy all the changes between each repository.

The solution I am currently considering is simply having my workflows directory as a git submodule. (Edit : Tested this and when your workflows directory is a submodule github does not recognize it as containing actions)

Is there an alternative to this solution? Are there any current "best practices" for managing these workflows?

1 Answers

GitHub recently added workflow templates for organizations, see 'Sharing workflow templates within your organization'

As for alternatives - you could either write your own actions or shell scripts which will take care of as much tasks as possible. While you still need to take care of workflows themselves, in extreme cases they can be chopped down to a checkout and do-everything-i-want steps. Shell scripts have an extra advantage that they can work on other CI as long chosen shell is supported.

And finally, you could create master repo holding all workflows and bot account which will automagically push all changes in workflows to other repositories, but that's basically automating what you already doing.

I've seen (almost) all mentioned solutions used in wild, with some shifting here and there. Repositories which used/plans to use other CI pick shell scripts. Organizations focused on just one ecosystem pick actions (either their own, or created by community). Some people on support forum picked autopush as that was closest to having templates at the time. Can't say much about usage of workflow templates - feature went public only few weeks ago [at the moment of writing] so that's not really a suprise.

Related