Skip to content

pkg_npm should support stamping with arbitrary stable/volatile keys 聽#1694

Description

@joeljeske

馃殌 feature request

Relevant Rules

pkg_npm

Description

I want to be able to stamp multiple pieces of version information in npm archive.

Describe the solution you'd like

pkg_npm (and probably pkg_web) should allow values to use make-style variable replacements in the substitutions dictionary. The keys would still refer to strings in the source files to find and replace.

pkg_npm(
  substitutions = {
    # normal substitution
    "blaze": "bazel",
    # Make-style substitutions (from both volatile-keys and stable-keys)
    "GIT_HASH": "$(BUILD_SCM_HASH)",
    "HOST": "$(BUILD_HOST)",
    "GIT_BRANCH": "$(STABLE_SCM_BRANCH)", 
  },
  stamp = 1 # or 0,
)

Describe alternatives you've considered

Writing a rule to manually copy the info from the version file into the relevant files.

Activity

  1. alexeagle commented on Mar 7, 2020

    @alexeagle
    Collaborator

    Yeah that makes a lot of sense. Do you have time to contribute it?

  2. joeljeske commented on Mar 8, 2020

    @joeljeske
    ContributorAuthor

    Yea I can look into it hopefully. I would want to see your thoughts on #1693 and how it relates to this ticket. My needs would only be satisfied here if I could mark some targets as to never rely on stamping and some conditional on the stamp flag.

    It seems like there might be place for a generic rule or task that makes the stamping easy for plain text interpolations as opposed to duplicating this functionality in multiple places.

  3. alexeagle commented on Mar 9, 2020

    @alexeagle
    Collaborator

    Also I'd be curious why it's good to support both stable keys and volatile keys. In particular since contributing npm publishing to bazelisk I was wondering why they use the stable keys file, and whether we should be recommending users to do the same. @philwo if you have a minute to comment?

  4. philwo commented on Mar 9, 2020

    @philwo
    Contributor

    @meisterT told me he can help us out here. I'm not very knowledgeable about this particular feature of Bazel.

  5. joeljeske commented on Mar 9, 2020

    @joeljeske
    ContributorAuthor

    It would seem that the use of stable keys vs. volatile keys is up to the needs of the user/organization. Some orgs may want to re-use via cache as much as possible and only ever stamp an artifact the first time its contents are generated, and others may want to re-stamp it when certain criteria is met (branch change, user/host change, etc...)

    It would seem to me that the stamping feature of Bazel is representative of the needs of Google but may not be very flexible for a wider variety of needs, especially when it comes to remote caching of stamped builds

  6. thesayyn commented on Jun 22, 2020

    @thesayyn
    Collaborator

    I have opened up a PR for the stamping feature of pkg_web a long time ago. It works the way you've described. Which still waiting for a review BTW.

    See #1621, #1664

  7. mattem commented on Jun 22, 2020

    @mattem
    Collaborator

    @thesayyn, thanks for the contribution, apologies that we missed following up the on review. I'll take a look at the PR shortly and ping Alex too.

  8. thesayyn commented on Jun 22, 2020

    @thesayyn
    Collaborator

    Thank you. Also, I can implement the same feature for pkg_npm too.

  9. alexeagle commented on Aug 30, 2020

    @alexeagle
    Collaborator

    Okay I just did stamping at work with rules_go so it's super clear what to do (they did a nice job in rules_go docs of presenting it simply as well, so I'll borrow from them)

  10. alexeagle commented on Aug 31, 2020

    @alexeagle
    Collaborator

    Fixed by #2157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions