Skip to content

Commit d20bde0

Browse files
committed
added changelog generator
1 parent 6bf3443 commit d20bde0

File tree

4 files changed

+676
-3
lines changed

4 files changed

+676
-3
lines changed

.github/workflows/publish.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ jobs:
3838

3939
- name: Build docs
4040
run: ./vendor/bin/robo build:docs
41-
41+
42+
- name: Build changelog
43+
run: ./vendor/bin/robo changelog
44+
env:
45+
GH_PAT: ${{ secrets.GH_PAT }}
46+
4247
- name: Publish docs
4348
run: ./vendor/bin/robo publish
4449

RoboFile.php

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function changelog() {
410410
->run();
411411
}
412412

413-
protected function processChangelog()
413+
protected function oldProcessChangelog()
414414
{
415415
$sortByVersionDesc = function (\SplFileInfo $a, \SplFileInfo $b) {
416416
$pattern = '/^CHANGELOG-(\d+\.(?:x|\d+)).md$/';
@@ -523,6 +523,11 @@ public function buildPhar56()
523523

524524
}
525525

526+
public function findReleases()
527+
{
528+
529+
}
530+
526531
public function release()
527532
{
528533
$version = self::STABLE_BRANCH . '.' . date('Ymd');
@@ -605,6 +610,73 @@ private function packPhar($pharFileName)
605610
$pharTask->run();
606611
}
607612

613+
public function processChangelog()
614+
{
615+
$client = new \Github\Client();
616+
$token = getenv('GH_PAT');
617+
if ($token) {
618+
$client->authenticate(getenv('GH_PAT'), null, \Github\Client::AUTH_ACCESS_TOKEN);
619+
}
620+
$codeceptionReleases = $client->repo()->releases()->all('codeception', 'Codeception');
621+
$moduleReleases = [];
622+
623+
$repositories = $client->repos()->org('Codeception', ['per_page' => 100]);
624+
foreach ($repositories as $repository) {
625+
if ($repository['name'] !== 'Codeception' && !str_starts_with($repository['name'], 'module-')) continue;
626+
$this->say($repository['name']);
627+
if ($repository['disabled'] || $repository['archived']) continue;
628+
try {
629+
$release = $client->repo()->releases()->latest('codeception', $repository['name']);
630+
$release['repo'] = $repository['name'];
631+
$moduleReleases[]= $release;
632+
} catch (\Exception $err) {
633+
// $this->say("Repository not available " . $repository['name']);
634+
// $this->say($err->getMessage());
635+
}
636+
}
637+
638+
$releases = array_merge($codeceptionReleases, $moduleReleases);
639+
usort($releases, function($r1, $r2) {
640+
return strtotime($r1['published_at']) > strtotime($r2['published_at']) ? -1 : 1;
641+
});
642+
643+
$changelog = "";
644+
645+
foreach ($releases as $release) {
646+
$repo = $release['repo'] ?? 'Codeception';
647+
$isModule = isset($release['repo']);
648+
$changelog .= sprintf("\n\n### 🎉 %s %s: %s\n\n", $repo, $release['tag_name'], $release['name']);
649+
650+
$changelog .= sprintf("> Released by **[![](%s) %s](%s) at %s**\n",
651+
$release['author']['avatar_url'] . '&s=16',
652+
$release['author']['login'],
653+
$release['author']['html_url'],
654+
$release['published_at']
655+
);
656+
657+
$body = $release['body'];
658+
//user
659+
660+
$body = preg_replace('~\s@([\w-]+)~', ' **[$1](https://github.com/$1)**', $body);
661+
//issue
662+
$body = preg_replace(
663+
'~#(\d+)~',
664+
"[#$1](https://github.com/Codeception/$repo/issues/$1)",
665+
$body
666+
);
667+
668+
$body .= "\n\n[🦑 Repository](https://github.com/Codeception/$repo) ";
669+
$body .= "| [📦 Releases](https://github.com/Codeception/$repo/releases) ";
670+
if ($isModule) {
671+
$body .= "| [📖 Module Docs](/docs/modules/$repo) ";
672+
}
673+
$changelog .= "\n$body\n";
674+
675+
}
676+
677+
return $changelog;
678+
}
679+
608680
public function updateBuildsPage()
609681
{
610682
$sortByVersion = function (\SplFileInfo $a, \SplFileInfo $b) {
@@ -677,4 +749,6 @@ private function updateVersionFile($pharFile, $versionFile)
677749
}
678750
$this->taskWriteToFile($versionFile)->text($hash)->run();
679751
}
752+
753+
680754
}

0 commit comments

Comments
 (0)