Skip to content

Commit

Permalink
release/6.0.3 (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb authored Jul 2, 2022
1 parent a8df8ca commit 9fca571
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 9 deletions.
33 changes: 25 additions & 8 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<package version="2.1" xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd">
<package xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd">
<name>rdkafka</name>
<channel>pecl.php.net</channel>
<summary>Kafka client based on librdkafka</summary>
Expand All @@ -10,10 +10,10 @@
<email>arnaud.lb@gmail.com</email>
<active>yes</active>
</lead>
<date>2022-06-12</date>
<time>12:00:00</time>
<date>2022-07-02</date>
<time>12:26:56</time>
<version>
<release>6.0.2</release>
<release>6.0.3</release>
<api>6.0.0</api>
</version>
<stability>
Expand All @@ -22,8 +22,8 @@
</stability>
<license uri="http://opensource.org/licenses/mit-license.php">MIT License</license>
<notes>
## Bugfixes
- Fixed signature of RdKafka\KafkaConsumer::getMetadata() (#521, @arnaud-lb)
## Improvements
- Ability to provide custom `librdkafka` path during install (#526, @Wirone)
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -160,6 +160,23 @@
<configureoption name="with-rdkafka" default="autodetect" prompt="librdkafka installation path?"/>
</extsrcrelease>
<changelog>
<release>
<date>2022-06-12</date>
<time>12:00:00</time>
<version>
<release>6.0.2</release>
<api>6.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://opensource.org/licenses/mit-license.php">MIT License</license>
<notes>
## Bugfixes
- Fixed signature of RdKafka\KafkaConsumer::getMetadata() (#521, @arnaud-lb)
</notes>
</release>
<release>
<date>2022-02-15</date>
<time>12:00:00</time>
Expand Down Expand Up @@ -194,8 +211,8 @@

## Improvements
- PHP 8.1 support (@remicollet, @ruudk, @nick-zh)
- Added parameter types (when built with PHP>=8.0) (@arnaud-lb)
- Added tentative return types (when built with PHP>=8.1) (@arnaud-lb)
- Added parameter types (when built with PHP&gt;=8.0) (@arnaud-lb)
- Added tentative return types (when built with PHP&gt;=8.1) (@arnaud-lb)

## Deprecations
- PHP 8.1: Overloading php-rdkafka methods without specifying a return type
Expand Down
2 changes: 1 addition & 1 deletion php_rdkafka.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ PHP_METHOD(RdKafka, __construct);
extern zend_module_entry rdkafka_module_entry;
#define phpext_rdkafka_ptr &rdkafka_module_entry

#define PHP_RDKAFKA_VERSION "6.0.2"
#define PHP_RDKAFKA_VERSION "6.0.3"

extern zend_object_handlers kafka_default_object_handlers;
extern zend_class_entry * ce_kafka_exception;
Expand Down
152 changes: 152 additions & 0 deletions tools/new-package-release.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env php
<?php

const NS = 'http://pear.php.net/dtd/package-2.1';

if (!isset($argv[1])) {
fprintf(STDERR, "Missing version parameter\n");
printUsage();
exit(1);
}

$newVersion = $argv[1];

$doc = new DOMDocument();
if (!$doc->load(__DIR__.'/../package.xml')) {
throw new \Exception('Failed loading package.xml');
}

$releaseNotes = generateReleaseNotes($newVersion);

moveCurrentReleaseToChangelog($doc);
updateCurrentRelease($doc, $newVersion, $releaseNotes);

file_put_contents(__DIR__.'/../package.xml', $doc->saveXML());

function printUsage(): void
{
fprintf(STDERR, "Usage: %s <version>\n", $_SERVER['argv'][0]);
}

function generateReleaseNotes(string $newVersion): string
{
$cmd = sprintf(
'gh api repos/arnaud-lb/php-rdkafka/releases/generate-notes -f tag_name=%s',
escapeshellcmd($newVersion),
);

$result = exec($cmd);
if ($result === false) {
throw new \Exception(sprintf('Command `%s` failed', $cmd));
}

$lines = explode("\n", json_decode($result, true)['body']);

$newLines = [];
$add = false;
foreach ($lines as $line) {
if (str_starts_with($line, '###')) {
$add = true;
$line = substr($line, 1);
} elseif (str_starts_with($line, '##')) {
$add = false;
}
if ($add) {
$line = preg_replace(
'# by (@[^ ]+) in https://github.com/[^ ]+/pull/([0-9]+)#',
' (#\2, \1)',
$line,
);
$line = preg_replace(
'#^\*#',
'-',
$line,
);
$newLines[] = $line;
}
}

return implode("\n", $newLines);
}

function updateCurrentRelease(DOMDocument $doc, string $newVersion, string $releaseNotes): void
{
$date = date('Y-m-d');
$time = date('H:i:s');

$dateElem = findOneElement($doc, '/ns:package/ns:date');
replaceContent($dateElem, $doc->createTextNode($date));

$timeElem = findOneElement($doc, '/ns:package/ns:time');
replaceContent($timeElem, $doc->createTextNode($time));

$versionElem = findOneElement($doc, '/ns:package/ns:version/ns:release');
replaceContent($versionElem, $doc->createTextNode($newVersion));

$notesElem = findOneElement($doc, '/ns:package/ns:notes');
$releaseNotes = rtrim("\n " . str_replace("\n", "\n ", $releaseNotes))."\n ";
replaceContent($notesElem, $doc->createTextNode($releaseNotes));
}

function moveCurrentReleaseToChangelog(DOMDocument $doc): void
{
$oldRelease = $doc->createElementNS(NS, 'release');
$oldRelease->appendChild($doc->createTextNode("\n"));

$nodesToCopy = ['date', 'time', 'version', 'stability', 'license', 'notes'];

foreach ($nodesToCopy as $nodeName) {
$path = sprintf('/ns:package/ns:%s', $nodeName);
$elem = findOneElement($doc, $path);

$elem = $elem->cloneNode(true);

$oldRelease->appendChild($doc->createTextNode(" "));
$oldRelease->appendChild($elem);
$oldRelease->appendChild($doc->createTextNode("\n"));
}

indent($oldRelease, ' ');

$changelogElem = findOneElement($doc, '/ns:package/ns:changelog');
$changelogElem->insertBefore($oldRelease, $changelogElem->firstChild);
$changelogElem->insertBefore($doc->createTextNode("\n "), $oldRelease);
}

function findOneElement(DOMDocument $doc, string $path): DOMElement
{
$xp = new DOMXPath($doc, false);
$xp->registerNamespace('ns', NS);

$list = $xp->evaluate($path);
if ($list->length !== 1) {
throw new \Exception(sprintf(
'XPath expression %s expected to find 1 element, but found %d',
$path,
$list->length,
));
}

return $list->item(0);
}

function indent(DOMElement $elem, string $indentString): void
{
foreach ($elem->childNodes as $node) {
if ($node instanceof DOMText) {
$node->textContent = str_replace("\n", "\n".$indentString, $node->textContent);
} else if ($node instanceof DOMElement) {
indent($node, $indentString);
}
}
}

function replaceContent(DOMElement $elem, DOMNode $newContent): void
{
while ($elem->firstChild !== null) {
$elem->removeChild($elem->firstChild);
}

$elem->appendChild($newContent);
}

0 comments on commit 9fca571

Please sign in to comment.