Skip to content

Commit fc6b411

Browse files
authored
Merge pull request #154 from andrewnicols/MDL-83424-take2
Attempt to support restructured directories
2 parents 9175008 + fdaf841 commit fc6b411

File tree

9 files changed

+76
-8
lines changed

9 files changed

+76
-8
lines changed

runner/main/jobtypes/behat/behat.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ function behat_to_env_file() {
4545
SELENIUMURL_10
4646

4747
WEBSERVER
48+
APACHE_DOCUMENT_ROOT
49+
PUBLICROOT
4850

4951
IONICURL
5052

@@ -151,6 +153,7 @@ function behat_check() {
151153
# Behat job type init.
152154
function behat_config() {
153155
# Apply some defaults.
156+
PUBLICROOT="${PUBLICROOT:-}"
154157
RUNCOUNT="${RUNCOUNT:-1}"
155158
BEHAT_SUITE="${BEHAT_SUITE:-}"
156159
BEHAT_TAGS="${BEHAT_TAGS:-}"
@@ -237,7 +240,7 @@ function behat_initcmd() {
237240

238241
# Build the complete init command.
239242
cmd=(
240-
php admin/tool/behat/cli/init.php
243+
php ${PUBLICROOT}admin/tool/behat/cli/init.php
241244
"${initsuite}"
242245
-j="${BEHAT_PARALLEL}"
243246
--axe
@@ -462,7 +465,7 @@ function behat_main_command() {
462465

463466
# Let's build the complete behat command for the 1st (parallel) run.
464467
_cmd=(
465-
php admin/tool/behat/cli/run.php
468+
php ${PUBLICROOT}admin/tool/behat/cli/run.php
466469
)
467470

468471
# Add the options and profile.
@@ -538,7 +541,7 @@ function behat_rerun_command() {
538541
# and, also, it automatically handles the file system links for the web server.
539542
# (output is a little bit uglier, but consistent with the main run).
540543
_reruncmd=(
541-
php admin/tool/behat/cli/run.php --rerun
544+
php ${PUBLICROOT}admin/tool/behat/cli/run.php --rerun
542545
)
543546

544547
# Add the config, options and profile.

runner/main/jobtypes/phpunit/phpunit.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# PHPUnit needed variables to go to the env file.
2121
function phpunit_to_env_file() {
2222
local env=(
23+
PUBLICROOT
24+
2325
DBTYPE
2426
DBTAG
2527
DBHOST
@@ -157,7 +159,7 @@ function phpunit_initcmd() {
157159
local -n cmd=$1
158160
cmd=(
159161
php
160-
admin/tool/phpunit/cli/init.php
162+
${PUBLICROOT}admin/tool/phpunit/cli/init.php
161163
)
162164
}
163165

runner/main/modules/docker-php/docker-php.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ function docker-php_setup() {
5454
--name "${WEBSERVER}" \
5555
--detach \
5656
--env-file "${ENVIROPATH}" \
57+
-e "APACHE_DOCUMENT_ROOT=${APACHE_DOCUMENT_ROOT}" \
5758
-v "${COMPOSERCACHE}:/var/www/.composer:rw" \
5859
-v "${SHAREDDIR}":/shared \
60+
-v "${BASEDIR}/modules/docker-php/entrypoint":/docker-entrypoint.d \
5961
"${DOCKER_PHP}"
6062

6163
# Ensure that the whole .composer directory is writable to all (www-data needs to write there).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
# Replace the default document root in Apache configuration files with the one set in the environment variable.
4+
# This is needed to make the webserver work with the Moodle codebase for Moodle 5.1 onwards with MDL-83424.
5+
6+
sed -ri -e 's@/var/www/html@${APACHE_DOCUMENT_ROOT}@g' /etc/apache2/sites-available/*.conf
7+
sed -ri -e 's@/var/www/@${APACHE_DOCUMENT_ROOT}@g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

runner/main/modules/moodle-core-copy/moodle-core-copy.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ function moodle-core-copy_check() {
3737
# Moodle core copy module config.
3838
function moodle-core-copy_config() {
3939
# Get the Moodle branch from code, so we can make decisions based on it.
40-
MOODLE_BRANCH=$(grep "\$branch" "${CODEDIR}"/version.php | sed "s/';.*//" | sed "s/^\$.*'//")
40+
if [[ -d "${CODEDIR}/public" ]]; then
41+
MOODLE_BRANCH=$(grep "\$branch" "${CODEDIR}"/public/version.php | sed "s/';.*//" | sed "s/^\$.*'//")
42+
else
43+
MOODLE_BRANCH=$(grep "\$branch" "${CODEDIR}"/version.php | sed "s/';.*//" | sed "s/^\$.*'//")
44+
fi
4145
}
4246

4347
# Moodle core copy module setup.

runner/main/modules/summary/summary.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ function summary_setup() {
5252
echo "== Build Id: ${BUILD_ID}"
5353
echo "== Workspace: ${WORKSPACE}"
5454
echo "== Code directory: ${CODEDIR}"
55+
echo "== Public directory: ${PUBLICROOT}"
5556
echo "== Shared directory: ${SHAREDDIR}"
57+
echo "== APACHE_DOCUMENT_ROOT: ${APACHE_DOCUMENT_ROOT}"
5658
echo "== UUID / Container suffix: ${UUID}"
5759
echo "== Environment: ${ENVIROPATH}"
5860
echo "== GIT commit: ${GIT_COMMIT}"
5961

6062
# Add all the summary information that the job type wants to add.
6163
get_job_to_summary "${JOBTYPE}"
6264
echo "============================================================================"
63-
}
65+
}

runner/main/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ fi
4848

4949
# Base directory where the code is located.
5050
CODEDIR="${CODEDIR:-${WORKSPACE}/moodle}"
51+
APACHE_DOCUMENT_ROOT="${APACHE_DOCUMENT_ROOT:-/var/www/html}"
52+
PUBLICROOT="${PUBLICROOT:-}"
53+
if [[ -d "${CODEDIR}/public" ]]; then
54+
PUBLICROOT="public/"
55+
APACHE_DOCUMENT_ROOT="/var/www/html/public"
56+
fi
5157

5258
# Fail if CODEDIR does not exist.
5359
if [[ ! -d ${CODEDIR} ]]; then

test/helpers/common.bash

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function git_moodle_checkout() {
3737
# Checkout a branch, tag or commit in the moodle.git repository.
3838
# $1: Branch, tag or commit to checkout.
3939
local branch="$1"
40+
local remote="$2"
4041

4142
if [[ -z ${branch} ]]; then
4243
echo "Please, specify a branch, tag or commit to checkout."
@@ -48,8 +49,18 @@ function git_moodle_checkout() {
4849
exit 1
4950
fi
5051

51-
# Checkout the branch or tag.
52-
git -C "${MOODLE_CI_RUNNER_GITDIR}" --git-dir .git checkout -f --quiet "${branch}" || exit 1
52+
53+
if [[ -n ${remote} ]]; then
54+
# Check if the remote is valid.
55+
git -C "${MOODLE_CI_RUNNER_GITDIR}" fetch "${remote}" "${branch}" || {
56+
echo "Unable to fetch ${remote} {$branch}."
57+
exit 1
58+
}
59+
git -C "${MOODLE_CI_RUNNER_GITDIR}" --git-dir .git checkout -f --quiet FETCH_HEAD || exit 1
60+
else
61+
# Checkout the branch or tag.
62+
git -C "${MOODLE_CI_RUNNER_GITDIR}" --git-dir .git checkout -f --quiet "${branch}" || exit 1
63+
fi
5364
}
5465

5566
function launch_runner() {

test/phpunit_test.bats

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,34 @@ teardown() {
8383
assert_output --partial "Running: php vendor/bin/phpunit"
8484
assert_output --partial "== Exit code: 0"
8585
}
86+
87+
@test "PHPUnit tests: run the job for MDL-83424 with filter applied" {
88+
# Set all the required variables.
89+
JOBTYPE="phpunit"
90+
PHP_VERSION="8.4"
91+
DBTYPE="pgsql"
92+
CODEDIR="${MOODLE_CI_RUNNER_GITDIR}"
93+
PHPUNIT_TESTSUITE="mod_label_testsuite"
94+
95+
# Checkout main
96+
run git_moodle_checkout MDL-83424-main https://github.com/andrewnicols/moodle.git
97+
assert_success
98+
99+
# Run the job
100+
run launch_runner
101+
assert_success
102+
assert_output --partial "== JOBTYPE: phpunit"
103+
assert_output --partial "== Moodle branch (version.php): 501"
104+
assert_output --partial "== PHP version: 8.4"
105+
assert_output --partial "== DBTYPE: pgsql"
106+
assert_output --partial "== PHPUNIT_TESTSUITE: mod_label_testsuite"
107+
assert_output --partial "== DBREPLICAS: 0"
108+
assert_output --partial "Setting up docker-caches module..."
109+
assert_output --partial "Initialising Moodle PHPUnit test environment..."
110+
assert_output --partial "Running: php vendor/bin/phpunit"
111+
assert_output --partial "OK"
112+
assert_output --regexp "Tests: [0-9]+"
113+
assert_output --partial "Exporting all docker logs for UUID"
114+
assert_output --partial "Stopping and removing all docker containers"
115+
assert_output --partial "== Exit code: 0"
116+
}

0 commit comments

Comments
 (0)