Skip to content

Commit

Permalink
[chloggen] Add ability to generate multiple changelog files
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski committed Jul 21, 2023
1 parent 02066be commit 88d0fa0
Show file tree
Hide file tree
Showing 29 changed files with 869 additions and 194 deletions.
16 changes: 16 additions & 0 deletions .chloggen/chloggen-multiple-logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. crosslink)
component: chloggen

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add ability to configure separate changelogs for different audiences

# One or more tracking issues related to the change
issues: [364]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
49 changes: 30 additions & 19 deletions chloggen/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,47 @@ func entryWithSubtext() *chlog.Entry {
}
}

func setupTestDir(t *testing.T, entries []*chlog.Entry) config.Config {
cfg := config.New(t.TempDir())
func entryForChangelogs(changeType string, issue int, keys ...string) *chlog.Entry {
keyStr := "default"
if len(keys) > 0 {
keyStr = strings.Join(keys, ",")
}
return &chlog.Entry{
Changelogs: keys,
ChangeType: changeType,
Component: "receiver/foo",
Note: fmt.Sprintf("Some change relevant to [%s]", keyStr),
Issues: []int{issue},
}
}

func setupTestDir(t *testing.T, entries []*chlog.Entry) {
require.NotNil(t, globalCfg, "test should instantiate globalCfg before calling setupTestDir")

// Create a known dummy changelog which may be updated by the test
changelogBytes, err := os.ReadFile(filepath.Join("testdata", config.DefaultChangelogMD))
// Create dummy changelogs which may be updated by the test
changelogBytes, err := os.ReadFile(filepath.Join("testdata", config.DefaultChangelogFilename))
require.NoError(t, err)
require.NoError(t, os.WriteFile(cfg.ChangelogMD, changelogBytes, os.FileMode(0755)))
for _, filename := range globalCfg.Changelogs {
require.NoError(t, os.MkdirAll(filepath.Dir(filename), os.FileMode(0755)))
require.NoError(t, os.WriteFile(filename, changelogBytes, os.FileMode(0755)))
}

require.NoError(t, os.Mkdir(cfg.ChlogsDir, os.FileMode(0755)))
// Create the chlogs directory
require.NoError(t, os.MkdirAll(globalCfg.ChlogsDir, os.FileMode(0755)))

// Copy the entry template, for tests that ensure it is not deleted
templateInRootDir := config.New("testdata").TemplateYAML
templateBytes, err := os.ReadFile(filepath.Clean(templateInRootDir))
require.NoError(t, err)
require.NoError(t, os.WriteFile(cfg.TemplateYAML, templateBytes, os.FileMode(0755)))
require.NoError(t, os.WriteFile(globalCfg.TemplateYAML, templateBytes, os.FileMode(0755)))

// Write the entries to the chlogs directory
for i, entry := range entries {
require.NoError(t, writeEntryYAML(cfg, fmt.Sprintf("%d.yaml", i), entry))
}

return cfg
}

func writeEntryYAML(cfg config.Config, filename string, entry *chlog.Entry) error {
entryBytes, err := yaml.Marshal(entry)
if err != nil {
return err
entryBytes, err := yaml.Marshal(entry)
require.NoError(t, err)
path := filepath.Join(globalCfg.ChlogsDir, fmt.Sprintf("%d.yaml", i))
require.NoError(t, os.WriteFile(path, entryBytes, os.FileMode(0755)))
}
path := filepath.Join(cfg.ChlogsDir, filename)
return os.WriteFile(path, entryBytes, os.FileMode(0755))
}

func runCobra(t *testing.T, args ...string) (string, string) {
Expand Down
4 changes: 3 additions & 1 deletion chloggen/cmd/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/build-tools/chloggen/internal/chlog"
"go.opentelemetry.io/build-tools/chloggen/internal/config"
)

const newUsage = `Usage:
Expand Down Expand Up @@ -51,7 +52,8 @@ func TestNewErr(t *testing.T) {
}

func TestNew(t *testing.T) {
globalCfg = setupTestDir(t, []*chlog.Entry{})
globalCfg = config.New(t.TempDir())
setupTestDir(t, []*chlog.Entry{})

var out, err string

Expand Down
5 changes: 2 additions & 3 deletions chloggen/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

var (
configFile string
globalCfg config.Config
globalCfg *config.Config
)

func rootCmd() *cobra.Command {
Expand All @@ -51,8 +51,7 @@ func init() {

func initConfig() {
// Don't override if already set in tests
var uninitialized config.Config
if globalCfg != uninitialized {
if globalCfg != nil {
return
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions chloggen/cmd/testdata/multiple_changelogs/CHANGELOG-API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Changelog

<!-- next version -->

## v0.45.0

### 🛑 Breaking changes 🛑

- `receiver/foo`: Some change relevant to [api] (#125)
- `receiver/foo`: Some change relevant to [user,api] (#11)

### 🚩 Deprecations 🚩

- `receiver/foo`: Some change relevant to [api] (#223)
- `receiver/foo`: Some change relevant to [user,api] (#234)

### 💡 Enhancements 💡

- `receiver/foo`: Some change relevant to [api,user] (#333)
- `receiver/foo`: Some change relevant to [api] (#555)

### 🧰 Bug fixes 🧰

- `receiver/foo`: Some change relevant to [api] (#111)
- `receiver/foo`: Some change relevant to [api] (#777)

## v0.44.0

### 🛑 Breaking changes 🛑

- `prometheusexporter`: Automatically rename metrics with units to follow Prometheus naming convention (#8950)

### 💡 Enhancements 💡

- `filterprocessor`: Ability to filter `Spans` (#6341)
- `flinkmetricsreceiver`: add attribute values to metadata #11520

### 🧰 Bug fixes 🧰

- `redactionprocessor`: respect allow_all_keys configuration (#11542)
39 changes: 39 additions & 0 deletions chloggen/cmd/testdata/multiple_changelogs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Changelog

<!-- next version -->

## v0.45.0

### 🛑 Breaking changes 🛑

- `receiver/foo`: Some change relevant to [user,api] (#11)

### 🚩 Deprecations 🚩

- `receiver/foo`: Some change relevant to [user] (#123)
- `receiver/foo`: Some change relevant to [user,api] (#234)

### 💡 Enhancements 💡

- `receiver/foo`: Some change relevant to [user] (#21)
- `receiver/foo`: Some change relevant to [api,user] (#333)

### 🧰 Bug fixes 🧰

- `receiver/foo`: Some change relevant to [user] (#32)
- `receiver/foo`: Some change relevant to [user] (#222)

## v0.44.0

### 🛑 Breaking changes 🛑

- `prometheusexporter`: Automatically rename metrics with units to follow Prometheus naming convention (#8950)

### 💡 Enhancements 💡

- `filterprocessor`: Ability to filter `Spans` (#6341)
- `flinkmetricsreceiver`: add attribute values to metadata #11520

### 🧰 Bug fixes 🧰

- `redactionprocessor`: respect allow_all_keys configuration (#11542)
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Changelog

<!-- next version -->

## v0.45.0

### 🛑 Breaking changes 🛑

- `receiver/foo`: Some change relevant to [api] (#125)
- `receiver/foo`: Some change relevant to [user,api] (#11)

### 🚩 Deprecations 🚩

- `receiver/foo`: Some change relevant to [default] (#123)
- `receiver/foo`: Some change relevant to [api] (#223)
- `receiver/foo`: Some change relevant to [user,api] (#234)

### 💡 Enhancements 💡

- `receiver/foo`: Some change relevant to [default] (#21)
- `receiver/foo`: Some change relevant to [api,user] (#333)
- `receiver/foo`: Some change relevant to [api] (#555)

### 🧰 Bug fixes 🧰

- `receiver/foo`: Some change relevant to [default] (#32)
- `receiver/foo`: Some change relevant to [default] (#222)
- `receiver/foo`: Some change relevant to [api] (#111)
- `receiver/foo`: Some change relevant to [api] (#777)

## v0.44.0

### 🛑 Breaking changes 🛑

- `prometheusexporter`: Automatically rename metrics with units to follow Prometheus naming convention (#8950)

### 💡 Enhancements 💡

- `filterprocessor`: Ability to filter `Spans` (#6341)
- `flinkmetricsreceiver`: add attribute values to metadata #11520

### 🧰 Bug fixes 🧰

- `redactionprocessor`: respect allow_all_keys configuration (#11542)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Changelog

<!-- next version -->

## v0.45.0

### 🛑 Breaking changes 🛑

- `receiver/foo`: Some change relevant to [user,api] (#11)

### 🚩 Deprecations 🚩

- `receiver/foo`: Some change relevant to [default] (#123)
- `receiver/foo`: Some change relevant to [user,api] (#234)

### 💡 Enhancements 💡

- `receiver/foo`: Some change relevant to [default] (#21)
- `receiver/foo`: Some change relevant to [api,user] (#333)

### 🧰 Bug fixes 🧰

- `receiver/foo`: Some change relevant to [default] (#32)
- `receiver/foo`: Some change relevant to [default] (#222)

## v0.44.0

### 🛑 Breaking changes 🛑

- `prometheusexporter`: Automatically rename metrics with units to follow Prometheus naming convention (#8950)

### 💡 Enhancements 💡

- `filterprocessor`: Ability to filter `Spans` (#6341)
- `flinkmetricsreceiver`: add attribute values to metadata #11520

### 🧰 Bug fixes 🧰

- `redactionprocessor`: respect allow_all_keys configuration (#11542)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Changelog

<!-- next version -->

## v0.45.0

### 🛑 Breaking changes 🛑

- `receiver/foo`: Some change relevant to [api] (#125)
- `receiver/foo`: Some change relevant to [user,api] (#11)

### 🚩 Deprecations 🚩

- `receiver/foo`: Some change relevant to [api] (#223)
- `receiver/foo`: Some change relevant to [user,api] (#234)

### 💡 Enhancements 💡

- `receiver/foo`: Some change relevant to [api,user] (#333)
- `receiver/foo`: Some change relevant to [api] (#555)

### 🧰 Bug fixes 🧰

- `receiver/foo`: Some change relevant to [api] (#111)
- `receiver/foo`: Some change relevant to [api] (#777)

## v0.44.0

### 🛑 Breaking changes 🛑

- `prometheusexporter`: Automatically rename metrics with units to follow Prometheus naming convention (#8950)

### 💡 Enhancements 💡

- `filterprocessor`: Ability to filter `Spans` (#6341)
- `flinkmetricsreceiver`: add attribute values to metadata #11520

### 🧰 Bug fixes 🧰

- `redactionprocessor`: respect allow_all_keys configuration (#11542)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Changelog

<!-- next version -->

## v0.45.0

### 🛑 Breaking changes 🛑

- `receiver/foo`: Some change relevant to [user,api] (#11)

### 🚩 Deprecations 🚩

- `receiver/foo`: Some change relevant to [default] (#123)
- `receiver/foo`: Some change relevant to [user,api] (#234)

### 💡 Enhancements 💡

- `receiver/foo`: Some change relevant to [default] (#21)
- `receiver/foo`: Some change relevant to [api,user] (#333)

### 🧰 Bug fixes 🧰

- `receiver/foo`: Some change relevant to [default] (#32)
- `receiver/foo`: Some change relevant to [default] (#222)

## v0.44.0

### 🛑 Breaking changes 🛑

- `prometheusexporter`: Automatically rename metrics with units to follow Prometheus naming convention (#8950)

### 💡 Enhancements 💡

- `filterprocessor`: Ability to filter `Spans` (#6341)
- `flinkmetricsreceiver`: add attribute values to metadata #11520

### 🧰 Bug fixes 🧰

- `redactionprocessor`: respect allow_all_keys configuration (#11542)
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 88d0fa0

Please sign in to comment.