From ab04451ac40834939b0953ddc4156bf21e0e6655 Mon Sep 17 00:00:00 2001 From: zongz Date: Mon, 9 Dec 2024 17:36:31 +0800 Subject: [PATCH] fix: move push on API `Push` Signed-off-by: zongz --- cmd/kcl/commands/mod_push.go | 29 +++++++++++++---------------- scripts/e2e/pull_pkg.sh | 5 +++++ scripts/e2e/push_pkg.sh | 5 +++++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/cmd/kcl/commands/mod_push.go b/cmd/kcl/commands/mod_push.go index a36d564..b6feb06 100644 --- a/cmd/kcl/commands/mod_push.go +++ b/cmd/kcl/commands/mod_push.go @@ -7,9 +7,9 @@ import ( "github.com/spf13/cobra" "kcl-lang.io/kpm/pkg/client" + "kcl-lang.io/kpm/pkg/downloader" "kcl-lang.io/kpm/pkg/errors" kpmoci "kcl-lang.io/kpm/pkg/oci" - "kcl-lang.io/kpm/pkg/opt" pkg "kcl-lang.io/kpm/pkg/package" "kcl-lang.io/kpm/pkg/reporter" "kcl-lang.io/kpm/pkg/utils" @@ -164,24 +164,21 @@ func pushPackage(ociUrl string, kclPkg *pkg.KclPkg, vendorMode bool, cli *client ) } } - - // 3. Generate the OCI options from oci url and the version of current kcl package. - ociOpts, err := opt.ParseOciOptionFromOciUrl(ociUrl, kclPkg.GetPkgTag()) - if err != (*reporter.KpmEvent)(nil) { - return reporter.NewErrorEvent( - reporter.UnsupportOciUrlScheme, - errors.InvalidOciUrl, - "only support url scheme 'oci://'.", - ) - } - ociOpts.Annotations, err = kclPkg.GenOciManifestFromPkg() + // 4. Push it. + ociSource := downloader.Source{} + err = ociSource.FromString(ociUrl) if err != nil { return err } - - reporter.ReportMsgTo(fmt.Sprintf("package '%s' will be pushed", kclPkg.GetPkgName()), cli.GetLogWriter()) - // 4. Push it. - err = cli.PushToOci(tarPath, ociOpts) + ociSource.ModSpec = &downloader.ModSpec{ + Name: kclPkg.GetPkgName(), + Version: kclPkg.GetPkgTag(), + } + err = cli.Push( + client.WithPushModPath(kclPkg.HomePath), + client.WithPushSource(ociSource), + client.WithPushVendorMode(vendorMode), + ) if err != (*reporter.KpmEvent)(nil) { return err } diff --git a/scripts/e2e/pull_pkg.sh b/scripts/e2e/pull_pkg.sh index 992cf5d..e5a2f6d 100755 --- a/scripts/e2e/pull_pkg.sh +++ b/scripts/e2e/pull_pkg.sh @@ -13,6 +13,11 @@ cd ./scripts/e2e/pkg_in_reg/ # Check if file exists + +if [ ! -d "./oci/ghcr.io/kcl-lang/k8s/1.27/k8s/1.27" ]; then + $current_dir/bin/kcl mod pull k8s:1.27 +fi + if [ ! -d "./oci/ghcr.io/kcl-lang/k8s/1.28/k8s/1.28" ]; then $current_dir/bin/kcl mod pull k8s:1.28 fi diff --git a/scripts/e2e/push_pkg.sh b/scripts/e2e/push_pkg.sh index c255b81..cd6e7ac 100755 --- a/scripts/e2e/push_pkg.sh +++ b/scripts/e2e/push_pkg.sh @@ -11,6 +11,11 @@ echo $current_dir $current_dir/bin/kcl registry login -u test -p 1234 localhost:5001 +cd ./scripts/e2e/pkg_in_reg/oci/ghcr.io/kcl-lang/k8s/1.27/k8s/1.27 +$current_dir/bin/kcl mod push + +cd "$current_dir" + cd ./scripts/e2e/pkg_in_reg/oci/ghcr.io/kcl-lang/k8s/1.28/k8s/1.28 $current_dir/bin/kcl mod push