mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-07 20:00:07 +00:00
tests: move github-labels to main repo
Move tool as part of static checks migration. Fixes #8187 Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com> Signed-off-by: Derek Lee <derlee@redhat.com> Signed-off-by: Gabriela Cervantes <gabriela.cervantes.tellez@intel.com> Signed-off-by: Graham Whaley <graham.whaley@intel.com> Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com> Signed-off-by: Marco Vedovati <mvedovati@suse.com> Signed-off-by: Peng Tao <bergwolf@hyper.sh> Signed-off-by: Shiming Zhang <wzshiming@foxmail.com> Signed-off-by: Snir Sheriber <ssheribe@redhat.com> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
This commit is contained in:
72
tests/cmd/github-labels/yaml.go
Normal file
72
tests/cmd/github-labels/yaml.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright (c) 2019 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const fileMode os.FileMode = 0600
|
||||
|
||||
func readYAML(file string) (*LabelsFile, error) {
|
||||
bytes, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lf := LabelsFile{}
|
||||
|
||||
err = yaml.Unmarshal(bytes, &lf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Sort(lf.Labels)
|
||||
sort.Sort(lf.Categories)
|
||||
|
||||
clean(&lf)
|
||||
|
||||
err = check(&lf)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("file was not in expected format: %v", err)
|
||||
}
|
||||
|
||||
return &lf, nil
|
||||
}
|
||||
|
||||
func writeYAML(lf *LabelsFile, file string) error {
|
||||
bytes, err := yaml.Marshal(lf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.WriteFile(file, bytes, fileMode)
|
||||
}
|
||||
|
||||
func checkYAML(file string) error {
|
||||
// read and check
|
||||
_, err := readYAML(file)
|
||||
|
||||
if err == nil {
|
||||
fmt.Printf("Checked file %v\n", file)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func sortYAML(fromFile, toFile string) error {
|
||||
// read and sort
|
||||
lf, err := readYAML(fromFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return writeYAML(lf, toFile)
|
||||
}
|
Reference in New Issue
Block a user