#dagger versioning

1 messages ยท Page 1 of 1 (latest)

strong walrus
#

Hello! Do you mean versioning of dagger modules?

#

Dagger modules use git as the source of truth. The git repository is the registry; git tags and branches can be used as versions

clear zealot
#

No sorry, I mean applying semantic versioning 2.0 in my CICD Pipelines

strong walrus
#

and git commits are used for pinning

clear zealot
#

https://semver.org/

I would like to automatically generate versioned tags when pipelines get triggered on stable, dev, and pre-release branches.

Basically I need semver to push versioned artifacts on OCI registries for my FluxCD GitOps operator to pull from based on some ImagePolicy

ivory steeple
clear zealot
#

yes, correct.

I guess that as input there is the need for some git context (previous tags, branch that triggered the pipeline, type of action pr/push ...).

If I understood correctl, in yaml defined CICD systems like Gitlab, a lot of people are using this npm package called semver for doing this (inside the Job's Container, of course)

undone magnet
#

We're using https://gitversion.net/docs/ (a dotnet tool) to do exactly that - within a dedicated Dagger module, then pass on the generated version to the next steps of our CI/CD pipeline

ivory steeple
#

Notice that using the git api in Dagger such as git https://github.com/dagger/dagger | branch main | tree

.git/packed-refs
.git/refs/tags/main
.git/shallow

and some other differences compared to git clone and then read in the Directory.

With the shallow clone, I don't get the right output from dotnet-gitversion

#

But if fed a local dir like from a previous git clone https://github.com/dagger/dagger then it works well

import dagger
from dagger import dag, function, object_type


@object_type
class GitVersion:
    @function
    def container(self, version: str = "6.1.0-alpine.3.20-9.0") -> dagger.Container:
        """Returns a gitversion container at provided version"""
        return dag.container().from_("gittools/gitversion:"+ version)

    @function
    async def version(self, repo: dagger.Directory) -> str:
        """Returns gitversion output for the provided repo Directory"""
        return await (
            self.container()
            .with_mounted_directory("/repo", repo)
            .with_workdir("/repo")
            .with_exec(["/tools/dotnet-gitversion"])
            .stdout()
        )
{
  "AssemblySemFileVer": "0.16.3.0",
  "AssemblySemVer": "0.16.3.0",
  "BranchName": "main",
  "BuildMetaData": null,
  "CommitDate": "2025-03-06",
  "CommitsSinceVersionSource": 44,
  "EscapedBranchName": "main",
  "FullBuildMetaData": "Branch.main.Sha.07b0cd6c664ffb2fef63fd98eee0b8bb89cebae7",
  "FullSemVer": "0.16.3-44",
  "InformationalVersion": "0.16.3-44+Branch.main.Sha.07b0cd6c664ffb2fef63fd98eee0b8bb89cebae7",
  "Major": 0,
  "MajorMinorPatch": "0.16.3",
  "Minor": 16,
  "Patch": 3,
  "PreReleaseLabel": "",
  "PreReleaseLabelWithDash": "",
  "PreReleaseNumber": 44,
  "PreReleaseTag": "44",
  "PreReleaseTagWithDash": "-44",
  "SemVer": "0.16.3-44",
  "Sha": "07b0cd6c664ffb2fef63fd98eee0b8bb89cebae7",
  "ShortSha": "07b0cd6",
  "UncommittedChanges": 0,
  "VersionSourceSha": "b3e6f765a547b22edc61a24336177348b9f00d94",
  "WeightedPreReleaseNumber": 55044
}

with dagger -i -c 'version $(git https://github.com/dagger/dagger | branch main | tree)'

{
  "AssemblySemFileVer": "0.0.1.0",
  "AssemblySemVer": "0.0.1.0",
  "BranchName": "main",
  "BuildMetaData": null,
  "CommitDate": "2025-03-06",
  "CommitsSinceVersionSource": 1,
  "EscapedBranchName": "main",
  "FullBuildMetaData": "Branch.main.Sha.07b0cd6c664ffb2fef63fd98eee0b8bb89cebae7",
  "FullSemVer": "0.0.1-1",
  "InformationalVersion": "0.0.1-1+Branch.main.Sha.07b0cd6c664ffb2fef63fd98eee0b8bb89cebae7",
  "Major": 0,
  "MajorMinorPatch": "0.0.1",
  "Minor": 0,
  "Patch": 1,
  "PreReleaseLabel": "",
  "PreReleaseLabelWithDash": "",
  "PreReleaseNumber": 1,
  "PreReleaseTag": "1",
  "PreReleaseTagWithDash": "-1",
  "SemVer": "0.0.1-1",
  "Sha": "07b0cd6c664ffb2fef63fd98eee0b8bb89cebae7",
  "ShortSha": "07b0cd6",
  "UncommittedChanges": 0,
  "VersionSourceSha": "",
  "WeightedPreReleaseNumber": 55001
}
slim laurel
#

i'm actually planning on fixing this soon! and adding a ton more configurability to git clones ๐Ÿ™‚

median forge
#

yeah, I would like to know to .. not sure what the conclusion were ?

I played around with this and there are (limiting it to go-lang native impl ?)
SVU https://github.com/caarlos0/svu
and
NVS https://github.com/purpleclay/nsv

which has a module in daggerverse ?
https://daggerverse.dev/mod/github.com/purpleclay/daggerverse/nsv@910e1ac9754f208569ac4d65f1ef52d9a2301833

GitHub

semantic version utility. Contribute to caarlos0/svu development by creating an account on GitHub.

GitHub

Semantic versioning without any config. Contribute to purpleclay/nsv development by creating an account on GitHub.

clear zealot
ivory steeple
median forge
#

sry, yes limiting it to go-lang was my preference

clear zealot