-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathupdate-readme-changelog.php
More file actions
50 lines (41 loc) · 1.39 KB
/
update-readme-changelog.php
File metadata and controls
50 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<? php
/**
* Update readme.txt with new changelog entry
*
* Usage: php bin/update-readme-changelog.php --readme readme.txt --changelog-entry changelog-entry.txt --output readme.txt
*/
$options = getopt('', [
'readme:',
'changelog-entry:',
'output:',
]);
$readme_file = $options['readme'] ?? 'readme.txt';
$changelog_entry_file = $options['changelog-entry'] ?? '';
$output_file = $options['output'] ?? 'readme. txt';
if (! file_exists($readme_file)) {
fwrite(STDERR, "Error: readme. txt not found at {$readme_file}\n");
exit(1);
}
if (!file_exists($changelog_entry_file)) {
fwrite(STDERR, "Error: changelog entry file not found at {$changelog_entry_file}\n");
exit(1);
}
$readme_content = file_get_contents($readme_file);
$changelog_entry = file_get_contents($changelog_entry_file);
// Find the changelog section
$pattern = '/(== Changelog ==\s*\n\n)/';
if (preg_match($pattern, $readme_content, $matches, PREG_OFFSET_CAPTURE)) {
$insert_position = $matches[0][1] + strlen($matches[0][0]);
// Insert new changelog entry
$updated_content = substr_replace(
$readme_content,
$changelog_entry . "\n",
$insert_position,
0
);
file_put_contents($output_file, $updated_content);
echo "Successfully updated {$output_file}\n";
} else {
fwrite(STDERR, "Error: Could not find Changelog section in readme.txt\n");
exit(1);
}