Skip to content

Commit c2d2a59

Browse files
Handle extract.release_notes properly on CI (#3047)
* Handle extract.release_notes * Update docs/contribute/changelog.md Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Add explicit extraction state property * Add further testing for extraction behavior gaps --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 77a1c93 commit c2d2a59

7 files changed

Lines changed: 548 additions & 3 deletions

File tree

docs/cli/changelog/add.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,20 @@ When running inside GitHub Actions, `changelog add` automatically reads the foll
137137
| --- | --- | --- |
138138
| `CHANGELOG_PR_NUMBER` | `--prs` | `github.event.pull_request.number` |
139139
| `CHANGELOG_TITLE` | `--title` | `steps.evaluate.outputs.title` |
140+
| `CHANGELOG_DESCRIPTION` | `--description` | `steps.evaluate.outputs.description` |
140141
| `CHANGELOG_TYPE` | `--type` | `steps.evaluate.outputs.type` |
141142
| `CHANGELOG_PRODUCTS` | `--products` | `steps.evaluate.outputs.products` |
142143
| `CHANGELOG_OWNER` | `--owner` | `github.repository_owner` |
143144
| `CHANGELOG_REPO` | `--repo` | `github.event.repository.name` |
144145

145146
**Precedence**: explicit CLI arguments always take priority over environment variables. Environment variables are only used when the corresponding CLI argument is not provided.
146147

148+
`CHANGELOG_DESCRIPTION` has additional precedence rules related to release note extraction:
149+
150+
- If `--description` is provided on the command line, it always wins.
151+
- If `--no-extract-release-notes` is passed (or `extract.release_notes: false` is set in the changelog configuration), `CHANGELOG_DESCRIPTION` is ignored. This prevents a description that was extracted by `evaluate-pr` from being applied when extraction has been disabled.
152+
- Otherwise, `CHANGELOG_DESCRIPTION` fills `--description` when it is not set on the command line.
153+
147154
The filename strategy is controlled by the `filename` option in `changelog.yml` (defaulting to `timestamp`). Refer to [changelog.example.yml](https://github.com/elastic/docs-builder/blob/main/config/changelog.example.yml) for details.
148155

149156
This allows the CI action to invoke `changelog add` with a minimal command line:

docs/cli/changelog/evaluate-pr.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ docs-builder changelog evaluate-pr [options...] [-h|--help]
6666
| `should-generate` | `true` if `changelog add` should run |
6767
| `should-upload` | `true` if the artifact should be uploaded |
6868
| `title` | Resolved PR title |
69+
| `description` | Release note extracted from the PR body (when `extract.release_notes` is enabled and a release note is found). Long or multi-line release notes (>120 characters) are placed here. Passed downstream as `CHANGELOG_DESCRIPTION` for `changelog add`. |
6970
| `type` | Resolved changelog type |
7071
| `products` | Comma-separated product specs resolved from PR labels via `pivot.products` mappings (e.g., `cloud-hosted, cloud-serverless`) |
7172
| `label-table` | Markdown table of configured label-to-type mappings |

docs/contribute/changelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ Ideally this task will be automated such that it's performed by a bot or GitHub
363363
If you run it from the command line, you must precede any special characters (such as backquotes) with a backslash escape character (`\`).
364364
:::
365365

366+
### CI two-step flow
367+
368+
When automated via the [changelog GitHub Actions](https://github.com/elastic/docs-actions/tree/main/changelog), changelog creation is a two-step process:
369+
370+
1. **`changelog evaluate-pr`** inspects the PR (title, labels, body) and produces outputs such as `title`, `type`, `description`, and `products`.
371+
2. **`changelog add`** reads those outputs from `CHANGELOG_*` environment variables and generates the changelog YAML file.
372+
373+
The `description` output from step 1 contains the release note extracted from the PR body (when `extract.release_notes` is enabled). If extraction is disabled — either by setting `extract.release_notes: false` in `changelog.yml` or by passing `--no-extract-release-notes` to `changelog add` — the `CHANGELOG_DESCRIPTION` environment variable is ignored and the extracted description is not written to the changelog.
374+
375+
Refer to [CI auto-detection](/cli/changelog/add.md#ci-auto-detection) for the full list of environment variables and precedence rules.
376+
366377
For up-to-date command usage information, use the `-h` option or refer to [](/cli/changelog/add.md).
367378

368379
### Authorization

src/services/Elastic.Changelog/Creation/ChangelogCreationService.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public record CreateChangelogArguments
4444
/// </summary>
4545
public bool? ExtractReleaseNotes { get; init; }
4646

47+
/// <summary>null and true both mean enabled; only explicit false disables extraction.</summary>
48+
public bool ExtractionDisabled => ExtractReleaseNotes == false;
49+
4750
/// <summary>
4851
/// Whether to extract linked issues/PRs from PR/issue body. null = use config default.
4952
/// </summary>
@@ -79,6 +82,7 @@ public async Task<bool> CreateChangelog(IDiagnosticsCollector collector, CreateC
7982
{
8083
try
8184
{
85+
var cliDescription = input.Description;
8286
input = EnrichFromCI(input);
8387

8488
// Load changelog configuration
@@ -92,6 +96,16 @@ public async Task<bool> CreateChangelog(IDiagnosticsCollector collector, CreateC
9296
// Apply config defaults to input (for extract_release_notes, extract_issues)
9397
input = ApplyConfigDefaults(input, config);
9498

99+
// When extraction is disabled (by CLI or config), discard any CI-injected description
100+
// that originated from evaluate-pr's release-note extraction.
101+
if (input.ExtractionDisabled
102+
&& string.IsNullOrWhiteSpace(cliDescription)
103+
&& !string.IsNullOrWhiteSpace(input.Description))
104+
{
105+
_logger.LogInformation("Clearing CI-provided description because release note extraction is disabled");
106+
input = input with { Description = null };
107+
}
108+
95109
// Multiple PRs: one changelog per PR (--use-pr-number uses PR number as each filename)
96110
if (input.Prs != null && input.Prs.Length > 1)
97111
return await CreateChangelogsForMultiplePrsAsync(collector, input, config, ctx);
@@ -412,11 +426,15 @@ internal CreateChangelogArguments EnrichFromCI(CreateChangelogArguments input)
412426
? input.Products
413427
: ProductArgument.ParseProductSpecs(ciProducts);
414428

429+
var enrichedDescription = !string.IsNullOrWhiteSpace(input.Description)
430+
? input.Description
431+
: input.ExtractionDisabled ? null : ciDescription;
432+
415433
return input with
416434
{
417435
Prs = enrichedPrs,
418436
Title = !string.IsNullOrWhiteSpace(input.Title) ? input.Title : ciTitle,
419-
Description = !string.IsNullOrWhiteSpace(input.Description) ? input.Description : ciDescription,
437+
Description = enrichedDescription,
420438
Type = !string.IsNullOrWhiteSpace(input.Type) ? input.Type : ciType,
421439
Owner = input.Owner ?? ciOwner,
422440
Repo = !string.IsNullOrWhiteSpace(input.Repo) ? input.Repo : ciRepo,

tests/Elastic.Changelog.Tests/Changelogs/Create/CreateChangelogTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public abstract class CreateChangelogTestBase(ITestOutputHelper output) : Change
1313
{
1414
protected IGitHubPrService MockGitHubService { get; } = A.Fake<IGitHubPrService>();
1515

16-
protected ChangelogCreationService CreateService() =>
17-
new(LoggerFactory, ConfigurationContext, MockGitHubService, FileSystem);
16+
protected ChangelogCreationService CreateService(IEnvironmentVariables? env = null) =>
17+
new(LoggerFactory, ConfigurationContext, MockGitHubService, FileSystem, env);
1818

1919
protected async Task<string> CreateConfigDirectory(string configContent)
2020
{

0 commit comments

Comments
 (0)