Skip to content

Commit

Permalink
new validate status changes logic
Browse files Browse the repository at this point in the history
- added exceptions for faulty old versions

These versions only have released .orig files on the final product.
That does not break anything but the .orig files are development files
used during chart bumps.
  • Loading branch information
nicholasSUSE committed Feb 24, 2025
1 parent 26c0f27 commit 245c016
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions pkg/validate/validate.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package validate

import (
"errors"
"fmt"
"path/filepath"
"strings"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-git/v5"
"github.com/rancher/charts-build-scripts/pkg/filesystem"
bashGit "github.com/rancher/charts-build-scripts/pkg/git"
"github.com/rancher/charts-build-scripts/pkg/lifecycle"
"github.com/rancher/charts-build-scripts/pkg/options"
"github.com/rancher/charts-build-scripts/pkg/path"
Expand Down Expand Up @@ -212,3 +215,56 @@ func copyAndUnzip(repoFs billy.Filesystem, upstreamPath, localPath string) error
}
return nil
}

// StatusExceptions checks if the git repository is clean and if it is not, it checks if the changes are allowed
func StatusExceptions(status git.Status) error {
if !status.IsClean() {
if err := validateExceptions(status); err != nil {
logrus.Errorf("git is not clean: %s\n", err.Error())
logrus.Errorf("status:\n%s\n", status)
return errors.New("Repository must be clean to run validation")
}

g, err := bashGit.OpenGitRepo(".")
if err != nil {
return err
}
if err := g.FullReset(); err != nil {
return err
}
}

return nil
}

// validateExceptions checks if the changes are allowed
func validateExceptions(status git.Status) error {
/**
* The following exceptions are allowed to be modified, they were wrongly released with .orig files on the final production version.
* This does not break anything and it is not allowed to modify already released charts.
*/
exceptions := map[string][]string{
"rancher-istio": {"105.4.0+up1.23.2"},
"prometheus-federator": {"103.0.0+up0.4.0", "103.0.1+up0.4.1", "104.0.0+up0.4.0"},
}

for changedFile, _ := range status {

Check failure on line 251 in pkg/validate/validate.go

View workflow job for this annotation

GitHub Actions / lint

should omit 2nd value from range; this loop is equivalent to `for changedFile := range ...`
if changedFile == "index.yaml" {
continue
}

for exceptionChart, exceptionVersions := range exceptions {
if !strings.Contains(changedFile, exceptionChart) {
continue
}

for _, exceptionVersion := range exceptionVersions {
if !strings.Contains(changedFile, exceptionVersion) {
return fmt.Errorf("chart: %s - version: %s is not allowed to be modified", exceptionChart, exceptionVersion)
}
}
}
}

return nil
}

0 comments on commit 245c016

Please sign in to comment.