rules-template icon indicating copy to clipboard operation
rules-template copied to clipboard

Switch template to Copier

Open ypid opened this issue 1 year ago • 1 comments

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/

ypid avatar May 19 '24 13:05 ypid

Yeah this sounds great to me!

alexeagle avatar Jan 23 '25 20:01 alexeagle

We'd welcome this -- looking at Copier for other applications as well.

arrdem avatar May 30 '25 18:05 arrdem

@cbachhuber There is already an issue for this. Let's use this for further discussion.

hofbi avatar Dec 02 '25 16:12 hofbi

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:

  1. feature branch or separate repo with an eventual big bang integration
  2. 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.

cbachhuber avatar Dec 06 '25 06:12 cbachhuber

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?

hofbi avatar Dec 08 '25 11:12 hofbi

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

cbachhuber avatar Dec 09 '25 20:12 cbachhuber

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

hofbi avatar Dec 10 '25 18:12 hofbi

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.)

cbachhuber avatar Dec 13 '25 20:12 cbachhuber

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.

hofbi avatar Dec 14 '25 08:12 hofbi