Skip to content

Commit

Permalink
Validate kinds match config in fragment when batching release notes (#…
Browse files Browse the repository at this point in the history
…711)

* Add changie fragment checks in CI
  • Loading branch information
miniscruff authored Sep 8, 2024
1 parent 49bf31d commit fcad6bc
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/fixed-20240908-004631.yaml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions core/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 26 additions & 0 deletions docs/integrations/ci.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fcad6bc

Please sign in to comment.