docker / metadata-action

GitHub Action to extract metadata (tags, labels) from Git reference and GitHub events for Docker
https://github.com/marketplace/actions/docker-metadata-action
Apache License 2.0
892 stars 115 forks source link

semver tag : allow outputing build information (part after plus) #384

Open Murazaki opened 7 months ago

Murazaki commented 7 months ago

Description

Please allow outputting "+" prefixed information in semver tags, as some of us uses it for fork versioning.

crazy-max commented 7 months ago

Can you show an example of versioning? It should be compliant with https://semver.org/

Murazaki commented 7 months ago

I'm working on a fork. The upstream has a base semver version : 2.3.8 (git tag v2.3.8) My fork adds on top of that : 2.3.8+fork.1.0.1 (git tag v2.3.8+fork.1.0.1) Type=semver gives a build tag like this : 2.3.8

It would be better to be able to show that particular info in the docker tag : 2.3.8+fork.1.0.1

Of course it doesn't need to be default, and it can be on a per name basis. I was envisioning a variable addBuildInfo=<true|false> or addBuildInfo=<nameToPickUp> (for instance addBuildInfo=fork)

crazy-max commented 6 months ago

Thanks for your feedback. I don't think we need an extra variable, build metadata for semver should be included whatever the case.

Murazaki commented 6 months ago

Thanks for taking that into account.

I was looking at the code and I can see some choices have been made either in metadata-action or in semver that made it a bit difficult to add prerelease and build values with handlebars. I was looking into ways to make those available with helpers, here is what I came up with (there's still an issue on the type of the entry data, register might happen at the wrong time)

    handlebars.registerHelper("prereleaseMetadata", function () {
      return (this.prerelease ? "-" + this.prerelease.join(".") : "");
    });

    handlebars.registerHelper("buildMetadata", function () {
      return (this.build ? "+" + this.build.join(".") : "");
    });

    handlebars.registerHelper("completeVersion", function () {
      return (
        [this.major, this.minor, this.patch].join(".") +
        (this.prerelease ? "-" + this.prerelease.join(".") : "") +
        (this.build ? "+" + this.build.join(".") : "")
      );
    });

I put the changes in a branch, but I'm still working on adding a handlebar environment around that. https://github.com/Murazaki/metadata-action/tree/feature/semver-supplementary-data