Skip to content

chore(tools): add chloggen for changelog management - #7346

Merged
zhxiaogg merged 1 commit into
grafana:mainfrom
zhxiaogg:chloggen-vendor-baseline
Jun 2, 2026
Merged

chore(tools): add chloggen for changelog management#7346
zhxiaogg merged 1 commit into
grafana:mainfrom
zhxiaogg:chloggen-vendor-baseline

Conversation

@zhxiaogg

@zhxiaogg zhxiaogg commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

What this PR does:

Adds the OpenTelemetry chloggen changelog tool under tools/chloggen, as part of the tools module, to manage CHANGELOG.md from per-PR entry files.

  • chloggen's packages live in the tools module; the only change to tools/go.mod is promoting cobra / testify / yaml.v3 to direct dependencies.
  • chlog-{new,validate,preview,update} Makefile targets build and run it from the repo root.
  • The code originates from OTel chloggen and is maintained in-tree (not synced upstream). The Apache-2.0 LICENSE and upstream copyright headers are retained — see tools/chloggen/FORK.md for attribution.

This is infrastructure only — changelog adoption (.chloggen config, CI enforcement, CHANGELOG.md migration) and the configurable change_type change follow in separate PRs.

Which issue(s) this PR fixes:
N/A

Checklist

  • Tests updated — N/A (the tool's own tests are included and passing; no Tempo logic added)
  • Documentation added — tools/chloggen/FORK.md
  • CHANGELOG.md updated — N/A (tooling chore, no user-facing change)
@zhxiaogg
zhxiaogg force-pushed the chloggen-vendor-baseline branch from 9468014 to 030d777 Compare June 2, 2026 16:13
Add the chloggen changelog tool under tools/chloggen, as part of the
tools module, to manage CHANGELOG.md from per-PR entry files. The
chlog-{new,validate,preview,update} Makefile targets build and run it
from the repo root.

The code originates from OpenTelemetry chloggen (open-telemetry/
opentelemetry-go-build-tools) and is maintained directly in-tree, not
synced upstream. The Apache-2.0 LICENSE and upstream copyright headers
are retained; see tools/chloggen/FORK.md for provenance.

Changelog adoption (.chloggen config, CI, CHANGELOG migration) and the
configurable change_type change are handled separately.
@zhxiaogg
zhxiaogg force-pushed the chloggen-vendor-baseline branch from 030d777 to bde3f79 Compare June 2, 2026 16:23
@zhxiaogg zhxiaogg changed the title chore(tools): vendor chloggen for changelog management Jun 2, 2026
@zhxiaogg
zhxiaogg marked this pull request as ready for review June 2, 2026 16:38
Copilot AI review requested due to automatic review settings June 2, 2026 16:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR vendors the OpenTelemetry chloggen changelog generator into Tempo under tools/chloggen (as part of the tools Go module) and wires up repo-root Makefile targets intended to build/run it for managing CHANGELOG.md from per-PR YAML entry files.

Changes:

  • Add the tools/chloggen CLI (cobra-based) plus its internal config/changelog rendering logic and upstream-derived tests/testdata.
  • Promote cobra, testify, and yaml.v3 to direct dependencies in tools/go.mod to support the new tool.
  • Add chlog-{new,validate,preview,update} Makefile targets that build the tool into ./bin/chloggen and run it from the repo root.

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
Makefile Adds chlog-* targets to build/run chloggen from repo root.
tools/go.mod Promotes cobra, testify, and yaml.v3 to direct tool-module deps.
tools/chloggen/FORK.md Documents in-tree fork status and attribution.
tools/chloggen/LICENSE Adds upstream Apache-2.0 license text for the fork.
tools/chloggen/README.md Adds basic usage documentation for the tool.
tools/chloggen/main.go Adds the chloggen CLI entrypoint wiring to cmd.Execute().
tools/chloggen/cmd/cmd_test.go Adds cobra test harness and helper data builders.
tools/chloggen/cmd/new.go Implements chloggen new (create entry file from template).
tools/chloggen/cmd/new_test.go Tests new command behavior and filename sanitization.
tools/chloggen/cmd/root.go Defines root cobra command, global config init, and repo root discovery.
tools/chloggen/cmd/root_test.go Tests root command help/usage and repoRoot.
tools/chloggen/cmd/update.go Implements chloggen update (render and write changelog updates).
tools/chloggen/cmd/update_test.go Golden-file tests for update behavior across scenarios.
tools/chloggen/cmd/validate.go Implements chloggen validate (validate YAML entries).
tools/chloggen/cmd/validate_test.go Tests validation behavior and error accumulation.
tools/chloggen/cmd/testdata/.chloggen/TEMPLATE.yaml Test-only YAML template used by command tests.
tools/chloggen/cmd/testdata/CHANGELOG.md Baseline changelog input used in command tests.
tools/chloggen/cmd/testdata/all_change_types/CHANGELOG.md Golden output for “all_change_types” update scenario.
tools/chloggen/cmd/testdata/all_change_types_alphabetical/CHANGELOG.md Golden output verifying component sort ordering.
tools/chloggen/cmd/testdata/all_change_types_multiple/CHANGELOG.md Golden output for multiple-entry update scenario.
tools/chloggen/cmd/testdata/breaking_only/CHANGELOG.md Golden output for breaking-only scenario.
tools/chloggen/cmd/testdata/bug_fix_only/CHANGELOG.md Golden output for bug-fix-only scenario.
tools/chloggen/cmd/testdata/deprecation_only/CHANGELOG.md Golden output for deprecation-only scenario.
tools/chloggen/cmd/testdata/dry_run/CHANGELOG.md Golden output baseline for dry-run scenario.
tools/chloggen/cmd/testdata/enhancement_only/CHANGELOG.md Golden output for enhancement-only scenario.
tools/chloggen/cmd/testdata/filter_component/CHANGELOG.md Golden output for component filter scenario.
tools/chloggen/cmd/testdata/filter_component_no_match/CHANGELOG.md Golden output for “no filter match” scenario.
tools/chloggen/cmd/testdata/multiple_changelogs/CHANGELOG-API.md Golden output for multi-changelog (“api”) scenario.
tools/chloggen/cmd/testdata/multiple_changelogs/CHANGELOG.md Golden output for multi-changelog (“user”) scenario.
tools/chloggen/cmd/testdata/multiple_changelogs_multiple_defaults/CHANGELOG-API.md Golden output for multi-defaults + multi-changelog (“api”).
tools/chloggen/cmd/testdata/multiple_changelogs_multiple_defaults/CHANGELOG.md Golden output for multi-defaults + multi-changelog (“user”).
tools/chloggen/cmd/testdata/multiple_changelogs_single_default/CHANGELOG-API.md Golden output for single-default + multi-changelog (“api”).
tools/chloggen/cmd/testdata/multiple_changelogs_single_default/CHANGELOG.md Golden output for single-default + multi-changelog (“user”).
tools/chloggen/cmd/testdata/new_component_only/CHANGELOG.md Golden output for new-component-only scenario.
tools/chloggen/cmd/testdata/subtext/CHANGELOG.md Golden output for subtext formatting scenario.
tools/chloggen/internal/chlog/TEMPLATE.yaml Adds default entry template used by the tool.
tools/chloggen/internal/chlog/entry.go Implements entry parsing/validation and entry file discovery/deletion.
tools/chloggen/internal/chlog/entry_test.go Tests entry validation and YAML file read/delete behavior.
tools/chloggen/internal/chlog/summary.go Implements summary generation via Go templates (embedded default).
tools/chloggen/internal/chlog/summary.tmpl Provides the embedded default summary template.
tools/chloggen/internal/chlog/summary_test.go Tests summary rendering against golden files.
tools/chloggen/internal/chlog/testdata/CHANGELOG Golden output file for default summary template tests.
tools/chloggen/internal/chlog/testdata/CHANGELOG_custom Golden output file for custom template tests.
tools/chloggen/internal/chlog/testdata/custom.tmpl Custom template used by summary tests.
tools/chloggen/internal/config/config.go Implements config defaults and YAML config loading.
tools/chloggen/internal/config/config.yaml Adds example/commented config file.
tools/chloggen/internal/config/config_test.go Tests config defaults, path resolution, and error cases.
Comment on lines +69 to +86
cfg := &Config{}
if err = yaml.Unmarshal(cfgBytes, &cfg); err != nil {
return nil, err
}

cfg.ConfigYAML = cfgYAML
cfg.EntriesDir = makeAbs(rootDir, cfg.EntriesDir, DefaultEntriesDir)
cfg.TemplateYAML = makeAbs(rootDir, cfg.TemplateYAML, filepath.Join(DefaultEntriesDir, DefaultTemplateYAML))

if len(cfg.ChangeLogs) == 0 && len(cfg.DefaultChangeLogs) > 0 {
return nil, errors.New("cannot specify 'default_changelogs' without 'changelogs'")
}

if len(cfg.ChangeLogs) == 0 {
cfg.ChangeLogs[DefaultChangeLogKey] = filepath.Join(rootDir, DefaultChangeLogFilename)
cfg.DefaultChangeLogs = []string{DefaultChangeLogKey}
return cfg, nil
}
Comment on lines +97 to +100
for _, key := range cfg.DefaultChangeLogs {
if _, ok := cfg.ChangeLogs[key]; !ok {
return nil, fmt.Errorf("'default_changelogs' contains key %q which is not defined in 'changelogs'", key)
}
Comment on lines +134 to +142
if len(entry.ChangeLogs) == 0 {
for _, cl := range cfg.DefaultChangeLogs {
entries[cl] = append(entries[cl], entry)
}
} else {
for _, cl := range entry.ChangeLogs {
entries[cl] = append(entries[cl], entry)
}
}
Comment on lines +154 to +163
for _, file := range yamlFiles {
if file == cfg.TemplateYAML || file == cfg.ConfigYAML {
continue
}

if err := os.Remove(file); err != nil {
fmt.Printf("Failed to delete: %s\n", file)
}
}
return nil
Comment on lines +70 to +73
if dry {
cmd.Printf("Generated changelog updates for %s:", changeLogKey)
cmd.Println(chlogUpdate)
continue
Comment on lines +94 to +97
tmpMD := filename + ".tmp"
if err = os.WriteFile(filepath.Clean(tmpMD), []byte(chlogBuilder.String()), 0o600); err != nil {
return err
}
Comment on lines +103 to +109
cmd.Printf("Finished updating %s\n", filename)

if err = chlog.DeleteEntries(globalCfg); err != nil {
return err
}
}
return nil
Comment thread Makefile
Comment on lines +438 to +459
CHLOGGEN ?= $(CURDIR)/bin/chloggen
CHLOGGEN_CONFIG := .chloggen/config.yaml

.PHONY: $(CHLOGGEN)
$(CHLOGGEN):
cd $(CURDIR)/tools/chloggen && go build -o $(CHLOGGEN) .

.PHONY: chlog-new
chlog-new: $(CHLOGGEN) ## Create a new changelog entry under .chloggen/
$(CHLOGGEN) new --config $(CHLOGGEN_CONFIG)

.PHONY: chlog-validate
chlog-validate: $(CHLOGGEN) ## Validate the pending changelog entries
$(CHLOGGEN) validate --config $(CHLOGGEN_CONFIG)

.PHONY: chlog-preview
chlog-preview: $(CHLOGGEN) ## Render the pending changelog entries to stdout
$(CHLOGGEN) update --config $(CHLOGGEN_CONFIG) --dry

.PHONY: chlog-update
chlog-update: $(CHLOGGEN) ## Collate pending entries into CHANGELOG.md (VERSION=vX.Y.Z)
$(CHLOGGEN) update --config $(CHLOGGEN_CONFIG) --version "$(VERSION)"
@zhxiaogg

zhxiaogg commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

will address the issues in next PR, this one is to baseline the chloggen tool codes into tempo.

@zalegrala zalegrala left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤞 LGTM

@zhxiaogg
zhxiaogg merged commit 90e1d17 into grafana:main Jun 2, 2026
29 checks passed
@zhxiaogg
zhxiaogg deleted the chloggen-vendor-baseline branch June 2, 2026 17:46
zhxiaogg added a commit that referenced this pull request Jun 3, 2026
* chore(tools): add chloggen for changelog management (#7346)

(cherry picked from commit 90e1d17)

* chore(tools): configurable chloggen change types and required entry author (#7351)

(cherry picked from commit 2e3dabb)

* chore: adopt chloggen for changelog management (#7339)

(cherry picked from commit f3e791f)

* chore: update changelog check to include modified files (#7366)

(cherry picked from commit 57897eb)

* chore(chloggen): branch-name default, optional auto-filled PR, type/docs skip (#7368)

(cherry picked from commit d182bec)

* chore(chloggen): retarget changelog workflow to release-v2.9

Backport adaptation: the changelog workflow introduced in #7339 only runs
for PRs targeting main and uses origin/main as the diff base. Point both at
release-v2.9 so the check runs on backport PRs to this branch.

---------

Co-authored-by: Ruslan Mikhailov <195758209+ruslan-mikhailov@users.noreply.github.com>
zhxiaogg added a commit that referenced this pull request Jun 3, 2026
* chore(tools): add chloggen for changelog management (#7346)

(cherry picked from commit 90e1d17)

* chore(tools): configurable chloggen change types and required entry author (#7351)

(cherry picked from commit 2e3dabb)

* chore: adopt chloggen for changelog management (#7339)

(cherry picked from commit f3e791f)

* chore: update changelog check to include modified files (#7366)

(cherry picked from commit 57897eb)

* chore(chloggen): branch-name default, optional auto-filled PR, type/docs skip (#7368)

(cherry picked from commit d182bec)

* chore(chloggen): retarget changelog workflow to release-v2.10

Backport adaptation: the changelog workflow introduced in #7339 only runs
for PRs targeting main and uses origin/main as the diff base. Point both at
release-v2.10 so the check runs on backport PRs to this branch.

---------

Co-authored-by: Ruslan Mikhailov <195758209+ruslan-mikhailov@users.noreply.github.com>
zhxiaogg added a commit that referenced this pull request Jun 3, 2026
* chore(tools): add chloggen for changelog management (#7346)

(cherry picked from commit 90e1d17)

* chore(tools): configurable chloggen change types and required entry author (#7351)

(cherry picked from commit 2e3dabb)

* chore: adopt chloggen for changelog management (#7339)

(cherry picked from commit f3e791f)

* chore: update changelog check to include modified files (#7366)

(cherry picked from commit 57897eb)

* chore(chloggen): branch-name default, optional auto-filled PR, type/docs skip (#7368)

(cherry picked from commit d182bec)

* chore(chloggen): retarget changelog workflow to release-v3.0

Backport adaptation: the changelog workflow introduced in #7339 only runs
for PRs targeting main and uses origin/main as the diff base. Point both at
release-v3.0 so the check runs on backport PRs to this branch.

---------

Co-authored-by: Ruslan Mikhailov <195758209+ruslan-mikhailov@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants