<?php
namespace ConventionalChangelog;
use ConventionalChangelog\Git\Repository;
use ConventionalChangelog\Helper\SemanticVersion;
$releaseMessagePrefix = 'chore(release): ';
return [
// Ignore changelogs
'ignorePatterns' => [
'/' . preg_quote($releaseMessagePrefix, '/') . '.*/i',
'/chore\(changelog\)[:].*/i',
],
'releaseCommitMessageFormat' => "{$releaseMessagePrefix}{{currentTag}}",
'postRun' => function () use ($releaseMessagePrefix) {
$lastTag = Repository::getLastTag();
$lastTagCommit = Repository::getLastTagCommit();
$lastCommit = Repository::getLastCommit();
if ($lastTagCommit !== $lastCommit) {
return;
}
$binFile = __DIR__ . '/src/Scanner.php';
$distFile = __DIR__ . '/dist/scanner';
$versionFile = __DIR__ . '/dist/version';
$readmeFile = __DIR__ . '/README.md';
$semverRegex = SemanticVersion::PATTERN;
// Get version
$version = new SemanticVersion($lastTag);
$versionString = $version->getVersion();
// Update version on readme
$readme = file_get_contents($readmeFile);
$readme = preg_replace("/(https:\/\/img\.shields\.io\/badge\/version)-({$semverRegex})-/m", '$1-' . $versionString . '-', $readme);
file_put_contents($readmeFile, $readme);
// Update version on bin
$bin = file_get_contents($binFile);
$bin = preg_replace("/(public static \\\$version = )('{$semverRegex})'/m", '$1\'' . $version->getVersion() . '\'', $bin);
file_put_contents($binFile, $bin);
// Update version file
file_put_contents($versionFile, $versionString);
// Build
include __DIR__ . '/bin/build';
// Delete tag
Repository::deleteTag($lastTag);
// Commit and tag
$message = $releaseMessagePrefix . $version->getVersion();
Repository::commit($message, [$binFile, $readmeFile, $versionFile, $distFile], true, true, true);
Repository::tag($lastTag);
},
];
|