File: extract-release-notes.php

package info (click to toggle)
phpunit-version 5.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 28,668 kB
  • sloc: php: 98; xml: 22; makefile: 5
file content (46 lines) | stat: -rwxr-xr-x 781 bytes parent folder | download | duplicates (36)
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
#!/usr/bin/env php
<?php declare(strict_types=1);
if ($argc !== 2) {
    print $argv[0] . ' <tag>' . PHP_EOL;

    exit(1);
}

$version = $argv[1];

$file = __DIR__ . '/../../ChangeLog.md';

if (!is_file($file) || !is_readable($file)) {
    print $file . ' cannot be read' . PHP_EOL;

    exit(1);
}

$buffer = '';
$append = false;

foreach (file($file) as $line) {
    if (str_starts_with($line, '## [' . $version . ']')) {
        $append = true;

        continue;
    }

    if ($append && (str_starts_with($line, '## ') || str_starts_with($line, '['))) {
        break;
    }

    if ($append) {
        $buffer .= $line;
    }
}

$buffer = trim($buffer);

if ($buffer === '') {
    print 'Unable to extract release notes' . PHP_EOL;

    exit(1);
}

print $buffer . PHP_EOL;