-
Notifications
You must be signed in to change notification settings - Fork 32
/
.changelog
52 lines (41 loc) · 1.79 KB
/
.changelog
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
51
52
<?php
namespace ConventionalChangelog;
use ConventionalChangelog\Git\Repository;
use ConventionalChangelog\Helper\SemanticVersion;
$releaseMessagePrefix = 'chore(release): ';
return [
'types' => ['feat', 'fix', 'perf', 'docs', 'chore'],
// Ignore changelogs
'ignorePatterns' => [
'/' . preg_quote($releaseMessagePrefix, '/') . '.*/i',
'/chore\(changelog\)[:].*/i',
],
'releaseCommitMessageFormat' => "{$releaseMessagePrefix}{{currentTag}}",
'postRun' => function () use ($releaseMessagePrefix) {
$lastTag = Repository::getLastTagRefname();
$lastTagCommit = Repository::getLastTagRefnameCommit();
$lastCommit = Repository::getLastCommit();
if ($lastTagCommit !== $lastCommit) {
return;
}
$binFile = __DIR__ . '/conventional-changelog';
$readmeFile = __DIR__ . '/README.md';
$semverRegex = SemanticVersion::PATTERN;
// Get version
$version = new SemanticVersion($lastTag);
// Update version on readme
$readme = file_get_contents($readmeFile);
$readme = preg_replace("/(https:\/\/img\.shields\.io\/badge\/version)-({$semverRegex})-/m", '$1-' . $version->getVersion() . '-', $readme);
file_put_contents($readmeFile, $readme);
// Update version on bin
$bin = file_get_contents($binFile);
$bin = preg_replace("/(\('conventional-changelog', )'({$semverRegex})'/m", '$1\'' . $version->getVersion() . '\'', $bin);
file_put_contents($binFile, $bin);
// Delete tag
Repository::deleteTag($lastTag);
// Commit and tag
$message = $releaseMessagePrefix . $version->getVersion();
Repository::commit($message, [$binFile, $readmeFile], true, true, true);
Repository::tag($lastTag);
},
];