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

feat: supports add dependencies by git branch #340

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,10 @@ func (c *KpmClient) DownloadFromGit(dep *pkg.Git, localPath string) (string, err
msg = fmt.Sprintf("with commit '%s'", dep.Commit)
}

if len(dep.Branch) != 0 {
msg = fmt.Sprintf("with branch '%s'", dep.Branch)
}

reporter.ReportMsgTo(
fmt.Sprintf("cloning '%s' %s", dep.Url, msg),
c.logWriter,
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func KpmUpdate(c *cli.Context, kpmcli *client.KpmClient) error {
return reporter.NewErrorEvent(reporter.FailedUpdatingBuildList, err, "failed to update build list")
}

// get all the vertices in the graph
// get all the vertices in the graph
modules, err := graph.TopologicalSort(depGraph)
if err != nil {
return reporter.NewErrorEvent(reporter.FailedTopologicalSort, err, "failed to sort the dependencies")
Expand All @@ -131,8 +131,8 @@ func KpmUpdate(c *cli.Context, kpmcli *client.KpmClient) error {

// GetModulesToUpdate validates if the packages is present in kcl.mod file and
// find the latest version if version is not specified. Depending on the value of pkgVersion,
// modulesToUpgrade or modulesToDowngrade will be updated.
func GetModulesToUpdate(kclPkg *pkg.KclPkg, modulesToUpgrade []module.Version, modulesToDowngrade []module.Version, pkgInfo string) error {
// modulesToUpgrade or modulesToDowngrade will be updated.
func GetModulesToUpdate(kclPkg *pkg.KclPkg, modulesToUpgrade []module.Version, modulesToDowngrade []module.Version, pkgInfo string) error {
pkgInfo = strings.TrimSpace(pkgInfo)
pkgName, pkgVersion, err := ParseOciPkgNameAndVersion(pkgInfo)
if err != nil {
Expand Down Expand Up @@ -172,9 +172,9 @@ func GetModulesToUpdate(kclPkg *pkg.KclPkg, modulesToUpgrade []module.Version,
return nil
}

// InsertModuleToDeps checks whether module is present in the buildList and it is not the same as the target module,
// InsertModuleToDeps checks whether module is present in the buildList and it is not the same as the target module,
// and inserts it to the dependencies of kclPkg
func InsertModuleToDeps(kclPkg *pkg.KclPkg, module module.Version, target module.Version, buildList []module.Version, reqs mvs.ReqsGraph) (error) {
func InsertModuleToDeps(kclPkg *pkg.KclPkg, module module.Version, target module.Version, buildList []module.Version, reqs mvs.ReqsGraph) error {
if module.Path == target.Path || !slices.Contains(buildList, module) {
return nil
}
Expand All @@ -196,4 +196,4 @@ func InsertModuleToDeps(kclPkg *pkg.KclPkg, module module.Version, target module
}
kclPkg.ModFile.Dependencies.Deps[module.Path] = d
return nil
}
}
12 changes: 12 additions & 0 deletions pkg/package/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (source *Source) MarshalTOML() string {
const GIT_URL_PATTERN = "git = \"%s\""
const TAG_PATTERN = "tag = \"%s\""
const GIT_COMMIT_PATTERN = "commit = \"%s\""
const GIT_BRANCH_PATTERN = "branch = \"%s\""
const VERSION_PATTERN = "version = \"%s\""
const SEPARATOR = ", "

Expand All @@ -134,6 +135,12 @@ func (git *Git) MarshalTOML() string {
sb.WriteString(SEPARATOR)
sb.WriteString(fmt.Sprintf(GIT_COMMIT_PATTERN, git.Commit))
}

if len(git.Branch) != 0 {
sb.WriteString(SEPARATOR)
sb.WriteString(fmt.Sprintf(GIT_BRANCH_PATTERN, git.Branch))
}

if len(git.Version) != 0 {
sb.WriteString(SEPARATOR)
sb.WriteString(fmt.Sprintf(VERSION_PATTERN, git.Version))
Expand Down Expand Up @@ -367,6 +374,7 @@ func (source *Source) UnmarshalModTOML(data interface{}) error {
const GIT_URL_FLAG = "git"
const TAG_FLAG = "tag"
const GIT_COMMIT_FLAG = "commit"
const GIT_BRANCH_FLAG = "branch"

func (git *Git) UnmarshalModTOML(data interface{}) error {
meta, ok := data.(map[string]interface{})
Expand All @@ -386,6 +394,10 @@ func (git *Git) UnmarshalModTOML(data interface{}) error {
git.Commit = v
}

if v, ok := meta[GIT_BRANCH_FLAG].(string); ok {
git.Branch = v
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
KPM_HOME=""
KCLVM_VENDOR_HOME=""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kpm --quiet run
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
a:
name: flask-demo
replicas: 1
labels:
app: flask-demo
service:
type: NodePort
ports:
- port: 5000
protocol: TCP
targetPort: 5000
containers:
flaskdemo:
image: kcllang/flask_demo:8d31498e765ff67a2fa9933d4adffe067544b2fe
ports:
- protocol: TCP
containerPort: 5000
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_kpm_run_with_git_commit_dep"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
flask-demo-kcl-manifests = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git", branch = "main" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[dependencies]
[dependencies.flask-demo-kcl-manifests]
name = "flask-demo-kcl-manifests"
full_name = "flask_manifests_0.0.1"
version = "0.0.1"
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests.git"
branch = "main"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import flask_demo_kcl_manifests as flask

a = flask.config
Loading