Skip to content

Commit

Permalink
Fix: fix filepath for windows (#79)
Browse files Browse the repository at this point in the history
Signed-off-by: FogDong <[email protected]>


### Description of your changes

<!--

Briefly describe what this pull request does. We love pull requests that
resolve an open KubeVela issue. If yours does, you
can uncomment the below line to indicate which issue your PR fixes, for
example
"Fixes #500":

-->

fix filepath for windows

Ref kubevela/kubevela#4982

I have:

- [x] Read and followed KubeVela's [contribution
process](https://github.com/kubevela/kubevela/blob/master/contribute/create-pull-request.md).
- [ ] [Related Docs](https://github.com/kubevela/kubevela.io) updated
properly. In a new feature or configuration option, an update to the
documentation is necessary.
- [x] Run `make reviewable` to ensure this PR is ready for review.
- [ ] Added `backport release-x.y` labels to auto-backport this PR if
necessary.

### How has this code been tested

<!--
Before reviewers can be confident in the correctness of this pull
request, it
needs to tested and shown to be correct. Briefly describe the testing
that has
already been done or which is planned for this change.
-->


### Special notes for your reviewer

<!--

Be sure to direct your reviewers'
attention to anything that needs special consideration.

-->
  • Loading branch information
FogDong authored Nov 2, 2022
2 parents fe82815 + 4880769 commit bc4323e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
14 changes: 11 additions & 3 deletions pkg/stdlib/actions/v1/pkgs/util.cue
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@
#do: "log"
#provider: "util"

// +usage=The data to print in the controller logs
data?: {...} | string
// +usage=The log level of the data
level: *3 | int
// note that if you set source in multiple op.#Log, only the latest one will work
// +usage=The log source of this step. You can specify it from a url or resources. Note that if you set source in multiple op.#Log, only the latest one will work
source?: close({
// +usage=Specify the log source url of this step
url: string
}) | close({
// +usage=Specify the log resources of this step
resources?: [...{
name?: string
cluster?: string
// +usage=Specify the name of the resource
name?: string
// +usage=Specify the cluster of the resource
cluster?: string
// +usage=Specify the namespace of the resource
namespace?: string
// +usage=Specify the label selector of the resource
labelSelector?: {...}
}]
})
Expand Down
29 changes: 17 additions & 12 deletions pkg/stdlib/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ func GetPackages() (map[string]string, error) {
ret := make(map[string]string)

for _, dirs := range versions {
pathPrefix := filepath.Join(builtinActionPath, dirs.Name())
files, err := fs.ReadDir(filepath.Join(pathPrefix, packagePath))
pathPrefix := fmt.Sprintf("%s/%s", builtinActionPath, dirs.Name())
files, err := fs.ReadDir(fmt.Sprintf("%s/%s", pathPrefix, packagePath))
if err != nil {
return nil, err
}
opBytes, err := fs.ReadFile(filepath.Join(pathPrefix, "op.cue"))
opBytes, err := fs.ReadFile(fmt.Sprintf("%s/%s", pathPrefix, "op.cue"))
if err != nil {
return nil, err
}
opContent := string(opBytes) + "\n"
for _, file := range files {
body, err := fs.ReadFile(filepath.Join(pathPrefix, packagePath, file.Name()))
body, err := fs.ReadFile(fmt.Sprintf("%s/%s/%s", pathPrefix, packagePath, file.Name()))
if err != nil {
return nil, err
}
Expand All @@ -96,17 +96,23 @@ func GetPackages() (map[string]string, error) {
// AddImportsFor install imports for build.Instance.
func AddImportsFor(inst *build.Instance, tagTempl string) error {
inst.Imports = append(inst.Imports, GeneralImports...)
addDefault := true
addDefault := make(map[string]bool)
for _, builtin := range builtinImport {
addDefault[builtin.PkgName] = true
}

for _, a := range inst.Imports {
if a.PkgName == filepath.Base(builtinPackageName) || (a.PkgName == filepath.Join(filepath.Base(builtinPackageName), "v1")) {
addDefault = false
break
for _, builtin := range builtinImport {
if a.PkgName == builtin.PkgName {
addDefault[builtin.PkgName] = false
}
}

}
if addDefault {
inst.Imports = append(inst.Imports, builtinImport...)

for _, builtin := range builtinImport {
if add := addDefault[builtin.PkgName]; add {
inst.Imports = append(inst.Imports, builtin)
}
}
if tagTempl != "" {
p := &build.Instance{
Expand All @@ -126,7 +132,6 @@ func AddImportsFor(inst *build.Instance, tagTempl string) error {
}

func initBuiltinImports() ([]*build.Instance, error) {

imports := make([]*build.Instance, 0)
pkgs, err := GetPackages()
if err != nil {
Expand Down

0 comments on commit bc4323e

Please sign in to comment.