Skip to content

Commit

Permalink
Fix: fix filepath for windows
Browse files Browse the repository at this point in the history
Signed-off-by: FogDong <[email protected]>
  • Loading branch information
FogDong committed Nov 2, 2022
1 parent 6a5c9d7 commit 4880769
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 4880769

Please sign in to comment.