Skip to content

Commit 609de1a

Browse files
authored
Merge pull request #359 from andrewnicols/83424-followups
Support public directory for checks (MDL-83424)
2 parents b3a101d + 1421db4 commit 609de1a

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

list_valid_components/list_valid_components.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@ done
2424
# calculate some variables
2525
mydir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2626

27+
if [[ -d "${gitdir}/public" || -f "${gitdir}/public/version.php" ]]; then
28+
# If we have public directory, then use it as rootdir
29+
rootdir="${gitdir}/public"
30+
echo "+ INFO: Using public directory as rootdir: ${rootdir}"
31+
else
32+
rootdir="${gitdir}"
33+
echo "+ INFO: Using gitdir as rootdir: ${gitdir}"
34+
fi
35+
2736
# Since Moodle 2.6 we don't need to install the moodle site nor copy the php script to it.
28-
if [[ -f "${gitdir}/lib/classes/component.php" ]]; then
37+
if [[ -f "${rootdir}/lib/classes/component.php" ]]; then
2938
cd ${mydir}
30-
${phpcmd} list_valid_components.php --basedir="${gitdir}" --absolute=true
39+
${phpcmd} list_valid_components.php --basedir="${rootdir}" --absolute=true
3140
exitstatus=${PIPESTATUS[0]}
3241
if [ $exitstatus -ne 0 ]; then
3342
echo "Problem executing the >= 2.6 alternative"

verify_phpunit_xml/create_phpunit_xml.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,28 @@
7979
cli_error('Something went wrong. Components not loaded from ' . $options['basedir']);
8080
}
8181

82+
if (file_exists("{$options['basedir']}/public/version.php")) {
83+
$dirroot = "{$options['basedir']}/public";
84+
} else {
85+
$dirroot = $options['basedir'];
86+
}
87+
8288
// We need to register the Moodle autoloader.
83-
require_once($options['basedir'] . '/lib/classes/component.php');
89+
require_once("{$dirroot}/lib/classes/component.php");
8490
spl_autoload_register([\core_component::class, 'classloader']);
8591

8692
// Now, let's invoke phpunit utils to generate the phpunit.xml file
8793

8894
// We need to load a few things manually.
89-
require_once($options['basedir'] . '/lib/phpunit/classes/util.php');
95+
require_once("{$dirroot}/lib/phpunit/classes/util.php");
9096

9197
if (!class_exists(\core\output\core_renderer::class)) {
9298
// From Moodle 4.5 we start to autoload the output components and including outputcomponents.php will throw an exception.
9399
// If the core_renderer class can be autoloaded then we do not need to include outputcomponents.php.
94-
require_once($options['basedir'] . '/lib/outputcomponents.php');
100+
require_once("{$dirroot}/lib/outputcomponents.php");
95101
}
96102

97-
require_once($options['basedir'] . '/lib/testing/lib.php');
103+
require_once("{$dirroot}/lib/testing/lib.php");
98104
phpunit_util::build_config_file();
99105

100106
// We are done, end here.

versions_check_set/versions_check_set.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,18 @@ else
5555
echo "+ INFO: Not applying versions interval check (betweenversions environment variable)" >> "${resultfile}"
5656
fi
5757

58+
if [[ -d "${gitdir}/public" || -f "${gitdir}/public/version.php" ]]; then
59+
# If we have public directory, then use it as rootdir
60+
rootdir="${gitdir}/public"
61+
echo "+ INFO: Using public directory as rootdir: ${rootdir}" >> "${resultfile}"
62+
else
63+
rootdir="${gitdir}"
64+
echo "+ INFO: Using gitdir as rootdir: ${gitdir}" >> "${resultfile}"
65+
fi
66+
5867
# First of all, guess the current branch from main version.php file ($branch). We'll be using
5968
# it to decide about different checks later.
60-
currentbranch="$( grep "\$branch.*=.*;" "${gitdir}/version.php" || true )"
69+
currentbranch="$( grep "\$branch.*=.*;" "${rootdir}/version.php" || true )"
6170
if [ -z "${currentbranch}" ]; then
6271
echo "+ ERROR: Main version.php file is missing: \$branch = 'xx' line." >> "${resultfile}"
6372
elif [[ ${currentbranch} =~ branch\ *=\ *.([0-9]{2,3}).\; ]]; then
@@ -75,11 +84,15 @@ fi
7584
# path (full or null)
7685
${mydir}/../list_valid_components/list_valid_components.sh > "${WORKSPACE}/valid_components.txt"
7786

78-
# Find all the version.php files
87+
# Find all the version.php files in the gitdir.
88+
# Note: In 501 and earlier the version.php files were in the root of the gitdir.
89+
# In 501 and later they are in the public directory.
90+
# In future plugins may be in the root directory and not public.
91+
# So we need to find all version.php files in the gitdir.
7992
allfiles=$( find "${gitdir}" -name version.php | awk -F "/" '{print NF-1"\t"$0}' | sort -n | cut -f 2- )
8093

8194
# version.php files to ignore
82-
ignorefiles="(local/(ci|moodlecheck)/version.php|.*/tests/fixtures/.*/version.php)"
95+
ignorefiles="(public/)?(local/(ci|moodlecheck)/version.php|.*/tests/fixtures/.*/version.php)"
8396

8497
# Perform various checks with the version.php files
8598
for i in ${allfiles}; do
@@ -98,9 +111,9 @@ for i in ${allfiles}; do
98111

99112
# Calculate prefix for all the regexp operations below
100113
prefix='\$plugin->'
101-
if [ "${i}" == "${gitdir}/version.php" ]; then
114+
if [ "${i}" == "${rootdir}/version.php" ]; then
102115
prefix='\$'
103-
elif [[ "${i}" =~ ${gitdir}/mod/[^/]*/version.php ]]; then
116+
elif [[ "${i}" =~ ${rootdir}/mod/[^/]*/version.php ]]; then
104117
# Before 2.7, both "module" and "plugin" were allowed in core for activity modules. For 2.7 and up
105118
# only the default "plugin" is allowed.
106119
if [[ "${currentbranch}" -lt "27" ]]; then
@@ -183,7 +196,7 @@ for i in ${allfiles}; do
183196
fi
184197

185198
# If we are in main version.php
186-
if [ "${i}" == "${gitdir}/version.php" ]; then
199+
if [[ "${i}" == "${gitdir}/version.php" || "${i}" == "${gitdir}/public/version.php" ]]; then
187200
mainversion=${version}
188201

189202
mainrelease="$( grep "${prefix}release.*=.*;" ${i} || true )"
@@ -366,12 +379,12 @@ for i in ${allfiles}; do
366379
done
367380

368381
# Now, look for backup/backup.class.php to ensure it matches main /version.php
369-
echo "- ${gitdir}/backup/backup.class.php:" >> "${resultfile}"
370-
if [ ! -f "${gitdir}/backup/backup.class.php" ]; then
382+
echo "- ${rootdir}/backup/backup.class.php:" >> "${resultfile}"
383+
if [ ! -f "${rootdir}/backup/backup.class.php" ]; then
371384
echo " + ERROR: File backup/backup.class.php not found" >> "${resultfile}"
372385
else
373386
# - backup::VERSION must be always >= $version (8 first digits comparison)
374-
backupversion="$( grep "const.*VERSION.*=.*;" "${gitdir}/backup/backup.class.php" || true )"
387+
backupversion="$( grep "const.*VERSION.*=.*;" "${rootdir}/backup/backup.class.php" || true )"
375388
if [ -z "${backupversion}" ]; then
376389
echo " + ERROR: backup/backup.class.php is missing: const VERSION = XXXXX line." >> "${resultfile}"
377390
fi
@@ -398,7 +411,7 @@ else
398411
fi
399412

400413
# - backup::RELEASE must match $release (X.Y only)
401-
backuprelease="$( grep "const.*RELEASE.*=.*;" "${gitdir}/backup/backup.class.php" || true )"
414+
backuprelease="$( grep "const.*RELEASE.*=.*;" "${rootdir}/backup/backup.class.php" || true )"
402415
if [ -z "${backuprelease}" ]; then
403416
echo " + ERROR: backup/backup.class.php is missing: const RELEASE = 'X.Y' line." >> "${resultfile}"
404417
fi
@@ -448,7 +461,7 @@ if [ ! -z "${setversion}" ] && (($count == 0)); then
448461
fi
449462
# Skip the main version.php file. Let's force to perform manual update there
450463
# (without it, upgrade won't work)
451-
if [ "${i}" == "${gitdir}/version.php" ]; then
464+
if [ "${i}" == "${rootdir}/version.php" ]; then
452465
continue
453466
fi
454467
echo "- ${i}:" >> "${resultfile}"
@@ -460,7 +473,7 @@ if [ ! -z "${setversion}" ] && (($count == 0)); then
460473
perl -p -i -e "${replaceregex}" ${i}
461474
done
462475
# also the backup/backup.class.php file
463-
i=${gitdir}/backup/backup.class.php
476+
i=${rootdir}/backup/backup.class.php
464477
echo "- ${i}:" >> "${resultfile}"
465478
replaceregex="s/(const *VERSION *= *)([0-9]{10}(\.[0-9]{2})?)/\${1}${setversion}/g"
466479
perl -p -i -e "${replaceregex}" ${i}

0 commit comments

Comments
 (0)