|
| 1 | +# Working with an existing app template |
| 2 | + |
| 3 | +This guide covers how to develop and test changes to an app template (e.g., `template-application-rails`, `template-application-flask`) and apply those changes to a project using the Platform CLI. |
| 4 | + |
| 5 | +## How template versioning works |
| 6 | + |
| 7 | +The Platform CLI uses [Copier](https://copier.readthedocs.io/en/stable/) under the hood, which relies on **Git tags** for version resolution. When you run an `install` or `update` command, the CLI clones the template repository and **checks out the latest tagged version** by default — not `main` or any other branch. |
| 8 | + |
| 9 | +This means: |
| 10 | + |
| 11 | +- **Tags are the source of truth.** The CLI will not pick up commits on `main` unless those commits are included in a tagged release. |
| 12 | +- **A new tag must be created** in the template repository for the CLI to recognize and install new changes. |
| 13 | +- Tags should follow [PEP 440](https://peps.python.org/pep-0440/) versioning (e.g., `v0.1.0`, `v0.2.0`). Non-compliant tags are ignored during version resolution. |
| 14 | + |
| 15 | +> [!IMPORTANT] |
| 16 | +> Simply merging changes to `main` in a template repository is **not sufficient** for those changes to be picked up by the CLI. A new version tag must be pushed to the repository. |
| 17 | +
|
| 18 | +### Example: releasing a new template version |
| 19 | + |
| 20 | +After merging your changes to the template's `main` branch: |
| 21 | + |
| 22 | +```sh |
| 23 | +# In the template repository |
| 24 | +git tag v0.3.0 |
| 25 | +git push origin v0.3.0 |
| 26 | +``` |
| 27 | + |
| 28 | +Projects can then pick up this version: |
| 29 | + |
| 30 | +```sh |
| 31 | +nava-platform app update . myapp |
| 32 | +``` |
| 33 | + |
| 34 | +## Developing with a local template |
| 35 | + |
| 36 | +When working on template changes, you don't need to push to a remote or create tags. The CLI supports pointing directly at a **local directory** and a specific **branch or ref**, which is ideal for development and testing. |
| 37 | + |
| 38 | +### Setting up a local checkout |
| 39 | + |
| 40 | +Clone the app template repository (or use an existing clone): |
| 41 | + |
| 42 | +```sh |
| 43 | +git clone https://github.com/navapbc/template-application-rails ~/templates/template-application-rails |
| 44 | +``` |
| 45 | + |
| 46 | +Create a branch for your changes: |
| 47 | + |
| 48 | +```sh |
| 49 | +cd ~/templates/template-application-rails |
| 50 | +git checkout -b my-feature-branch |
| 51 | +``` |
| 52 | + |
| 53 | +Make your template changes and commit them. |
| 54 | + |
| 55 | +> [!NOTE] |
| 56 | +> Template changes must be committed to your local branch. Copier works from Git history, so uncommitted changes will not be applied. |
| 57 | +
|
| 58 | +### Using a Git worktree (alternative) |
| 59 | + |
| 60 | +If you'd rather keep your default branch intact, you can use a [Git worktree](https://git-scm.com/docs/git-worktree) instead of a new clone: |
| 61 | + |
| 62 | +```sh |
| 63 | +cd ~/templates/template-application-rails |
| 64 | +git worktree add ../template-application-rails-feature my-feature-branch |
| 65 | +``` |
| 66 | + |
| 67 | +This creates a separate working directory at `../template-application-rails-feature` checked out to `my-feature-branch`, while leaving your original clone on its current branch. |
| 68 | + |
| 69 | +### Installing from a local template |
| 70 | + |
| 71 | +Use `--template-uri` to point to your local checkout, and `--version` to specify the branch: |
| 72 | + |
| 73 | +```sh |
| 74 | +nava-platform app install \ |
| 75 | + --template-uri ~/templates/template-application-rails \ |
| 76 | + --version my-feature-branch \ |
| 77 | + --commit \ |
| 78 | + . myapp |
| 79 | +``` |
| 80 | + |
| 81 | +### Updating from a local template |
| 82 | + |
| 83 | +Similarly, to update an existing project using your local template changes: |
| 84 | + |
| 85 | +```sh |
| 86 | +nava-platform app update \ |
| 87 | + --template-uri ~/templates/template-application-rails \ |
| 88 | + --version my-feature-branch \ |
| 89 | + --commit \ |
| 90 | + . myapp |
| 91 | +``` |
| 92 | + |
| 93 | +> [!TIP] |
| 94 | +> Use `--version HEAD` to always apply the latest commit on the default branch of your local checkout, regardless of tags. |
| 95 | +
|
| 96 | +### Key CLI options for local development |
| 97 | + |
| 98 | +| Option | Description | |
| 99 | +|---|---| |
| 100 | +| `--template-uri` | Path or URL to the template source. Can be a local path (e.g., `~/templates/template-application-rails`) or a remote URL. | |
| 101 | +| `--version` | Template version to use. Accepts a branch name, tag, commit hash, or `HEAD`. Defaults to the latest tag. | |
| 102 | +| `--template-name` | Override the template name if your local directory has a different name than the upstream repository (e.g., if your worktree folder is named differently). | |
| 103 | +| `--commit` | Automatically commit the generated changes with a standard message. | |
| 104 | + |
| 105 | +## Infra template local development |
| 106 | + |
| 107 | +The infra template works the same way. The default `--template-uri` for `infra` commands is `https://github.com/navapbc/template-infra`, but you can override it: |
| 108 | + |
| 109 | +```sh |
| 110 | +nava-platform infra install \ |
| 111 | + --template-uri ~/templates/template-infra \ |
| 112 | + --version my-feature-branch \ |
| 113 | + --commit \ |
| 114 | + . myapp |
| 115 | +``` |
| 116 | + |
| 117 | +```sh |
| 118 | +nava-platform infra update \ |
| 119 | + --template-uri ~/templates/template-infra \ |
| 120 | + --version my-feature-branch \ |
| 121 | + . |
| 122 | +``` |
| 123 | + |
| 124 | +## Summary |
| 125 | + |
| 126 | +| Scenario | What to do | |
| 127 | +|---|---| |
| 128 | +| Use the latest released template version | Just run `install` or `update` — the CLI defaults to the latest tag. | |
| 129 | +| Release a new template version for all projects | Tag a new version in the template repo and push it. | |
| 130 | +| Test local template changes during development | Use `--template-uri` pointed at your local clone and `--version` set to your branch. | |
| 131 | +| Always use the latest commit (skip tag resolution) | Pass `--version HEAD`. | |
0 commit comments