Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) charts-build-scripts linter settings #189

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Install golint
run: go install golang.org/x/lint/golint@latest
- name: Run golint
run: golint ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version : v1.62

build:
runs-on: ubuntu-latest
Expand Down
11 changes: 7 additions & 4 deletions .golangci.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
]
},
"run": {
"skip-files": [
"/zz_generated_"
],
"deadline": "5m"
"issues" : {
"skip-files" : [
"/zz_generated_"

]
},
"timeout": "5m"
}
}
161 changes: 13 additions & 148 deletions go.mod

Large diffs are not rendered by default.

627 changes: 2 additions & 625 deletions go.sum

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func main() {
}
}

func listPackages(c *cli.Context) {
func listPackages(_ *cli.Context) {
repoRoot := getRepoRoot()
packageList, err := charts.ListPackages(repoRoot, CurrentPackage)
if err != nil {
Expand All @@ -434,7 +434,7 @@ func listPackages(c *cli.Context) {
logrus.Infof("Found the following packages: %v", packageList)
}

func prepareCharts(c *cli.Context) {
func prepareCharts(_ *cli.Context) {
util.SetSoftErrorMode(SoftErrorMode)
packages := getPackages()
if len(packages) == 0 {
Expand All @@ -447,7 +447,7 @@ func prepareCharts(c *cli.Context) {
}
}

func generatePatch(c *cli.Context) {
func generatePatch(_ *cli.Context) {
packages := getPackages()
if len(packages) == 0 {
logrus.Infof("No packages found.")
Expand All @@ -468,7 +468,7 @@ func generatePatch(c *cli.Context) {
}
}

func generateCharts(c *cli.Context) {
func generateCharts(_ *cli.Context) {
packages := getPackages()
if len(packages) == 0 {
logrus.Infof("No packages found.")
Expand All @@ -484,7 +484,7 @@ func generateCharts(c *cli.Context) {
}
}

func downloadIcon(c *cli.Context) {
func downloadIcon(_ *cli.Context) {
packages := getPackages()
if len(packages) == 0 {
logrus.Infof("No packages found.")
Expand All @@ -498,13 +498,13 @@ func downloadIcon(c *cli.Context) {
}
}

func generateRegSyncConfigFile(c *cli.Context) {
func generateRegSyncConfigFile(_ *cli.Context) {
if err := regsync.GenerateConfigFile(); err != nil {
logrus.Fatal(err)
}
}

func createOrUpdateIndex(c *cli.Context) {
func createOrUpdateIndex(_ *cli.Context) {
repoRoot := getRepoRoot()
if err := helm.CreateOrUpdateHelmIndex(filesystem.GetFilesystem(repoRoot)); err != nil {
logrus.Fatal(err)
Expand All @@ -527,7 +527,7 @@ func unzipAssets(c *cli.Context) {
createOrUpdateIndex(c)
}

func cleanRepo(c *cli.Context) {
func cleanRepo(_ *cli.Context) {
packages := getPackages()
if len(packages) == 0 {
logrus.Infof("No packages found.")
Expand Down Expand Up @@ -615,15 +615,15 @@ func validateRepo(c *cli.Context) {
logrus.Info("Successfully validated current repository!")
}

func standardizeRepo(c *cli.Context) {
func standardizeRepo(_ *cli.Context) {
repoRoot := getRepoRoot()
repoFs := filesystem.GetFilesystem(repoRoot)
if err := standardize.RestructureChartsAndAssets(repoFs); err != nil {
logrus.Fatal(err)
}
}

func createOrUpdateTemplate(c *cli.Context) {
func createOrUpdateTemplate(_ *cli.Context) {
repoRoot := getRepoRoot()
repoFs := filesystem.GetFilesystem(repoRoot)
chartsScriptOptions := parseScriptOptions()
Expand All @@ -633,11 +633,11 @@ func createOrUpdateTemplate(c *cli.Context) {
logrus.Infof("Successfully updated repository based on upstream template.")
}

func setupCache(c *cli.Context) error {
func setupCache(_ *cli.Context) error {
return puller.InitRootCache(CacheMode, path.DefaultCachePath)
}

func cleanCache(c *cli.Context) {
func cleanCache(_ *cli.Context) {
if err := puller.CleanRootCache(path.DefaultCachePath); err != nil {
logrus.Fatal(err)
}
Expand Down Expand Up @@ -690,13 +690,13 @@ func getGitInfo() (*git.Repository, *git.Worktree, git.Status) {
return repo, wt, status
}

func checkImages(c *cli.Context) {
func checkImages(_ *cli.Context) {
if err := images.CheckImages(); err != nil {
logrus.Fatal(err)
}
}

func checkRCTagsAndVersions(c *cli.Context) {
func checkRCTagsAndVersions(_ *cli.Context) {
// Grab all images that contain RC tags
rcImageTagMap := images.CheckRCTags()

Expand Down Expand Up @@ -808,7 +808,7 @@ func release(c *cli.Context) {
createOrUpdateIndex(c)
}

func validateRelease(c *cli.Context) {
func validateRelease(_ *cli.Context) {
if Skip {
fmt.Println("skipping execution...")
return
Expand Down Expand Up @@ -845,7 +845,7 @@ func validateRelease(c *cli.Context) {
}
}

func compareIndexFiles(c *cli.Context) {
func compareIndexFiles(_ *cli.Context) {
if Branch == "" {
fmt.Println("BRANCH environment variable must be set to run validate-release-charts")
os.Exit(1)
Expand All @@ -860,7 +860,7 @@ func compareIndexFiles(c *cli.Context) {
fmt.Println("index.yaml files are the same at git repository and charts.rancher.io")
}

func chartBump(c *cli.Context) {
func chartBump(_ *cli.Context) {
if CurrentPackage == "" {
fmt.Println("CurrentPackage environment variable must be set")
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions pkg/auto/chart_bump_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Test_calculateNextVersion(t *testing.T) {
}

buildInputBump := func(latestVersion string, toReleaseVersion string) *Bump {
var toReleaseVersionPtr *string = &toReleaseVersion
var toReleaseVersionPtr = &toReleaseVersion

return &Bump{
targetChart: "rancher-chart",
Expand All @@ -102,7 +102,7 @@ func Test_calculateNextVersion(t *testing.T) {

buildExpectedBump := func(latest, latestRepoPrefix, toRelease, toReleaseRepoPrefix string) *Bump {
var (
toReleaseVersionPtr *string = &toRelease
toReleaseVersionPtr = &toRelease
targetVersion string
targetSemver semver.Version
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/auto/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const owner = "rancher"
const repo = "charts"

var (
errReleaseYaml error = errors.New("release.yaml errors")
errModifiedChart error = errors.New("released chart cannot be modified")
errMinorPatchVersion error = errors.New("chart version must be exactly 1 more patch/minor version than the previous chart version")
errReleaseYaml = errors.New("release.yaml errors")
errModifiedChart = errors.New("released chart cannot be modified")
errMinorPatchVersion = errors.New("chart version must be exactly 1 more patch/minor version than the previous chart version")
)

// validation struct will hold the pull request and its files to be validated.
Expand Down
16 changes: 8 additions & 8 deletions pkg/auto/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Test_validateReleaseYaml(t *testing.T) {
},
dep: &lifecycle.Dependencies{
AssetsVersionsMap: map[string][]lifecycle.Asset{
"chart-1": []lifecycle.Asset{
"chart-1": {
{
Version: "104.0.1",
},
Expand Down Expand Up @@ -136,12 +136,12 @@ func Test_validateReleaseYaml(t *testing.T) {
},
dep: &lifecycle.Dependencies{
AssetsVersionsMap: map[string][]lifecycle.Asset{
"chart-1": []lifecycle.Asset{
"chart-1": {
{
Version: "104.0.0",
},
},
"chart-2": []lifecycle.Asset{
"chart-2": {
{
Version: "104.0.0",
},
Expand Down Expand Up @@ -180,7 +180,7 @@ func Test_validateReleaseYaml(t *testing.T) {
},
dep: &lifecycle.Dependencies{
AssetsVersionsMap: map[string][]lifecycle.Asset{
"chart-1": []lifecycle.Asset{
"chart-1": {
{
Version: "104.0.0",
},
Expand Down Expand Up @@ -226,12 +226,12 @@ func Test_validateReleaseYaml(t *testing.T) {
},
dep: &lifecycle.Dependencies{
AssetsVersionsMap: map[string][]lifecycle.Asset{
"chart-1": []lifecycle.Asset{
"chart-1": {
{
Version: "104.0.0",
},
},
"chart-2": []lifecycle.Asset{
"chart-2": {
{
Version: "104.0.0",
},
Expand Down Expand Up @@ -277,12 +277,12 @@ func Test_validateReleaseYaml(t *testing.T) {
},
dep: &lifecycle.Dependencies{
AssetsVersionsMap: map[string][]lifecycle.Asset{
"chart-1": []lifecycle.Asset{
"chart-1": {
{
Version: "104.0.0",
},
},
"chart-2": []lifecycle.Asset{
"chart-2": {
{
Version: "104.0.0",
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/charts/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func PrepareDependencies(rootFs, pkgFs billy.Filesystem, mainHelmChartPath strin
}
continue
}
if filesystem.RemoveAll(dependencyFs, dependency.WorkingDir); err != nil {
if err := filesystem.RemoveAll(dependencyFs, dependency.WorkingDir); err != nil {
return err
}
if err := dependency.Upstream.Pull(rootFs, dependencyFs, dependency.WorkingDir); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/charts/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func ListPackages(repoRoot string, specificPackage string) ([]string, error) {
return packageList, err
}

listPackages := func(fs billy.Filesystem, dirPath string, isDir bool) error {
listPackages := func(_ billy.Filesystem, dirPath string, isDir bool) error {
if !isDir {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/charts/puller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (u LocalPackage) String() string {
type Local struct{}

// Pull grabs the Helm chart by preparing the package itself
func (u Local) Pull(rootFs, fs billy.Filesystem, path string) error {
func (u Local) Pull(_, _ billy.Filesystem, _ string) error {
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"compress/gzip"
"crypto/sha1"
"fmt"
"github.com/rancher/charts-build-scripts/pkg/util"
"io"
"io/ioutil"
"net/http"
Expand All @@ -15,6 +14,8 @@ import (
"sort"
"strings"

"github.com/rancher/charts-build-scripts/pkg/util"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs"
"github.com/sirupsen/logrus"
Expand Down
12 changes: 6 additions & 6 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ func CreateOrUpdateHelmIndex(rootFs billy.Filesystem) error {
}

// UpdateIndex updates the original index with the new contents
func UpdateIndex(original, new *helmRepo.IndexFile) (*helmRepo.IndexFile, bool) {
func UpdateIndex(origRepo, newRepo *helmRepo.IndexFile) (*helmRepo.IndexFile, bool) {
// Create a copy of new to return
updatedIndex := helmRepo.NewIndexFile()
updatedIndex.Merge(new)
updatedIndex.Merge(newRepo)
upToDate := true

// Preserve generated timestamp
updatedIndex.Generated = original.Generated
updatedIndex.Generated = origRepo.Generated

// Ensure newer version of chart is used if it has been updated
for chartName, chartVersions := range updatedIndex.Entries {
for i, chartVersion := range chartVersions {
version := chartVersion.Version
if !original.Has(chartName, version) {
if !origRepo.Has(chartName, version) {
// Keep the newly generated chart version as-is
upToDate = false
logrus.Debugf("Chart %s has introduced a new version %s: %v", chartName, chartVersion.Version, *chartVersion)
continue
}
// Get original chart version
var originalChartVersion *helmRepo.ChartVersion
for _, originalChartVersion = range original.Entries[chartName] {
for _, originalChartVersion = range origRepo.Entries[chartName] {
if originalChartVersion.Version == chartVersion.Version {
// found originalChartVersion, which must exist since we checked that the original has it
break
Expand All @@ -94,7 +94,7 @@ func UpdateIndex(original, new *helmRepo.IndexFile) (*helmRepo.IndexFile, bool)
}
}

for chartName, chartVersions := range original.Entries {
for chartName, chartVersions := range origRepo.Entries {
for _, chartVersion := range chartVersions {
if !updatedIndex.Has(chartName, chartVersion.Version) {
// Chart was removed
Expand Down
2 changes: 1 addition & 1 deletion pkg/lifecycle/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (ld *Dependencies) populateAssetsVersionsPath() error {
// during its traversal of the directory specified by dirPath
// All results will be appended fo filePaths
var filePaths []string
doFunc := func(fs billy.Filesystem, path string, isDir bool) error {
doFunc := func(_ billy.Filesystem, path string, isDir bool) error {
if !isDir {
filePaths = append(filePaths, path)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/lifecycle/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Test_populateAssetsVersionsPath(t *testing.T) {
{Version: "1.0.0"},
},
},
walkDirWrapper: func(fs billy.Filesystem, dirPath string, doFunc filesystem.RelativePathFunc) error {
walkDirWrapper: func(_ billy.Filesystem, dirPath string, doFunc filesystem.RelativePathFunc) error {
// Simulate the behavior of filesystem.WalkDir as needed for your test.
if dirPath == "assets/chart1" {
doFunc(nil, "assets/chart1/chart1-1.0.0.tgz", false)
Expand Down Expand Up @@ -94,7 +94,7 @@ func Test_populateAssetsVersionsPath(t *testing.T) {
{Version: "1.0.0"},
},
},
walkDirWrapper: func(fs billy.Filesystem, dirPath string, doFunc filesystem.RelativePathFunc) error {
walkDirWrapper: func(_ billy.Filesystem, _ string, doFunc filesystem.RelativePathFunc) error {
doFunc(nil, "", false)
return fmt.Errorf("Some random error")
},
Expand Down
Loading