this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: include metadata when publishing modules

This change wires up the new metadata support
in the modregistry package to the actual `cue mod publish`
command.

Fixes #3034

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I62804cc56326f3b2b20d977901146f7548492f96
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193706
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+55 -4
+7 -4
cmd/cue/cmd/modpublish.go
··· 92 92 93 93 // TODO verify that all dependencies exist in the registry. 94 94 95 - var vcsStatus vcs.Status 95 + var meta *modregistry.Metadata 96 96 97 97 switch mf.Source.Kind { 98 98 case "self": ··· 121 121 }); err != nil { 122 122 return err 123 123 } 124 - vcsStatus = status 124 + meta = &modregistry.Metadata{ 125 + VCSType: mf.Source.Kind, 126 + VCSCommit: status.Revision, 127 + VCSCommitTime: status.CommitTime, 128 + } 125 129 } 126 130 info, err := zf.Stat() 127 131 if err != nil { ··· 129 133 } 130 134 131 135 rclient := modregistry.NewClientWithResolver(resolver) 132 - _ = vcsStatus // TODO attach vcsStatus to PutModule metadata 133 - if err := rclient.PutModule(backgroundContext(), mv, zf, info.Size()); err != nil { 136 + if err := rclient.PutModuleWithMetadata(backgroundContext(), mv, zf, info.Size(), meta); err != nil { 134 137 return fmt.Errorf("cannot put module: %v", err) 135 138 } 136 139 fmt.Printf("published %s\n", mv)
+33
cmd/cue/cmd/script_test.go
··· 20 20 "context" 21 21 "encoding/json" 22 22 "fmt" 23 + "io" 23 24 "io/fs" 24 25 "net/http" 25 26 "net/http/httptest" ··· 32 33 "testing" 33 34 "time" 34 35 36 + "cuelabs.dev/go/oci/ociregistry/ociclient" 35 37 "cuelabs.dev/go/oci/ociregistry/ocimem" 38 + "cuelabs.dev/go/oci/ociregistry/ociref" 36 39 "github.com/google/shlex" 37 40 "github.com/rogpeppe/go-internal/goproxytest" 38 41 "github.com/rogpeppe/go-internal/gotooltest" ··· 111 114 data = tsExpand(ts, data) 112 115 ts.Check(os.WriteFile(path, []byte(data), 0o666)) 113 116 } 117 + }, 118 + // get-manifest writes the manifest for a given reference within an OCI 119 + // registry to a file in JSON format. 120 + "get-manifest": func(ts *testscript.TestScript, neg bool, args []string) { 121 + usage := func() { 122 + ts.Fatalf("usage: get-metadata OCI-ref@tag dest-file") 123 + } 124 + if neg { 125 + usage() 126 + } 127 + if len(args) != 2 { 128 + usage() 129 + } 130 + ref, err := ociref.Parse(args[0]) 131 + if err != nil { 132 + ts.Fatalf("invalid OCI reference %q: %v", args[0], err) 133 + } 134 + if ref.Tag == "" { 135 + ts.Fatalf("no tag in OCI reference %q", args[0]) 136 + } 137 + client, err := ociclient.New(ref.Host, &ociclient.Options{ 138 + Insecure: true, 139 + }) 140 + ts.Check(err) 141 + r, err := client.GetTag(context.Background(), ref.Repository, ref.Tag) 142 + ts.Check(err) 143 + data, err := io.ReadAll(r) 144 + ts.Check(err) 145 + err = os.WriteFile(ts.MkAbs(args[1]), data, 0o666) 146 + ts.Check(err) 114 147 }, 115 148 // memregistry starts an in-memory OCI server and sets the argument 116 149 // environment variable name to its hostname.
+15
cmd/cue/cmd/testdata/script/registry_publish_with_git.txtar
··· 18 18 exec cue eval . 19 19 cmp stdout ../expect-eval-stdout 20 20 21 + # Check that the manifest contains the expected git metadata 22 + # Note: we use cue vet rather than cmp because the 23 + # manifest contains information that's tricky to control/predict 24 + # in a test, such as git commit times and commit hashes. 25 + get-manifest $MEMREGISTRY/x.example/e:v0.0.1 $WORK/manifest0.json 26 + exec cue vet $WORK/manifest-schema.cue $WORK/manifest0.json 27 + 21 28 # If the git directory is not clean, the publish should fail. We can 22 29 # conveniently combine that check with the .gitignore removal. 23 30 cd $WORK/example ··· 38 45 exec cue eval . 39 46 cmp stdout $WORK/expect-eval-stdout2 40 47 48 + -- manifest-schema.cue -- 49 + import "time" 50 + 51 + annotations!: { 52 + "org.cuelang.vcs-type"!: "git" 53 + "org.cuelang.vcs-commit-time"!: time.Time 54 + "org.cuelang.vcs-commit"!: =~"^[a-f0-9]+$" 55 + } 41 56 -- expect-publish-stdout -- 42 57 published x.example/e@v0.0.1 43 58 -- expect-eval-stdout --