...

Source file src/sigs.k8s.io/release-utils/magefile.go

Documentation: sigs.k8s.io/release-utils

     1  //go:build mage
     2  // +build mage
     3  
     4  /*
     5  Copyright 2021 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package main
    21  
    22  import (
    23  	"fmt"
    24  	"path/filepath"
    25  
    26  	"sigs.k8s.io/release-utils/mage"
    27  )
    28  
    29  // Default target to run when none is specified
    30  // If not set, running mage will list available targets
    31  var Default = Verify
    32  
    33  const (
    34  	binDir    = "bin"
    35  	scriptDir = "scripts"
    36  )
    37  
    38  var boilerplateDir = filepath.Join(scriptDir, "boilerplate")
    39  
    40  // All runs all targets for this repository
    41  func All() error {
    42  	if err := Verify(); err != nil {
    43  		return err
    44  	}
    45  
    46  	if err := Test(); err != nil {
    47  		return err
    48  	}
    49  
    50  	return nil
    51  }
    52  
    53  // Test runs various test functions
    54  func Test() error {
    55  	if err := mage.TestGo(true); err != nil {
    56  		return err
    57  	}
    58  
    59  	return nil
    60  }
    61  
    62  // Verify runs repository verification scripts
    63  func Verify() error {
    64  	fmt.Println("Running copyright header checks...")
    65  	if err := mage.VerifyBoilerplate("", binDir, boilerplateDir, true); err != nil {
    66  		return err
    67  	}
    68  
    69  	fmt.Println("Running external dependency checks...")
    70  	if err := mage.VerifyDeps("", "", "", true); err != nil {
    71  		return err
    72  	}
    73  
    74  	fmt.Println("Running go module linter...")
    75  	if err := mage.VerifyGoMod(); err != nil {
    76  		return err
    77  	}
    78  
    79  	fmt.Println("Running golangci-lint...")
    80  	if err := mage.RunGolangCILint("", false); err != nil {
    81  		return err
    82  	}
    83  
    84  	fmt.Println("Running go build...")
    85  	if err := mage.VerifyBuild(scriptDir); err != nil {
    86  		return err
    87  	}
    88  
    89  	return nil
    90  }
    91  

View as plain text