Skip to content

Commit 0fe9938

Browse files
[changelog] Fix Dependabot fallback branch validation (#191) (#193)
* [changelog] Fix Dependabot fallback branch validation (#191) * Update wiki submodule pointer for PR #193 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 6ba524e commit 0fe9938

6 files changed

Lines changed: 103 additions & 7 deletions

File tree

.github/actions/changelog/create-dependabot-entry/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ outputs:
2222
created:
2323
description: Whether a changelog entry was created and pushed.
2424
value: ${{ steps.create.outputs.created }}
25+
status:
26+
description: Whether the branch already had an entry, auto-created one, or still remains missing.
27+
value: ${{ steps.create.outputs.status }}
2528
message:
2629
description: Generated changelog entry message, or empty when no entry was needed.
2730
value: ${{ steps.create.outputs.message }}
Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,62 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
if composer dev-tools changelog:check -- --file="${INPUT_CHANGELOG_FILE}" --against="origin/${INPUT_BASE_REF}" >/dev/null 2>&1; then
5-
echo "created=false" >> "$GITHUB_OUTPUT"
6-
exit 0
7-
fi
4+
entry_message="$(php -r 'require "vendor/autoload.php"; $resolver = new \FastForward\DevTools\Changelog\DependabotChangelogEntryMessageResolver(); echo $resolver->resolve(getenv("INPUT_PULL_REQUEST_TITLE") ?: "", (int) (getenv("INPUT_PULL_REQUEST_NUMBER") ?: 0));')"
85

6+
git fetch --no-tags --depth=1 origin "+refs/heads/${INPUT_BASE_REF}:refs/remotes/origin/${INPUT_BASE_REF}"
97
git fetch --no-tags --depth=1 origin "+refs/heads/${INPUT_HEAD_REF}:refs/remotes/origin/${INPUT_HEAD_REF}"
108
git switch -C "${INPUT_HEAD_REF}" "refs/remotes/origin/${INPUT_HEAD_REF}"
119
git config user.name "github-actions[bot]"
1210
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
1311

14-
entry_message="$(php -r 'require "vendor/autoload.php"; $resolver = new \FastForward\DevTools\Changelog\DependabotChangelogEntryMessageResolver(); echo $resolver->resolve(getenv("INPUT_PULL_REQUEST_TITLE") ?: "", (int) (getenv("INPUT_PULL_REQUEST_NUMBER") ?: 0));')"
12+
if composer dev-tools changelog:check -- --file="${INPUT_CHANGELOG_FILE}" --against="origin/${INPUT_BASE_REF}" >/dev/null 2>&1; then
13+
{
14+
echo "created=false"
15+
echo "status=already-present"
16+
printf 'message=%s\n' "${entry_message}"
17+
} >> "$GITHUB_OUTPUT"
18+
19+
exit 0
20+
fi
1521

1622
composer dev-tools changelog:entry -- --type=changed --file="${INPUT_CHANGELOG_FILE}" "${entry_message}"
1723
git add "${INPUT_CHANGELOG_FILE}"
24+
25+
if git diff --cached --quiet -- "${INPUT_CHANGELOG_FILE}"; then
26+
{
27+
echo "created=false"
28+
echo "status=missing"
29+
printf 'message=%s\n' "${entry_message}"
30+
} >> "$GITHUB_OUTPUT"
31+
32+
exit 1
33+
fi
34+
1835
git commit -m "Add changelog entry for Dependabot PR #${INPUT_PULL_REQUEST_NUMBER}"
1936
git push origin "HEAD:${INPUT_HEAD_REF}"
2037

38+
if ! composer dev-tools changelog:check -- --file="${INPUT_CHANGELOG_FILE}" --against="origin/${INPUT_BASE_REF}" >/dev/null 2>&1; then
39+
{
40+
echo "created=false"
41+
echo "status=missing"
42+
printf 'message=%s\n' "${entry_message}"
43+
} >> "$GITHUB_OUTPUT"
44+
45+
exit 1
46+
fi
47+
48+
if ! grep -F --quiet -- "- ${entry_message}" "${INPUT_CHANGELOG_FILE}"; then
49+
{
50+
echo "created=false"
51+
echo "status=missing"
52+
printf 'message=%s\n' "${entry_message}"
53+
} >> "$GITHUB_OUTPUT"
54+
55+
exit 1
56+
fi
57+
2158
{
2259
echo "created=true"
60+
echo "status=auto-created"
2361
printf 'message=%s\n' "${entry_message}"
2462
} >> "$GITHUB_OUTPUT"

.github/wiki

Submodule wiki updated from 0fedf54 to 79fb0c2

.github/workflows/changelog.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ jobs:
141141
142142
- Changelog file: `${{ env.CHANGELOG_FILE }}`
143143
- Compared base ref: `origin/${{ env.BASE_REF }}`
144+
- Dependabot fallback status: `${{ steps.dependabot_entry.outputs.status || 'not needed' }}`
144145
- Dependabot fallback entry created: `${{ steps.dependabot_entry.outputs.created || 'false' }}`
145-
- Dependabot fallback entry message: `${{ steps.dependabot_entry.outputs.message || 'not needed' }}`
146+
- Dependabot fallback generated message: `${{ steps.dependabot_entry.outputs.message || 'not needed' }}`
146147
- Validation result: success
147148
148149
prepare_release_pull_request:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- GitHub Actions(deps): Bump marocchino/sticky-pull-request-comment from 2 to 3 (#182)
1414
- GitHub Actions(deps): Bump actions/github-script from 8 to 9 (#183)
1515
- Auto-create and push minimal changelog entries for same-repository Dependabot pull requests before changelog validation reruns (#186)
16+
- Resolve Dependabot changelog fallback state from the actual PR head branch and report `already-present`, `auto-created`, or `missing` in the workflow summary so rebased PRs cannot pass on inherited `Unreleased` entries alone (#191)
1617

1718
## [1.20.0] - 2026-04-23
1819

tests/Changelog/Checker/UnreleasedEntryCheckerTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,59 @@ public function hasPendingChangesWillReturnTrueWhenBaselineDoesNotContainNewEntr
175175
self::assertTrue($this->checker->hasPendingChanges(self::FILE, 'origin/main'));
176176
}
177177

178+
/**
179+
* @return void
180+
*/
181+
#[Test]
182+
public function hasPendingChangesWillIgnoreEntriesOnlyInheritedFromTheBaseBranch(): void
183+
{
184+
$this->filesystem->readFile(self::FILE)
185+
->willReturn('current changelog')
186+
->shouldBeCalledOnce();
187+
$this->parser->parse('current changelog')
188+
->willReturn($this->createDocument([
189+
'Auto-create and push minimal changelog entries for same-repository Dependabot pull requests before changelog validation reruns (#186)',
190+
]))
191+
->shouldBeCalledOnce();
192+
$this->gitClient->show('origin/main', self::FILE, self::WORKING_DIRECTORY)
193+
->willReturn('baseline changelog')
194+
->shouldBeCalledOnce();
195+
$this->parser->parse('baseline changelog')
196+
->willReturn($this->createDocument([
197+
'Auto-create and push minimal changelog entries for same-repository Dependabot pull requests before changelog validation reruns (#186)',
198+
]))
199+
->shouldBeCalledOnce();
200+
201+
self::assertFalse($this->checker->hasPendingChanges(self::FILE, 'origin/main'));
202+
}
203+
204+
/**
205+
* @return void
206+
*/
207+
#[Test]
208+
public function hasPendingChangesWillStillDetectBranchSpecificEntriesAlongsideInheritedOnes(): void
209+
{
210+
$this->filesystem->readFile(self::FILE)
211+
->willReturn('current changelog')
212+
->shouldBeCalledOnce();
213+
$this->parser->parse('current changelog')
214+
->willReturn($this->createDocument([
215+
'Auto-create and push minimal changelog entries for same-repository Dependabot pull requests before changelog validation reruns (#186)',
216+
'GitHub Actions(deps): Bump actions/github-script from 8 to 9 (#183)',
217+
]))
218+
->shouldBeCalledOnce();
219+
$this->gitClient->show('origin/main', self::FILE, self::WORKING_DIRECTORY)
220+
->willReturn('baseline changelog')
221+
->shouldBeCalledOnce();
222+
$this->parser->parse('baseline changelog')
223+
->willReturn($this->createDocument([
224+
'Auto-create and push minimal changelog entries for same-repository Dependabot pull requests before changelog validation reruns (#186)',
225+
]))
226+
->shouldBeCalledOnce();
227+
228+
self::assertTrue($this->checker->hasPendingChanges(self::FILE, 'origin/main'));
229+
}
230+
178231
/**
179232
* @return void
180233
*/

0 commit comments

Comments
 (0)