Skip to content

Commit 47c4e50

Browse files
committed
Ensure update-history can find the root directory when installed via composer
1 parent 36af667 commit 47c4e50

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Release History
22

33
## update-history x.x.x (not yet released)
4+
* Bug fixes
45

56
## update-history 1.0.0
67

bin/update-history

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
<?php declare(strict_types=1);
33

44
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
5-
require __DIR__ . '/../vendor/autoload.php';
6-
} elseif (file_exists(__DIR__ . '/../../../autoload.php')) {
7-
require __DIR__ . '/../../../autoload.php';
5+
# Running from own package
6+
$root = __DIR__ . '/../';
7+
} elseif (file_exists(__DIR__ . '/../../../../vendor/autoload.php')) {
8+
# Running from vendor/wikimedia/update-history
9+
$root = __DIR__ . '/../../../../';
810
} else {
9-
echo 'Project dependencies need to be installed using composer.';
11+
error_log('Project dependencies need to be installed using composer.');
1012
exit(1);
1113
}
14+
require "$root/vendor/autoload.php";
1215

1316
global $argv;
1417

1518
$which = $argv[1] ?? 'patch';
16-
\Wikimedia\UpdateHistory\UpdateHistory::main( $which );
19+
\Wikimedia\UpdateHistory\UpdateHistory::main( $root, $which );

src/UpdateHistory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
class UpdateHistory {
1010
/**
1111
* Main entry point.
12+
* @param string $root Package root (where the HISTORY.md file is found)
1213
* @param string $which One of 'patch', 'minor', or 'major'.
1314
* @return int Exit code: zero on success, non-zero on failure.
1415
*/
15-
public static function main( string $which = 'patch' ): int {
16-
$changeLogPath = __DIR__ . '/../HISTORY.md';
16+
public static function main( string $root, string $which = 'patch' ): int {
17+
$changeLogPath = "$root/HISTORY.md";
1718
$changeLog = file_get_contents( $changeLogPath );
1819
$changeLog = preg_replace_callback(
1920
'/^(#+)( \S+)? (x\.x\.x|\d+\.\d+\.\d+)(.*)$/m',

0 commit comments

Comments
 (0)