Skip to content

Commit 5c66cac

Browse files
authored
Merge pull request #103 from andrewnicols/83424
MDL-83424 support new directory structure
2 parents 7dcd4b6 + d291398 commit 5c66cac

File tree

6 files changed

+113
-5
lines changed

6 files changed

+113
-5
lines changed

bumpversions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
$rc = Helper::getOption($options, 'r', 'rc');
4141
$date = Helper::getOption($options, 'd', 'date');
4242
$isdevbranch = (bool) Helper::getOption($options, 'i', 'isdevbranch');
43-
$path = rtrim($path, '/') . '/version.php';
43+
44+
// Find the version.php.
45+
$path = Helper::getVersionPath($path);
4446

4547
$release = Helper::bumpVersion($path, $branch, $type, $rc, $date, $isdevbranch);
4648
$result = 0;

get_next_version_number.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
$rc = Helper::getOption($options, 'r', 'rc');
4242
$date = Helper::getOption($options, 'd', 'date');
4343
$isdevbranch = (bool) Helper::getOption($options, 'i', 'isdevbranch');
44-
$path = rtrim($path, '/') . '/version.php';
44+
45+
// Find the version.php.
46+
$path = Helper::getVersionPath($path);
4547

4648
$currentVersion = VersionInfo::fromVersionFile($path);
4749
$nextVersion = $currentVersion->getNextVersion(

prerelease.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ bump_version() {
118118
output " - ${R}Failed to bump version file [$outcome].${N}"
119119
_pushup=false
120120
else
121-
git add version.php
121+
versionpath=version.php
122+
if [ ! -f $versionpath ]; then
123+
versionpath=public/version.php
124+
fi
125+
126+
git add $versionpath
122127
if git_staged_changes ; then
123128
if $weekly ; then
124129
git commit --quiet -m "weekly release $release"

release.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,13 @@ skippedbranches=()
121121
output
122122
output "${normal}You are about to push:"
123123
for b in "${allbranches[@]}" ; do
124+
versionpath=version.php
125+
if [ ! -f $versionpath ]; then
126+
versionpath=public/version.php
127+
fi
128+
124129
# Search for a 'real' release by ensuring the top commit on version.php changes $release and was recent.
125-
releasebumped=$(git show --since='8 hours ago' -n1 origin/${b} version.php | grep "+\$release\s*=\s*")
130+
releasebumped=$(git show --since='8 hours ago' -n1 origin/${b} $versionpath | grep "+\$release\s*=\s*")
126131
if [[ -n ${releasebumped} || $_skip_version_check ]]; then
127132
output "${G}$b: ${normal}$(git log -n1 --pretty=format:"%s (%an %ar)" origin/$b)"
128133
# Check if between the last commit in the branch and now, it has been PUBLISHING_TIME (UTC)

src/Helper.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Helper
3030
/**
3131
* Bump the version.
3232
*
33-
* @param string $path The path to the versio file
33+
* @param string $path The path to the version file
3434
* @param string $branch The branch name to set
3535
* @param string $type The type of release
3636
* @param string $rc If a release candidate, the RC number
@@ -60,6 +60,30 @@ public static function bumpVersion(
6060
return $newVersionInfo->release;
6161
}
6262

63+
/**
64+
* Get the path to the version file.
65+
*
66+
* @param string $path Path to the Moodle root
67+
* @return string Path to version.php
68+
* @throws \ValueError if no version.php could be found
69+
*/
70+
public static function getVersionPath(
71+
string $path,
72+
): string {
73+
$possibles = [
74+
rtrim($path, '/') . '/public/version.php',
75+
rtrim($path, '/') . '/version.php',
76+
];
77+
78+
foreach ($possibles as $possible) {
79+
if (file_exists($possible)) {
80+
return $possible;
81+
}
82+
}
83+
84+
throw new \ValueError("Unable to find a version.php in {$path}");
85+
}
86+
6387
/**
6488
* Determine the next branch number based on the current one.
6589
*

tests/unit/HelperTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,4 +420,74 @@ public static function invalidOptionProvider(): array
420420
],
421421
];
422422
}
423+
424+
#[DataProvider('getVersionPathProvider')]
425+
public function testGetVersionPath(
426+
array $structure,
427+
string $path,
428+
?string $expected,
429+
): void {
430+
$root = vfsStream::setup('root', structure: $structure);
431+
432+
if ($expected === null) {
433+
$this->expectException(\ValueError::class);
434+
$this->expectExceptionMessage("Unable to find a version.php in {$path}");
435+
Helper::getVersionPath($path);
436+
} else {
437+
$this->assertSame($expected, Helper::getVersionPath($path));
438+
}
439+
}
440+
441+
public static function getVersionPathProvider(): \Generator
442+
{
443+
yield 'Valid path' => [
444+
'structure' => [
445+
'version.php' => '<?php // Version file content.',
446+
],
447+
'path' => vfsStream::url('root'),
448+
'expected' => vfsStream::url('root/version.php'),
449+
];
450+
451+
yield 'Valid path with trailing slash' => [
452+
'structure' => [
453+
'version.php' => '<?php // Version file content.',
454+
],
455+
'path' => vfsStream::url('root/'),
456+
'expected' => vfsStream::url('root/version.php'),
457+
];
458+
459+
yield 'Valid path in public' => [
460+
'structure' => [
461+
'public' => [
462+
'version.php' => '<?php // Version file content.',
463+
],
464+
],
465+
'path' => vfsStream::url('root'),
466+
'expected' => vfsStream::url('root/public/version.php'),
467+
];
468+
469+
yield 'Valid path in public with trailing slash' => [
470+
'structure' => [
471+
'public' => [
472+
'version.php' => '<?php // Version file content.',
473+
],
474+
],
475+
'path' => vfsStream::url('root/'),
476+
'expected' => vfsStream::url('root/public/version.php'),
477+
];
478+
479+
yield 'Invalid path' => [
480+
'structure' => [],
481+
'path' => vfsStream::url('root'),
482+
'expected' => null,
483+
];
484+
485+
yield 'Invalid path in public' => [
486+
'structure' => [
487+
'public' => [],
488+
],
489+
'path' => vfsStream::url('root'),
490+
'expected' => null,
491+
];
492+
}
423493
}

0 commit comments

Comments
 (0)