Switch template to Copier
See https://copier.readthedocs.io/en/stable/
This will allow to do the:
- search for "com_myorg_rules_mylang" and replace with the name you'll use for your workspace
- search for "myorg" and replace with GitHub org
- search for "mylang", "Mylang", "MYLANG" and replace with the language/tool your rules are for
- rename directory "mylang" similarly
steps for the user automatically after asking for those details.
Also, when this template involves, users can use Copier to pull in those changes to their instantiated projects. Ref: https://copier.readthedocs.io/en/stable/updating/
Yeah this sounds great to me!
We'd welcome this -- looking at Copier for other applications as well.
@cbachhuber There is already an issue for this. Let's use this for further discussion.
Looking at https://github.com/superlinear-ai/substrate, the copier template with the most stars, copier gives us the possibility to cleanly separate the template repo bazel-contrib/rules-template/ from the template content, as the template content will live in bazel-contrib/rules-template/template/ under copier.
How to transition from the current GitHub Template? I think big bang would be possible, as there are sometimes weeks without any commit in this repo. However, there are many questions to answer, for example which dotfiles, which CI jobs, which Bazel config files, etc. should go where (rules-template/, rules-template/template/, or both), and how to DRY. Also, we want small PRs.
I see these options:
- feature branch or separate repo with an eventual big bang integration
- Have a transition period in which we have a half-ready
template/folder. Accept that this folder will make it into instantiations of this GitHub template. I don't think there's a way of ignoring this folder in GitHub Template instantiation.
Which do you prefer? Am I overlooking a better way? I couldn't find a 'Transitioning from GitHub Templates to copier' section in the copier docs or on the web.
Further, we'd need to agree on how to roll out copier to instantiations of rules-template. I think https://github.com/orgs/copier-org/discussions/1393 is the way to go.
How would the final workflow look like assuming we have the template code in template? And if the template is in there, it the root then an instantiations of the template already?
For creating a new ruleset, a user would click "Use this template" and then run a copier command (maybe as GH action) to automatically update all names and boostrap the template?
With copier, you won't be using GitHub templates at all anymore. See here or here. TL;DR:
Create new ruleset:
uvx copier copy gh:bazel-contrib/rules-template path/to/local/repository
Update ruleset that already follows the copier template:
uvx copier update # --exclude foo/ --exclude bar/
if the template is in there [
template/], it the root then an instantiations of the template already?
Nope, the root of bazel-contrib/rules-template will just be code and configuration that controls development of the template repository itself, i.e., CI and GitHub config, pre-commit, etc. See for example https://github.com/superlinear-ai/substrate
That's not really convenient for a user if they have to run some command to setup their repo instead of just clicking a "Use this template" button.
I think @alexeagle was trying to solve a similar problem with all the repos under https://github.com/bazel-starters, which are all template repos that a created from https://github.com/aspect-build/aspect-workflows-template as their "template template" 😅
The only difference of the https://github.com/bazel-starters templates compared to the rules-template is that we want some automated "search and replace" when instantiating the template. But maybe this can be solved by a github action that is executed after creating the repo via "Use this template". So basically 1) click "Use this template" and 2) click a button to trigger the GHA that will do all the search and replace.
Something like this
graph TD
rules-template-template -->|uvx copier update| rules-template
rules-template-template -->|uvx copier update| rules-A
rules-template-template -->|uvx copier update| rules-B
rules-template -->|Use this teamplate + GHA run| rules-A
rules-template -->|Use this teamplate + GHA run| rules-B
Interesting idea. To check if this is possible, let's get specific. What data do you want to search-replace when instantiating the template? rules-{name}, what else?
I'm not sure we can do much else, since the repo name is probably the only thing you can define when instantiating a GitHub template that a GitHub Action can see.
(One could pass info through the repo description, but that's a hard to use hack.)
Looking at the readme of this repo, replacing the name in all different variations is probably all we need to do for starters.
Creating this GitHub action is even something we can now independently of copier. It would be the automation for the first few search and replace steps in the readme.