Skip to content

feat: add --changelog flag to requires update command#3626

Open
teresaromero wants to merge 10 commits into
elastic:mainfrom
teresaromero:requires-update-command-changelog
Open

feat: add --changelog flag to requires update command#3626
teresaromero wants to merge 10 commits into
elastic:mainfrom
teresaromero:requires-update-command-changelog

Conversation

@teresaromero

@teresaromero teresaromero commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends requires update with two optional flags that automate changelog maintenance when bumping package dependencies:

elastic-package requires update [--changelog] [--changelog-type <type>]
  • --changelog — for each bumped dependency, appends one changelog entry to changelog.yml and bumps the package's own version in both changelog.yml and manifest.yml.
  • --changelog-type — overrides the inferred entry type for all generated entries (bugfix, enhancement, or breaking-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

  1. Tier inference — each proposal's CurrentProposed semver delta determines its tier (TierMajor, TierMinor, TierPatch). Content-dependency constraints that can't be parsed as an exact version default to TierMinor.
  2. Aggregate tier — the largest tier across all bumped proposals drives the package version bump (same major|minor|patch mode as changelog add --next <tier>).
  3. Atomic write — all edits (manifest bytes + changelog bytes) are computed in memory and PatchYAML is validated before any file is written, so a failed patch leaves no partial state.
  4. Placeholder link — every generated entry uses https://github.com/elastic/integrations/pull/REPLACE_ME as 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.
  5. new_version in JSON outputResult.NewVersion is populated when --changelog bumps the version, making it available to automation via --format json.

Reviewer notes

  • Placeholder link contractChangelogPlaceholderLink (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.
  • Tier inference for content constraintsCurrent values that are semver constraints (e.g. ^0.3.0) cannot be diffed against Proposed; they default to TierMinor. This is a deliberate approximation since Masterminds/semver exposes no constraint floor.
  • Atomic write orderingPatchYAML is validated in memory before either file is written. changelog.yml is written first, then manifest.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.
  • Version divergence guard — the command errors if manifest.yml version differs from the changelog.yml top revision before applying changes. package-spec requires they agree; this protects against already-dirty packages.

teresaromero and others added 5 commits June 2, 2026 11:12
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>
@teresaromero teresaromero force-pushed the requires-update-command-changelog branch from 494de88 to bb45b33 Compare June 2, 2026 09:13
@teresaromero teresaromero marked this pull request as ready for review June 2, 2026 09:13
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>
@teresaromero teresaromero requested a review from a team June 2, 2026 12:30
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

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.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment thread internal/requiresupdates/changelog.go Outdated
Comment on lines +188 to +191
manifestBytes, err = changelog.SetManifestVersion(manifestBytes, next.String())
if err != nil {
return nil, "", err
}

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.

Taking as a example elastic-package changelog command, changelog and manifest updates are separated.

err = patchChangelogFile(packageRoot, entry)
if err != nil {
return err
}
err = setManifestVersion(packageRoot, version)
if err != nil {
return err
}

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.

Comment thread cmd/requires.go
}
}
} else if applied {
cmd.Println("Updated manifest.yml")

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.

If --changelog is set, this message should also indicate that changelog.yml has been updated.

Comment thread cmd/requires.go Outdated
Comment on lines +54 to +55
updateCmd.Flags().Bool(cobraext.RequiresChangelogFlagName, false, cobraext.RequiresChangelogFlagDescription)
updateCmd.Flags().String(cobraext.RequiresChangelogTypeFlagName, "", cobraext.RequiresChangelogTypeFlagDescription)

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.

There is no documentation added for these 2 new flags here:

requiresUpdateLongDescription = `Update requires.input and requires.content pins to the latest registry versions compatible with this package's Kibana constraint.
By default manifest.yml is updated. Use --dry-run to report available bumps without writing the manifest.
Version pins must be exact semver versions (constraints such as ^0.3.0 are not accepted).
When a newer dependency exists but requires a higher Kibana version than this package allows, a warning is printed suggesting to bump conditions.kibana.version on the integration package.`

Comment thread cmd/requires.go Outdated
// 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"}

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.

Taking a look to this list, there is another place where these values are king of defined.

ChangelogAddTypeFlagDescription = "type of change (bugfix, enhancement or breaking-change) for the changelog entry"

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.
@elasticmachine

Copy link
Copy Markdown
Contributor

💚 Build Succeeded

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically update package dependencies

3 participants