Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cue: the current release/language version should be known for local builds #2908

Closed
mvdan opened this issue Mar 4, 2024 · 2 comments
Closed
Assignees
Labels
modules Issues related to CUE modules and the experimental implementation

Comments

@mvdan
Copy link
Member

mvdan commented Mar 4, 2024

Until the accepted proposal at golang/go#50603 is implemented, this is the situation:

$ go install ./cmd/cue
go: downloading cuelabs.dev/go/oci/ociregistry v0.0.0-20240229191153-7fc950808203
$ cue version
cue version v0.0.0-20240304112812-bab5d3a8d1ae

go version devel go1.23-b5a64ba62e 2024-03-01 08:06:08 +0000
      -buildmode exe
       -compiler gc
  DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v3
             vcs git
    vcs.revision bab5d3a8d1ae6ec55b51e3cee7c96f27d6cbb478
        vcs.time 2024-03-04T11:28:12Z
    vcs.modified false
$ go install cuelang.org/go/cmd/cue@bab5d3a8d1ae6ec55b51e3cee7c96f27d6cbb478
go: downloading cuelang.org/go v0.8.0-alpha.4.0.20240304112812-bab5d3a8d1ae
$ cue version
cue version v0.8.0-alpha.4.0.20240304112812-bab5d3a8d1ae

go version devel go1.23-b5a64ba62e 2024-03-01 08:06:08 +0000
      -buildmode exe
       -compiler gc
  DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v3

That is, a local build has VCS information, but it doesn't know what semver version it is or it follows, in this case https://github.com/cue-lang/cue/releases/tag/v0.8.0-alpha.4.

This affects cue mod init and cue mod tidy in that not knowing the semver tag means we don't insert language.version: #2811 (comment)

This is a tracking issue; we can't do much until upstream implements the accepted proposal, so I expect this issue will remain open for at least a few months. Still, it's useful to track as a dependency for other issues or sharp UX edges.

@mvdan mvdan added the modules Issues related to CUE modules and the experimental implementation label Mar 4, 2024
@mvdan
Copy link
Member Author

mvdan commented Mar 4, 2024

Recently, @rogpeppe and I discussed adding a manual version string to the cmd/cue/cmd package, so that a local build would know what semver version tag it relates to, e.g. v0.8.0-alpha.4.0.20240304112812-bab5d3a8d1ae rather than v0.0.0-20240304112812-bab5d3a8d1ae. At the time I argued it's not really worth the manual work and effort, given that few users should be doing local builds, and that it didn't really impact any significant functionality.

Now that cue mod init and cue mod tidy are affected by this (see above), maybe it is worthwhile to do this. I suggest adding a const versionFallback string, which would be currently set to v0.8.0-alpha.4, to manually track the last semver tag we have done in the branch. From highest to lowest priortiy, we would determine the version as follows:

  1. Users explicity setting a version at build time via -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=<version>' would use that version as-is
  2. Users building via GOPROXY would get the module version reported by the proxy as-is
  3. Other users (i.e. those using go install ./cmd/cue) would get the fallback version manually added above, even if they are currently a few commits after that last tag, since cue version will still print the stamped VCS information

Teaching cue version about whether or not scenario 3 is exactly on a tag is possible, but it would require double the amount of manual work (e.g. const releaseCommit bool), which we would change immediately after every release tag. My impression is that this isn't worth it, and it wouldn't affect language.version either.

@myitcv
Copy link
Member

myitcv commented Mar 5, 2024

Sounds like a good approach to me. Thanks for the analysis.

@mvdan mvdan self-assigned this Mar 5, 2024
cueckoo pushed a commit that referenced this issue Mar 7, 2024
As described in https://cuelang.org/issue/2908, the behavior now is:

1) Users explicity setting a version at build time via
   -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=<version>'
   would use that version as-is, just like today
2) Users building via GOPROXY would get the module version
   reported by the proxy as-is, just like today
3) Other users (i.e. those using `go install ./cmd/cue`) would now get
   the fallback version added by this patch and updated manually,
   even if they are currently a few commits after that last tag,
   since `cue version` will still print the stamped VCS information

That is, up until now and in master, we had

    $ go install ./cmd/cue
    $ cue version
    cue version v0.0.0-20240307083748-cdcb6fa19bf3

    go version devel go1.23-58052fe8e7 2024-03-07 05:27:04 +0000
          -buildmode exe
           -compiler gc
      DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1,winreadlinkvolume=0,winsymlink=0
         CGO_ENABLED 1
              GOARCH amd64
                GOOS linux
             GOAMD64 v3
                 vcs git
        vcs.revision cdcb6fa
            vcs.time 2024-03-07T08:37:48Z
        vcs.modified false

Whereas now, we have

    $ go install ./cmd/cue
    $ cue version
    cue version v0.8.0-alpha.5

    go version devel go1.23-58052fe8e7 2024-03-07 05:27:04 +0000
          -buildmode exe
           -compiler gc
      DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1,winreadlinkvolume=0,winsymlink=0
         CGO_ENABLED 1
              GOARCH amd64
                GOOS linux
             GOAMD64 v3
                 vcs git
        vcs.revision 9d9b786f0996468bf527a9412d1389a7a17a0562
            vcs.time 2024-03-07T15:13:21Z
        vcs.modified false

Such a local build will also now be able to add language.version
to cue.mod/module.cue via `cue mod init` and `cue mod tidy`,
as up until now a local cmd/cue build did not know its own
semver version, from which we derive the language version.

Add a TODO to this added fallback version, as once upstream Go
implements the proposal at https://go.dev/issue/50603,
we can remove this manually updated version and keep semver versions
in local builds via the Go toolchain automatically.

Fixes #2908.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I9e6189fcdaff5b493c9065e5bb74f4dd9a023800
cueckoo pushed a commit that referenced this issue Mar 7, 2024
As described in https://cuelang.org/issue/2908, the behavior now is:

1) Users explicity setting a version at build time via
   -ldflags='-X cuelang.org/go/cmd/cue/cmd.version=<version>'
   would use that version as-is, just like today
2) Users building via GOPROXY would get the module version
   reported by the proxy as-is, just like today
3) Other users (i.e. those using `go install ./cmd/cue`) would now get
   the fallback version added by this patch and updated manually,
   even if they are currently a few commits after that last tag,
   since `cue version` will still print the stamped VCS information

That is, up until now and in master, we had

    $ go install ./cmd/cue
    $ cue version
    cue version v0.0.0-20240307083748-cdcb6fa19bf3

    go version devel go1.23-58052fe8e7 2024-03-07 05:27:04 +0000
          -buildmode exe
           -compiler gc
      DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1,winreadlinkvolume=0,winsymlink=0
         CGO_ENABLED 1
              GOARCH amd64
                GOOS linux
             GOAMD64 v3
                 vcs git
        vcs.revision cdcb6fa
            vcs.time 2024-03-07T08:37:48Z
        vcs.modified false

Whereas now, we have

    $ go install ./cmd/cue
    $ cue version
    cue version v0.8.0-alpha.5

    go version devel go1.23-58052fe8e7 2024-03-07 05:27:04 +0000
          -buildmode exe
           -compiler gc
      DefaultGODEBUG httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1,winreadlinkvolume=0,winsymlink=0
         CGO_ENABLED 1
              GOARCH amd64
                GOOS linux
             GOAMD64 v3
                 vcs git
        vcs.revision 9d9b786f0996468bf527a9412d1389a7a17a0562
            vcs.time 2024-03-07T15:13:21Z
        vcs.modified false

Such a local build will also now be able to add language.version
to cue.mod/module.cue via `cue mod init` and `cue mod tidy`,
as up until now a local cmd/cue build did not know its own
semver version, from which we derive the language version.

Add a TODO to this added fallback version, as once upstream Go
implements the proposal at https://go.dev/issue/50603,
we can remove this manually updated version and keep semver versions
in local builds via the Go toolchain automatically.

Update all existing test files as well.

Fixes #2908.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I9e6189fcdaff5b493c9065e5bb74f4dd9a023800
@cueckoo cueckoo closed this as completed in fc7038a Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules Issues related to CUE modules and the experimental implementation
Projects
Archived in project
Status: v0.8.0-rc.1
Development

No branches or pull requests

2 participants