Skip to content

Allow exposing arbitrary structured data to jinja context #1312

@c0m1c5an5

Description

@c0m1c5an5

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:

  1. 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
  1. 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 %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedPrevent from becoming stalefeatureA new feature or a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions