RFE: custom variables in templates

The templating syntax already supports some pre-defined variables such as version or release. I would like to have an option to define custom variables based on the content of the archive.

Use-case

I want to change the Release information dynamically based on the release type (regular, alpha/rc, dev, ...). I can parse this information from the tarball contents.

Example

regular release

Version: {{ version }}
Release: 1.{{ release }}

alpha release

Version: {{ version }}
Release: 0.alpha1.{{ release }}

Instead of the above, I'd like to use a custom variable, let's say isc_release:

Version: {{ version }}
Release: {{ isc_release }}.{{ release }}

Proposal

  • allow specifying a path to "custom variable" script in the apkg config
  • call this script before the templating engine runs and pass it the path to the tarball as an argument
  • expose the generated variables in the templating engine

I haven't given much thought about the precise mechanism of how to pass the variables from the script to apkg. A couple options that quickly come to mind are environment variables or some simple format on stdout, such as key=value, where each line contains one variable.


At this point, I'm primarily looking for a discussion and opinions about this idea.

  • Is this a good way to handle the described use-case?
  • Is the proposed solution general enough so it can be re-used for other purposes that call for custom variables?
  • Can you see any obstacles that would make this difficult to implement?
  • Would you accept this contribution into upstream?