...

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

Documentation: sigs.k8s.io/release-utils/mage

     1  /*
     2  Copyright 2021 The Kubernetes 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 mage
    18  
    19  import (
    20  	"fmt"
    21  	"log"
    22  
    23  	"github.com/blang/semver/v4"
    24  	"github.com/uwu-tools/magex/pkg"
    25  	"github.com/uwu-tools/magex/shx"
    26  )
    27  
    28  const (
    29  	// zeitgeist
    30  	defaultZeitgeistVersion = "v0.4.3"
    31  	zeitgeistCmd            = "zeitgeist"
    32  	zeitgeistModule         = "sigs.k8s.io/zeitgeist"
    33  )
    34  
    35  // Ensure zeitgeist is installed and on the PATH.
    36  func EnsureZeitgeist(version string) error {
    37  	if version == "" {
    38  		log.Printf(
    39  			"A zeitgeist version to install was not specified. Using default version: %s",
    40  			defaultZeitgeistVersion,
    41  		)
    42  
    43  		version = defaultZeitgeistVersion
    44  	}
    45  
    46  	if _, err := semver.ParseTolerant(version); err != nil {
    47  		return fmt.Errorf(
    48  			"%s was not SemVer-compliant, cannot continue: %w",
    49  			version, err,
    50  		)
    51  	}
    52  
    53  	if err := pkg.EnsurePackageWith(pkg.EnsurePackageOptions{
    54  		Name:           zeitgeistModule,
    55  		DefaultVersion: version,
    56  		VersionCommand: "version",
    57  	}); err != nil {
    58  		return fmt.Errorf("ensuring package: %w", err)
    59  	}
    60  
    61  	return nil
    62  }
    63  
    64  // VerifyDeps runs zeitgeist to verify dependency versions
    65  func VerifyDeps(version, basePath, configPath string, localOnly bool) error {
    66  	if err := EnsureZeitgeist(version); err != nil {
    67  		return fmt.Errorf("ensuring zeitgeist is installed: %w", err)
    68  	}
    69  
    70  	args := []string{"validate"}
    71  	if localOnly {
    72  		args = append(args, "--local-only")
    73  	}
    74  
    75  	if basePath != "" {
    76  		args = append(args, "--base-path", basePath)
    77  	}
    78  
    79  	if configPath != "" {
    80  		args = append(args, "--config", configPath)
    81  	}
    82  
    83  	if err := shx.RunV(zeitgeistCmd, args...); err != nil {
    84  		return fmt.Errorf("running zeitgeist: %w", err)
    85  	}
    86  
    87  	return nil
    88  }
    89  
    90  /*
    91  ##@ Dependencies
    92  
    93  .SILENT: update-deps update-deps-go update-mocks
    94  .PHONY:  update-deps update-deps-go update-mocks
    95  
    96  update-deps: update-deps-go ## Update all dependencies for this repo
    97  	echo -e "${COLOR}Commit/PR the following changes:${NOCOLOR}"
    98  	git status --short
    99  
   100  update-deps-go: GO111MODULE=on
   101  update-deps-go: ## Update all golang dependencies for this repo
   102  	go get -u -t ./...
   103  	go mod tidy
   104  	go mod verify
   105  	$(MAKE) test-go-unit
   106  	./scripts/update-all.sh
   107  
   108  update-mocks: ## Update all generated mocks
   109  	go generate ./...
   110  	for f in $(shell find . -name fake_*.go); do \
   111  		cp scripts/boilerplate/boilerplate.generatego.txt tmp ;\
   112  		cat $$f >> tmp ;\
   113  		mv tmp $$f ;\
   114  	done
   115  */
   116  

View as plain text