bazel-lib icon indicating copy to clipboard operation
bazel-lib copied to clipboard

expand_template not re-running?.

Open Ryang20718 opened this issue 1 year ago • 0 comments

I see the rule expand_template https://github.com/bazel-contrib/bazel-lib/blob/d042d563c6a91f7e11f66c42c83429199bd3d5d9/docs/expand_template.md for adding tags to oci_images has a field called stampwhich can be set to 1 to always stamp, but I’m not sure the stamp is always the most up to date?

in this simple macro, I often times change the underlying image, however, when I run push, the stamp is stale and not using the most up to date version of BUILD_DOCKER_TAG.

I’d like to avoid using --stamp since that causes the analysis cache to thrash. Is this expected or a bug?

minimal repro code snippet:

load("@rules_oci//oci:defs.bzl", _oci_image = "oci_image", _oci_push = "oci_push")

def oci_push(name, image, repository, remote_tags = None):
    """Push an oci image to a remote repository"""
    expand_template(
        name = "stamp",
        out = "_{}_stamp.txt".format(name),
        stamp_substitutions = {
            "docker-tag": "{{BUILD_DOCKER_TAG}}",
        },
        template = [
            "{}_docker-tag".format(Label(image).name),
        ],
        stamp = 1,
    )
    _oci_push(
        name = name,
        image = image,
        remote_tags = ":stamp" if (remote_tags == None) else remote_tags,
        repository = repository,
    )

Ryang20718 avatar Dec 26 '24 02:12 Ryang20718