diff --git a/bumpversions.php b/bumpversions.php index b337e61..efa540c 100644 --- a/bumpversions.php +++ b/bumpversions.php @@ -40,7 +40,9 @@ $rc = Helper::getOption($options, 'r', 'rc'); $date = Helper::getOption($options, 'd', 'date'); $isdevbranch = (bool) Helper::getOption($options, 'i', 'isdevbranch'); - $path = rtrim($path, '/') . '/version.php'; + + // Find the version.php. + $path = Helper::getVersionPath($path); $release = Helper::bumpVersion($path, $branch, $type, $rc, $date, $isdevbranch); $result = 0; diff --git a/get_next_version_number.php b/get_next_version_number.php index 6a2d651..a6cee1f 100644 --- a/get_next_version_number.php +++ b/get_next_version_number.php @@ -41,7 +41,9 @@ $rc = Helper::getOption($options, 'r', 'rc'); $date = Helper::getOption($options, 'd', 'date'); $isdevbranch = (bool) Helper::getOption($options, 'i', 'isdevbranch'); -$path = rtrim($path, '/') . '/version.php'; + +// Find the version.php. +$path = Helper::getVersionPath($path); $currentVersion = VersionInfo::fromVersionFile($path); $nextVersion = $currentVersion->getNextVersion( diff --git a/prerelease.sh b/prerelease.sh index c82e6f8..300f2fb 100755 --- a/prerelease.sh +++ b/prerelease.sh @@ -118,7 +118,12 @@ bump_version() { output " - ${R}Failed to bump version file [$outcome].${N}" _pushup=false else - git add version.php + versionpath=version.php + if [ ! -f $versionpath ]; then + versionpath=public/version.php + fi + + git add $versionpath if git_staged_changes ; then if $weekly ; then git commit --quiet -m "weekly release $release" diff --git a/release.sh b/release.sh index bdda55f..156bc54 100755 --- a/release.sh +++ b/release.sh @@ -121,8 +121,13 @@ skippedbranches=() output output "${normal}You are about to push:" for b in "${allbranches[@]}" ; do + versionpath=version.php + if [ ! -f $versionpath ]; then + versionpath=public/version.php + fi + # Search for a 'real' release by ensuring the top commit on version.php changes $release and was recent. - releasebumped=$(git show --since='8 hours ago' -n1 origin/${b} version.php | grep "+\$release\s*=\s*") + releasebumped=$(git show --since='8 hours ago' -n1 origin/${b} $versionpath | grep "+\$release\s*=\s*") if [[ -n ${releasebumped} || $_skip_version_check ]]; then output "${G}$b: ${normal}$(git log -n1 --pretty=format:"%s (%an %ar)" origin/$b)" # Check if between the last commit in the branch and now, it has been PUBLISHING_TIME (UTC) diff --git a/src/Helper.php b/src/Helper.php index 368bf4b..8772c4f 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -30,7 +30,7 @@ class Helper /** * Bump the version. * - * @param string $path The path to the versio file + * @param string $path The path to the version file * @param string $branch The branch name to set * @param string $type The type of release * @param string $rc If a release candidate, the RC number @@ -60,6 +60,30 @@ public static function bumpVersion( return $newVersionInfo->release; } + /** + * Get the path to the version file. + * + * @param string $path Path to the Moodle root + * @return string Path to version.php + * @throws \ValueError if no version.php could be found + */ + public static function getVersionPath( + string $path, + ): string { + $possibles = [ + rtrim($path, '/') . '/public/version.php', + rtrim($path, '/') . '/version.php', + ]; + + foreach ($possibles as $possible) { + if (file_exists($possible)) { + return $possible; + } + } + + throw new \ValueError("Unable to find a version.php in {$path}"); + } + /** * Determine the next branch number based on the current one. * diff --git a/tests/unit/HelperTest.php b/tests/unit/HelperTest.php index 63d8763..3a5b3c0 100644 --- a/tests/unit/HelperTest.php +++ b/tests/unit/HelperTest.php @@ -420,4 +420,74 @@ public static function invalidOptionProvider(): array ], ]; } + + #[DataProvider('getVersionPathProvider')] + public function testGetVersionPath( + array $structure, + string $path, + ?string $expected, + ): void { + $root = vfsStream::setup('root', structure: $structure); + + if ($expected === null) { + $this->expectException(\ValueError::class); + $this->expectExceptionMessage("Unable to find a version.php in {$path}"); + Helper::getVersionPath($path); + } else { + $this->assertSame($expected, Helper::getVersionPath($path)); + } + } + + public static function getVersionPathProvider(): \Generator + { + yield 'Valid path' => [ + 'structure' => [ + 'version.php' => ' vfsStream::url('root'), + 'expected' => vfsStream::url('root/version.php'), + ]; + + yield 'Valid path with trailing slash' => [ + 'structure' => [ + 'version.php' => ' vfsStream::url('root/'), + 'expected' => vfsStream::url('root/version.php'), + ]; + + yield 'Valid path in public' => [ + 'structure' => [ + 'public' => [ + 'version.php' => ' vfsStream::url('root'), + 'expected' => vfsStream::url('root/public/version.php'), + ]; + + yield 'Valid path in public with trailing slash' => [ + 'structure' => [ + 'public' => [ + 'version.php' => ' vfsStream::url('root/'), + 'expected' => vfsStream::url('root/public/version.php'), + ]; + + yield 'Invalid path' => [ + 'structure' => [], + 'path' => vfsStream::url('root'), + 'expected' => null, + ]; + + yield 'Invalid path in public' => [ + 'structure' => [ + 'public' => [], + ], + 'path' => vfsStream::url('root'), + 'expected' => null, + ]; + } }