diff --git a/.changes/unreleased/fixed-20240908-004631.yaml b/.changes/unreleased/fixed-20240908-004631.yaml new file mode 100644 index 00000000..a061d232 --- /dev/null +++ b/.changes/unreleased/fixed-20240908-004631.yaml @@ -0,0 +1,5 @@ +kind: fixed +body: Validate kinds match config in fragment when batching release notes +time: 2024-09-08T00:46:31.38990871-07:00 +custom: + Issue: "688" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ef0be729..8f70d57b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,6 +48,9 @@ jobs: - name: Test run: go test -coverprofile=c.out ./... + - name: Validate Changie fragments + run: go run main.go batch major --dry-run + - name: Coverage uses: codacy/codacy-coverage-reporter-action@v1 with: diff --git a/core/utils.go b/core/utils.go index b20eecc6..3b42641a 100644 --- a/core/utils.go +++ b/core/utils.go @@ -28,6 +28,7 @@ var ( ErrBadVersionOrPart = errors.New("part string is not a supported version or version increment") ErrMissingAutoLevel = errors.New("kind config missing auto level value for auto bumping") ErrNoChangesFoundForAuto = errors.New("no unreleased changes found for automatic bumping") + ErrKindNotFound = errors.New("kind not found but configuration expects one") ) var ( @@ -310,6 +311,8 @@ func GetChanges( kc := cfg.KindFromKeyOrLabel(c.KindKey) if kc != nil { c.KindLabel = kc.Label + } else if len(cfg.Kinds) > 0 { + return nil, fmt.Errorf("%w: '%s'", ErrKindNotFound, c.KindKey) } changes = append(changes, c) diff --git a/core/utils_test.go b/core/utils_test.go index 6d38c402..34e8a181 100644 --- a/core/utils_test.go +++ b/core/utils_test.go @@ -631,6 +631,27 @@ func TestGetAllChanges(t *testing.T) { then.Equals(t, "third", changes[2].Body) } +func TestGetAllChangesErrorIfNoKindWhenConfigured(t *testing.T) { + then.WithTempDir(t) + + cfg := utilsTestConfig() + orderedTimes := []time.Time{ + time.Date(2019, 5, 25, 20, 45, 0, 0, time.UTC), + } + + changes := []Change{ + {Kind: "added not found", Body: "ignored", Time: orderedTimes[0]}, + } + for i, c := range changes { + then.WriteFileTo(t, c, cfg.ChangesDir, cfg.UnreleasedDir, fmt.Sprintf("%d.yaml", i)) + } + + then.CreateFile(t, cfg.ChangesDir, cfg.UnreleasedDir, "ignored.txt") + + _, err := GetChanges(cfg, nil, "") + then.Err(t, ErrKindNotFound, err) +} + func TestGetAllChangesWithProject(t *testing.T) { then.WithTempDir(t) diff --git a/docs/integrations/ci.md b/docs/integrations/ci.md new file mode 100644 index 00000000..ec1ffc79 --- /dev/null +++ b/docs/integrations/ci.md @@ -0,0 +1,26 @@ +When creating changie fragments as part of your team workflow, you may have +suggestions or comments about the kind, body or custom fields that are +changed outside of the changie tool. +As changie fragments are plain yaml files there is nothing wrong with editing +these after creating the fragment. +However, it is possible to create invalid fragments when doing so, +one such example is if you typo a kind or invalid custom prompt answer. + +One way to prevent this issue from causing later problems is to run +changie as part of your CI tests. + +This currently does not validate custom prompts meet validation rules such as min length. +This is likely to be extended in the future. + +Below is an example if you are using the github action. + +```yaml +- name: Validate changie fragment is valid + uses: miniscruff/changie-action@VERSION # view action repo for latest version + with: + version: latest # use the latest changie version + # dry run may not be required as you likely aren't + # committing the changes anyway, but it will print + # to stdout this way + args: batch major --dry-run +``` diff --git a/mkdocs.yml b/mkdocs.yml index 3aa072ac..0f399a08 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -98,6 +98,7 @@ nav: - Goreleaser: integrations/goreleaser.md - Release Trigger: integrations/release_trigger.md - yq: integrations/yq.md + - Continuous Integration: integrations/ci.md - Config: - config/index.md - CLI: