diff --git a/internal/module/module.go b/internal/module/module.go index 94a860e3..38916b21 100644 --- a/internal/module/module.go +++ b/internal/module/module.go @@ -311,7 +311,6 @@ func mapModuleRules(linterSettings *pkg.LintersSettings, configSettings *config. rules.LicenseRule.SetLevel(globalRules.LicenseRule.Impact, fallbackImpact) rules.RequarementsRule.SetLevel(globalRules.RequarementsRule.Impact, fallbackImpact) rules.LegacyReleaseFileRule.SetLevel(globalRules.LegacyReleaseFileRule.Impact, fallbackImpact) - rules.ChangelogRule.SetLevel(globalRules.ChangelogRule.Impact, fallbackImpact) } // mapTemplatesRules configures Templates linter rules diff --git a/pkg/config.go b/pkg/config.go index 2f55fa35..b5eabb16 100644 --- a/pkg/config.go +++ b/pkg/config.go @@ -220,7 +220,6 @@ type ModuleLinterRules struct { LicenseRule RuleConfig RequarementsRule RuleConfig LegacyReleaseFileRule RuleConfig - ChangelogRule RuleConfig } type OSSRuleSettings struct { Disable bool diff --git a/pkg/config/global/global.go b/pkg/config/global/global.go index aa9242f9..3775b9cd 100644 --- a/pkg/config/global/global.go +++ b/pkg/config/global/global.go @@ -109,7 +109,6 @@ type ModuleLinterRules struct { LicenseRule RuleConfig `mapstructure:"license"` RequarementsRule RuleConfig `mapstructure:"requarements"` LegacyReleaseFileRule RuleConfig `mapstructure:"legacy-release-file"` - ChangelogRule RuleConfig `mapstructure:"changelog"` } type TemplatesLinterConfig struct { diff --git a/pkg/linters/module/README.md b/pkg/linters/module/README.md index bfdc5317..582ea30a 100644 --- a/pkg/linters/module/README.md +++ b/pkg/linters/module/README.md @@ -8,7 +8,7 @@ The Module linter performs automated checks on Deckhouse modules to validate con ## Rules -The Module linter includes **8 validation rules**: +The Module linter includes **7 validation rules**: | Rule | Description | Configurable | |------|-------------|--------------| @@ -19,7 +19,6 @@ The Module linter includes **8 validation rules**: | [**license**](#license) | Validates license headers in source files | ✅ Yes | | [**requirements**](#requirements) | Validates version requirements for features | ❌ No | | [**legacy-release-file**](#legacy-release-file) | Checks for deprecated `release.yaml` file | ❌ No | -| [**changelog**](#changelog) | Validates changelog file presence and content | ❌ No | --- @@ -531,52 +530,3 @@ update: - from: "1.17" to: "1.20" ``` - ---- - -### Changelog - -Validates changelog.yaml file presence and content in modules. - -**Purpose:** Ensures modules have a changelog file that documents changes and version history. This maintains transparency about module evolution and helps users understand what changes are included in each version. - -**Checks:** -- ✅ `changelog.yaml` file must exist in module root -- ✅ File must not be empty (size > 0 bytes) - -**Validation Logic:** -- File `changelog.yaml` is required in the module root directory -- File must contain content (not be empty) -- Missing or empty files generate appropriate error messages - -**Examples:** - -```yaml -# changelog.yaml - Valid changelog ---- -features: - Linting: - Module: - - Added new changelog validation rule to ensure proper changelog format - - Enhanced module YAML file checking with additional validation rules - - Improved license checking functionality with better error reporting - - Added support for restricting UpdateMode to Auto in module configurations -fixes: - Linting: - Module: - - Fixed install output formatting issues - - Corrected changelog rule validation logic - - Resolved false positives in module YAML validation -chore: - Dependencies: - - Updated helm.sh/helm/v3 dependency from 3.18.4 to 3.18.5 - Linting: - - Refactored changelog validation code for better maintainability - -``` - -**Error Examples:** -``` -❌ changelog.yaml file is missing -❌ changelog.yaml file is empty -``` diff --git a/pkg/linters/module/module.go b/pkg/linters/module/module.go index 98947320..17ac7df9 100644 --- a/pkg/linters/module/module.go +++ b/pkg/linters/module/module.go @@ -56,7 +56,6 @@ func (l *Module) Run(m *module.Module) { CheckFiles(m, errorList.WithMaxLevel(l.cfg.Rules.LicenseRule.GetLevel())) rules.NewRequirementsRule().CheckRequirements(m.GetPath(), errorList.WithMaxLevel(l.cfg.Rules.RequarementsRule.GetLevel())) rules.NewLegacyReleaseFileRule().CheckLegacyReleaseFile(m.GetPath(), errorList.WithMaxLevel(l.cfg.Rules.LegacyReleaseFileRule.GetLevel())) - rules.NewChangelogRule().CheckChangelog(m.GetPath(), errorList.WithMaxLevel(l.cfg.Rules.ChangelogRule.GetLevel())) } func (l *Module) Name() string { diff --git a/pkg/linters/module/rules/changelog.go b/pkg/linters/module/rules/changelog.go deleted file mode 100644 index 995ac4e5..00000000 --- a/pkg/linters/module/rules/changelog.go +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright 2025 Flant JSC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package rules - -import ( - errs "errors" - "fmt" - "os" - "path/filepath" - - "github.com/deckhouse/dmt/pkg" - "github.com/deckhouse/dmt/pkg/errors" -) - -const ( - ChangelogRuleName = "changelog" - changelogFilename = "changelog.yaml" -) - -func NewChangelogRule() *ChangelogRule { - return &ChangelogRule{ - RuleMeta: pkg.RuleMeta{ - Name: ChangelogRuleName, - }, - } -} - -type ChangelogRule struct { - pkg.RuleMeta -} - -func (r *ChangelogRule) CheckChangelog(modulePath string, errorList *errors.LintRuleErrorsList) { - errorList = errorList.WithRule(r.GetName()) - - changelogPath := filepath.Join(modulePath, changelogFilename) - err := checkFile(changelogPath) - if err != nil { - errorList.WithFilePath(changelogFilename).Error(err.Error()) - } -} - -func checkFile(filePath string) error { - stat, err := os.Stat(filePath) - if errs.Is(err, os.ErrNotExist) { - return fmt.Errorf("changelog.yaml file does not exist: %w", err) - } - if err != nil { - return fmt.Errorf("failed to stat changelog.yaml file: %w", err) - } - if stat.Size() == 0 { - return fmt.Errorf("changelog.yaml file is empty") - } - - return nil -} diff --git a/pkg/linters/module/rules/changelog_test.go b/pkg/linters/module/rules/changelog_test.go deleted file mode 100644 index aea303a2..00000000 --- a/pkg/linters/module/rules/changelog_test.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2025 Flant JSC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package rules - -import ( - "os" - "path/filepath" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/deckhouse/dmt/pkg/errors" -) - -func TestChangelogRule_CheckChangelog(t *testing.T) { - tests := []struct { - name string - fileContent string - createFile bool - expectErrors int - }{ - { - name: "changelog.yaml file missing", - createFile: false, - expectErrors: 1, - }, - { - name: "changelog.yaml file empty", - fileContent: "", - createFile: true, - expectErrors: 1, - }, - { - name: "changelog.yaml file present and non-empty", - fileContent: "# Changelog\n\n## v1.0.0\n- Initial release", - createFile: true, - expectErrors: 0, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tempDir := t.TempDir() - if tt.createFile { - err := os.WriteFile(filepath.Join(tempDir, changelogFilename), []byte(tt.fileContent), 0600) - require.NoError(t, err) - } - - rule := NewChangelogRule() - errorList := errors.NewLintRuleErrorsList() - - rule.CheckChangelog(tempDir, errorList) - - if tt.expectErrors > 0 { - assert.True(t, errorList.ContainsErrors(), "Expected errors but got none") - assert.Len(t, errorList.GetErrors(), tt.expectErrors) - } else { - assert.False(t, errorList.ContainsErrors(), "Expected no errors but got some") - } - }) - } -}