-
Notifications
You must be signed in to change notification settings - Fork 258
Description
Feature Request
Allow user to provide additional data to be exposed in the jinja context for changelog generation.
Description
Allow user to pass arbitrary json-formatted data for use in the template interpolation.
Use cases
The most common use case is passing dynamically generated data to the changelog like docker container hashes, built binary checksums, etc.
Possible implementation
Add a cli flag (for example --data) that takes in a json string. Parse that string and add it to the jinja context under the user_data
key. This gives the most flexibility to the user. Though, having an ability to pass a json file would also be nice, since there can be cases, where shell command length limit is reached. If this implementation is approved, I can create a PR with these changes.
Alternative solutions
I currently use this workaround:
- Create a jinja file with a variable definition inside, that consumes a json string.
index_metadata_json="$(jq -cs '.' "${INDEX_METADATA}")"
cat - >.gitlab/semantic-release/.components/image_index_table.j2 <<-EOF
{% set image_index_metadata = ${index_metadata_json:-[]} %}
EOF
- Which is then included in the jinja template:
{% from 'macros.md.j2' import docker_slugify
%}{% from 'image_index_table.j2' import image_index_metadata
%}{#
#}{% if image_index_metadata | length > 0
%}{{ "## Images\n"
}}{{ "| Name | Image |\n"
}}{{ "| ---- | ----- |\n"
}}{% for meta in image_index_metadata %}{{
"| %s | `%s:%s` <br> `%s` <br> `%s@%s` |\n" | format(meta.name, meta.repo, docker_slugify(release.version.as_semver_tag()), meta.ref, meta.repo, meta.digest)
}}{% endfor %}{{
"\n"
}}{% endif %}