vitess.io/vitess@v0.16.2/go/tools/ci-config/main.go (about)

     1  /*
     2  Copyright 2022 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"encoding/json"
    21  	"fmt"
    22  	"log"
    23  	"os"
    24  	"strings"
    25  )
    26  
    27  type Test struct {
    28  	Args []string
    29  }
    30  
    31  type Config struct {
    32  	Tests map[string]*Test
    33  }
    34  
    35  func main() {
    36  	content, err := os.ReadFile("./test/config.json")
    37  	if err != nil {
    38  		log.Fatal(err)
    39  	}
    40  
    41  	tests := &Config{}
    42  	err = json.Unmarshal(content, tests)
    43  	if err != nil {
    44  		log.Fatal(err)
    45  	}
    46  
    47  	var failedConfig []string
    48  	for name, test := range tests.Tests {
    49  		if len(test.Args) == 0 {
    50  			continue
    51  		}
    52  		path := test.Args[0]
    53  		if !strings.HasPrefix(path, "vitess.io/vitess/") {
    54  			continue
    55  		}
    56  		path = path[len("vitess.io/vitess/"):]
    57  
    58  		stat, err := os.Stat(path)
    59  		if err != nil || !stat.IsDir() {
    60  			failedConfig = append(failedConfig, fmt.Sprintf("%s: %s", name, path))
    61  			continue
    62  		}
    63  	}
    64  
    65  	if len(failedConfig) > 0 {
    66  		fmt.Println("Some packages in test/config.json were not found in the codebase:")
    67  		for _, failed := range failedConfig {
    68  			fmt.Println("\t" + failed)
    69  		}
    70  		fmt.Println("\nYou must remove them from test/config.json to avoid unnecessary CI load.")
    71  		os.Exit(1)
    72  	}
    73  	fmt.Println("The file: test/config.json is clean.")
    74  }