# Publish a CUE module under a private GitHub repository namespace
# where `cue login` has been set up with read-write access to the namespace.
# Publish a version for this new repository with `cue mod publish`,
# and then fetch the module as a dependency via cmd/cue.

github-repo-module private
env VERSION=v0.0.1
env MODVER=${MODULE}@v0

cd publish

exec cue mod init --source self ${MODVER}
exec cue mod publish ${VERSION}

cd ../depend

env-fill out_foo.cue
exec cue mod init --source self depend.localhost
exec cue mod tidy
exec cue export
cmp stdout export.golden

# TODO(mvdan): Use another registry token without access to this private repo
# and check that they cannot list, fetch, or publish any versions.

-- publish/foo.cue --
package publish

foo: "foo value"

-- depend/out_foo.cue --
package depend

import mt "${MODVER}:publish"

out: mt.foo
-- depend/export.golden --
{
    "out": "foo value"
}
