-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update main.go to call the cobra file
- Loading branch information
Showing
1 changed file
with
17 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,25 @@ | ||
package main | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
"sigs.k8s.io/yaml" | ||
) | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
// validateYAML reads and parses the YAML file at the given path. | ||
func validateYAML(filePath string) string { | ||
data, err := os.ReadFile(filePath) | ||
if err != nil { | ||
return fmt.Sprintf("Error reading %s:\n%s", filePath, err.Error()) | ||
} | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
var content interface{} | ||
if err := yaml.UnmarshalStrict(data, &content); err != nil { | ||
return fmt.Sprintf("Error in %s:\n%w", filePath, err.Error()) | ||
} | ||
package main | ||
|
||
return "Valid" | ||
} | ||
import ( | ||
"k8s.io/release/cmd/publish-release/cmd" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
fmt.Println("No YAML files specified.") | ||
os.Exit(1) | ||
} | ||
|
||
files := os.Args[1:] | ||
invalidFiles := []string{} | ||
|
||
for _, file := range files { | ||
result := validateYAML(file) | ||
if result != "Valid" { | ||
invalidFiles = append(invalidFiles, result) | ||
} | ||
} | ||
|
||
if len(invalidFiles) > 0 { | ||
fmt.Println("YAML Validation Failed:\n") | ||
for _, errorMsg := range invalidFiles { | ||
fmt.Println(errorMsg) | ||
fmt.Println("\n" + strings.Repeat("-", 40) + "\n") | ||
} | ||
} else { | ||
fmt.Println("All YAML files are valid 🎉.") | ||
} | ||
cmd.Execute() | ||
} |