1# Publish a CUE module under a public GitHub repository namespace
2# where `cue login` has been set up with read-write access to the namespace.
3# Publish a version for this new repository with `cue mod publish`,
4# and then fetch the module as a dependency via cmd/cue.
5
6github-repo-module public
7env VERSION=v0.0.1
8env MODVER=${MODULE}@v0
9
10cd publish
11
12exec cue mod init --source self ${MODVER}
13exec cue mod publish ${VERSION}
14
15cd ../depend
16
17env-fill out_foo.cue
18exec cue mod init --source self depend.localhost
19exec cue mod tidy
20exec cue export
21cmp stdout export.golden
22
23# TODO(mvdan): Use another registry token without access to this private repo
24# and check that they can list and fetch, but not publish, any versions.
25
26# Trying to publish the same version again with the same contents should succeed.
27cd ../publish
28exec cue mod publish ${VERSION}
29
30# Trying to publish the same version again with different contents should fail.
31# TODO: Note that the error does say the repository has enabled tag immutability,
32# but that error message comes from Google Cloud, not from our registry service,
33# so it's not a stable string. We should give the user a short and stable error,
34# and test for it here with a regular expression.
35cd ../publish-different
36exec cue mod init --source self ${MODVER}
37! exec cue mod publish ${VERSION}
38stderr 'cannot tag.*400 Bad Request'
39
40-- publish/foo.cue --
41package publish
42
43foo: "foo value"
44
45-- publish-different/foo.cue --
46package publish
47
48foo: "different foo value"
49
50-- depend/out_foo.cue --
51package depend
52
53import mt "${MODVER}:publish"
54
55out: mt.foo
56-- depend/export.golden --
57{
58 "out": "foo value"
59}