Skip to content

Commit

Permalink
Fix make-release script for MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
wisskid committed Nov 11, 2023
1 parent bc4e70f commit 198338e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Empty file added changelog/.gitkeep
Empty file.
5 changes: 3 additions & 2 deletions make-release.sh
Expand Up @@ -8,8 +8,9 @@ else
fi

git checkout -b "release/$1"
sed -i "s/## \\[Unreleased\\]/## \\[Unreleased\\]\\n\\n## \\[$1\\] - $(date +%Y-%m-%d)/" CHANGELOG.md
sed -i "s/const SMARTY_VERSION = '[^']\+';/const SMARTY_VERSION = '$1';/" src/Smarty.php

php utilities/update-changelog.php $1
php utilities/update-smarty-version-number.php $1

git add CHANGELOG.md src/Smarty.php
git commit -m "version bump"
Expand Down
42 changes: 42 additions & 0 deletions utilities/update-changelog.php
@@ -0,0 +1,42 @@
<?php

// This takes the *.md files in changelog/ dir and inserts them
// right below the '## [Unreleased]' marker in CHANGELOG.md

$path_to_main_changelog = 'CHANGELOG.md';
$marker = '## [Unreleased]';
$changelog_files_pattern = 'changelog/*.md';
$new_version = $argv[1];

$file_contents = file_get_contents($path_to_main_changelog);

foreach (glob($changelog_files_pattern) as $filename) {
$content_to_insert = file_get_contents($filename);

if (!endsWithNewline($content_to_insert)) {
$content_to_insert .= "\n";
}

$file_contents = str_replace(
$marker,
$marker . $content_to_insert,
$file_contents
);
unlink($filename);
}


// add the version number and date
$file_contents = str_replace(
$marker,
$marker . sprintf("\n\n## [%s] - %s\n", $new_version, date('Y-m-d')),
$file_contents
);

file_put_contents($path_to_main_changelog, $file_contents);


function endsWithNewline($str): bool
{
return preg_match('/[\r\n]$/', $str) === 1;
}
11 changes: 11 additions & 0 deletions utilities/update-smarty-version-number.php
@@ -0,0 +1,11 @@
<?php

// This takes the Smarty class file and updates the SMARTY_VERSION constant

$path_to_smarty_class = 'src/Smarty.php';
$pattern = "/const SMARTY_VERSION = '[^']+'/";
$replacement = "const SMARTY_VERSION = '" . $argv[1] . "'";

$file_contents = preg_replace($pattern, $replacement, file_get_contents($path_to_smarty_class));

file_put_contents($path_to_smarty_class, $file_contents);

0 comments on commit 198338e

Please sign in to comment.