Manifests v2 (preview)
version: 2 is the next manifest format. It's a preview and can still change until comtrya 0.13.0, so don't use it yet for manifests you depend on. Version 1 manifests keep working, and both versions can sit in the same manifest directory.
Version 2 lets you write less and need fewer command.run workarounds. In short:
- Templates are rendered per value, after the manifest's
where, and a template can give a number or a boolean. - One name per action and field: the old aliases are errors that name the one to use.
- A variant sets only what differs from its action.
- Files can sit next to the manifest, without a
files/directory. titlenames an action in the log, andregisterkeeps what a command printed for later actions.- Package states:
state: latestandstate: absentonpackage.install(also in version 1).
Comtrya 0.12.0 and older refuse version: 2; 0.9.x and older ignore version and misread such a manifest. Migrating from version 1 lists what to change.
Templates per value
Version 1 renders the whole file with Tera and then parses the result. Version 2 parses the file first, checks the manifest's where, and then renders each value on its own:
# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
where: os.name == "linux"
actions:
- action: directory.create
path: "{{ user.home_dir }}/bin"
- action: command.run
command: echo
args: ["{{ variables.greeting }}, {{ user.name }}"]
privileged: "{{ variables.as_root }}"
- The file has to be valid YAML or TOML as it is, so quote values with templates:
path: "{{ user.home_dir }}/bin". - A manifest whose
whereis false isn't rendered at all, so a template that only works on Linux can't fail on macOS.whereconditions aren't templates; they read the contexts themselves. - An error names the value it's in, like
actions[1].args[0]: …. - A value that is one template and nothing else becomes a number or a boolean when its field doesn't hold text, like
privileged: "{{ variables.as_root }}"above, orchmod: "{{ variables.mode }}". Text fields keep the rendered text, soargs: ["{{ variables.port }}"]stays"8080". {% if %}and{% for %}work inside a value, but not around keys or actions: usewhereon the action, or a variant, instead.
One name per action and field
Version 1 knows several names for some actions and fields. Version 2 knows one, and an old name is an error that names the one to use:
| Version 1 also takes | Version 2 only takes |
|---|---|
cmd.run | command.run |
dir.copy, dir.create, dir.remove | directory.copy, directory.create, directory.remove |
binary.gh, bin.github, bin.gh | binary.github |
package.installed, package.repo | package.install, package.repository |
source, target in file.copy, file.download, file.unarchive and file.link | from, to |
sudo | privileged |
repository in git.clone | repo_url |
url in package.repository | name |
The schema shows every action and field under its one name. Values aren't affected: provider names like linux or privilege providers like doas work as before.
Variants set only what differs
In version 1, a variant is a complete action and repeats every field the action needs. In version 2, a variant sets only the fields that differ, and takes the others from its action:
# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
- action: package.install
name: fd
variants:
- where: os.distribution == "Ubuntu"
name: fd-find
- A field the variant sets replaces the action's field whole; lists and maps aren't merged.
- Which version applies is the same as in version 1: the first variant whose
whereis true, else the action itself. titleandcontinue_on_errorbelong to the whole action; a variant can't set them.
More in Variants.
Files next to the manifest
A source path that starts with ./ or ../ is relative to the manifest file, so a folder can hold a manifest and its files:
manifests/
zsh/
zsh.yaml
zshrc
# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
- action: file.link
from: ./zshrc
to: "{{ user.home_dir }}/.zshrc"
- A plain name, like
from: zshrc, still looks infiles/, as in version 1. - This works for
file.copy,file.link,file.unarchiveanddirectory.copy. - Comtrya reads every YAML and TOML file below the manifest directory as a manifest. If such a folder also holds YAML or TOML files that aren't manifests, like an app's own config, list them in
ignoreinComtrya.yaml. {{ manifest.dir }}and{{ manifest.name }}are the manifest's directory and name, in both versions.
title
title on an action is shown in the log instead of the generated summary:
# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
- action: package.install
title: Shell tools
list: [fd, ripgrep]
register
register: <name> on a command.run keeps what the command printed and how it exited. Later actions read it as registered.<name>.stdout, .stderr and .exit_code, in templates and in where:
# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
- action: command.run
command: rustc
args: [--version]
register: rustc
- action: command.run
title: Say which Rust is installed
command: echo
args: ["{{ registered.rustc.stdout }}"]
where: registered.rustc.exit_code == 0
The values are there for the later actions of the manifest and for the manifests that depend on it. A dry run runs no commands, so it skips actions that read registered.*. All rules in Registering the output.
Package states
state on package.install says whether a package is installed (present, the default), installed and up to date (latest), or removed (absent). It works in version 1 too:
# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions:
- action: package.install
list: [fd, ripgrep]
state: latest
- action: package.install
name: nano
state: absent
Which providers support it, and how they find outdated packages: Packages.
Editor support
Version 2 has its own JSON schema, published at https://comtrya.dev/schema-v2.json. It knows only the version 2 names, title, register, variants that set only some fields, and templates in place of numbers or booleans.
For YAML (yaml-language-server):
# yaml-language-server: $schema=https://comtrya.dev/schema-v2.json
version: 2
actions: []
For TOML (Taplo):
#:schema https://comtrya.dev/schema-v2.json
version = 2
actions = []