feat: add --changelog flag to requires update command#3626
feat: add --changelog flag to requires update command#3626teresaromero wants to merge 10 commits into
Conversation
Adds pure helpers to classify dependency bumps into semver tiers (patch/minor/major), aggregate tiers across proposals, map tiers to changelog entry types and --next mode strings, and a ChangelogPlaceholderLink constant. Adds Result.NewVersion for the command layer to populate. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds --changelog and --changelog-type flags to `elastic-package requires update`. When --changelog is set and there are bumps, the command runs two explicit steps: Apply (updates requires pins in manifest.yml) followed by ApplyChangelog (bumps the package version and adds one changelog entry per dependency in changelog.yml). The two steps remain separate so callers can invoke them independently. Domain logic (NextVersion, AssertManifestMatchesChangelogTop, BuildChangelogRevision, ApplyChangelog) lives in internal/requiresupdates; cmd/requires.go is a thin orchestration layer. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Documents the --changelog and --changelog-type flags for elastic-package requires update, including version bump tier logic, inferred vs overridden entry types, the placeholder link contract, dry-run and JSON output behaviour, and guard conditions. Also adds a godoc comment to changelogTypeChoices explaining that it mirrors the package-spec changelog entry type enum, with deprecation intentionally excluded for dependency-bump entries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
NextVersionFromRevisions and NextVersion now live in the changelog package (the natural home for operations on Revision slices), removing the duplication between changelogCmdVersion and requiresupdates.NextVersion. cmd/changelog.go calls changelog.NextVersion directly; requiresupdates.NextVersion delegates via tier.NextMode(); ApplyChangelog reads changelog.yml once and calls changelog.NextVersionFromRevisions with the already-parsed revisions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Table-driven TestApplyRequiresUpdate calls applyRequiresUpdate directly via t.TempDir() fixtures, covering inferred types, type override, major bump, multiple-dep aggregate tier, changelog-disabled path, and divergent-version error with no-file-write guarantee. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
494de88 to
bb45b33
Compare
Updated the formatting of test cases in requires_test.go and changelog_test.go for improved readability. Adjusted spacing and alignment of struct fields to maintain consistency across the codebase. Minor adjustments made in changelog.go for clarity in the NextMode function. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| bumped the package version. | ||
|
|
||
| **Guards.** The command refuses to proceed when the changelog top version and `manifest.yml` | ||
| version disagree, or when the changelog top version is a pre-release. Proposals that are |
There was a problem hiding this comment.
According to this doc , the changelog is not added if the top version is a pre-release.
Just checked that there is this method in ApplyChangelog:
if err := assertManifestVersionMatchesChangelogTop(manifestBytes, revisions); err != nil {
return nil, "", err
}Should this guard be added ? or is it managed already in another method?
There was a problem hiding this comment.
i am being aware now that i was thinking on "prereleased" as "experimental" too.... and this might be an implementation gap. i think we should probably ignore changelog for prerelease (-suffix) but allow for experimental.
assertManifestVersionMatchesChangelogTop just checks the manifest is aligned with the changelog latest entry
| manifestBytes, err = changelog.SetManifestVersion(manifestBytes, next.String()) | ||
| if err != nil { | ||
| return nil, "", err | ||
| } |
There was a problem hiding this comment.
Taking as a example elastic-package changelog command, changelog and manifest updates are separated.
elastic-package/cmd/changelog.go
Lines 98 to 106 in 6158fcd
What about moving the writing of the manifet out of the ApplyChangelog? So applyChangelog just updates changelog and not manifest ? That write could be done by requires.Apply.
| } | ||
| } | ||
| } else if applied { | ||
| cmd.Println("Updated manifest.yml") |
There was a problem hiding this comment.
If --changelog is set, this message should also indicate that changelog.yml has been updated.
| updateCmd.Flags().Bool(cobraext.RequiresChangelogFlagName, false, cobraext.RequiresChangelogFlagDescription) | ||
| updateCmd.Flags().String(cobraext.RequiresChangelogTypeFlagName, "", cobraext.RequiresChangelogTypeFlagDescription) |
There was a problem hiding this comment.
There is no documentation added for these 2 new flags here:
elastic-package/cmd/requires.go
Lines 35 to 40 in 6158fcd
| // package is built and checked against the spec; this list enables early flag | ||
| // validation. "deprecation" is intentionally excluded as it is not a valid type | ||
| // for automated dependency-bump changelog entries. | ||
| var changelogTypeChoices = []string{"bugfix", "enhancement", "breaking-change"} |
There was a problem hiding this comment.
Taking a look to this list, there is another place where these values are king of defined.
elastic-package/internal/cobraext/flags.go
Line 107 in 6158fcd
I know that this is unrelated to tihs PR, but could you add deprecation there in the flag description?
I wonder if we could set the list in the description programmatically.
Added detailed descriptions for new flags in the `elastic-package requires update` command, including `--format`, `--prerelease`, `--changelog`, and `--changelog-type`. Clarified their usage and effects on output and version bumping behavior. Updated related documentation in `cmd/requires.go` and `docs/howto/dependency_management.md` for consistency and clarity.
Updated the changelog command to include a predefined list of changelog entry types for better validation. Adjusted the `--changelog-type` flag description in both `cmd/changelog.go` and `cmd/requires.go` to reflect the new choices. This change improves user guidance and ensures consistency across commands regarding changelog entry types.
Updated the `requiresUpdateCommandAction` function to print a message indicating when the `changelog.yml` file is updated, in addition to the existing manifest update message. This improvement provides clearer feedback to users regarding changes made during the update process.
Updated the `applyRequiresUpdate` function to improve the handling of changelog and manifest version updates. The `ApplyChangelog` function now only returns the new version string, while the manifest version is updated separately using `ApplyManifestVersion`. Additionally, introduced a new `ReadChangelogBytes` function to enhance the parsing of changelog data from raw bytes. This refactor enhances clarity and maintains atomicity in the update process.
💚 Build Succeeded
History
|
Summary
Extends
requires updatewith two optional flags that automate changelog maintenance when bumping package dependencies:--changelog— for each bumped dependency, appends one changelog entry tochangelog.ymland bumps the package's own version in bothchangelog.ymlandmanifest.yml.--changelog-type— overrides the inferred entry type for all generated entries (bugfix,enhancement, orbreaking-change). Without this flag the type is inferred from the semver bump tier: major →breaking-change, minor/patch →enhancement.When combined with
--dry-run, nothing is written; the would-be new version and per-entry inferred types are printed instead.How it works
Current→Proposedsemver delta determines its tier (TierMajor,TierMinor,TierPatch). Content-dependency constraints that can't be parsed as an exact version default toTierMinor.major|minor|patchmode aschangelog add --next <tier>).PatchYAMLis validated before any file is written, so a failed patch leaves no partial state.https://github.com/elastic/integrations/pull/REPLACE_MEas its link. The [automation] Add requires-update workflow integrations#19217 PR-opening workflow is expected to replace this token with the real PR URL. This is a contract — the literal value must be confirmed with that workflow before merge.new_versionin JSON output —Result.NewVersionis populated when--changelogbumps the version, making it available to automation via--format json.Reviewer notes
ChangelogPlaceholderLink(https://github.com/elastic/integrations/pull/REPLACE_ME) is a contract with the [automation] Add requires-update workflow integrations#19217 PR-opening workflow, which must search-and-replace this exact token with the real PR URL. The literal value is still proposed — needs confirmation with that workflow before merge.Currentvalues that are semver constraints (e.g.^0.3.0) cannot be diffed againstProposed; they default toTierMinor. This is a deliberate approximation since Masterminds/semver exposes no constraint floor.PatchYAMLis validated in memory before either file is written.changelog.ymlis written first, thenmanifest.yml. A failure after the first write but before the second would leave the files inconsistent; this was accepted as a low-probability edge case vs. the complexity of a two-phase commit.manifest.ymlversion differs from thechangelog.ymltop revision before applying changes. package-spec requires they agree; this protects against already-dirty packages.