Skip to content

Commit 4ce009b

Browse files
committed
Add GHA support to moodle-docker
Basically does the same than old Travis runs, with some differences: - I've grouped the jobs into 3 categories (phpunit, behat, app). - Each one has own setup/teardown/test shell script, instead of the previous "mammoth" setup and test scripts, that I've left unmodified - Aiming to get the travis CI runs disabled because they are super slow (we only have 2 concurrent jobs allowed) and, while running, all the other moodlehq repos have to wait. - I'll create an issue to remove travis support once this is accepted and working ok. - Only change that I had to perform to existing stuff is raising the hardcoded sleep of 5 seconds to 10 seconds because I was getting some random failures with MySQL, needing more time to start. - We should move to proper health-checks for database (#160) containers soon, much like app containers (#131).
1 parent fa2b2d9 commit 4ce009b

11 files changed

+378
-1
lines changed

.github/workflows/ci.yml

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
name: moodle-docker CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
PHPUnit:
7+
runs-on: ubuntu-18.04
8+
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
include:
13+
# PostgreSQL (highest, lowest php supported)
14+
- { branch: master, php: "8.0", database: pgsql, suite: phpunit-full } # Full run only for mater.
15+
- { branch: master, php: "7.3", database: pgsql, suite: phpunit-full }
16+
- { branch: MOODLE_311_STABLE, php: "8.0", database: pgsql, suite: phpunit } # Other branches, quicker run.
17+
- { branch: MOODLE_311_STABLE, php: "7.3", database: pgsql, suite: phpunit }
18+
- { branch: MOODLE_310_STABLE, php: "7.4", database: pgsql, suite: phpunit }
19+
- { branch: MOODLE_310_STABLE, php: "7.2", database: pgsql, suite: phpunit }
20+
- { branch: MOODLE_39_STABLE, php: "7.4", database: pgsql, suite: phpunit }
21+
- { branch: MOODLE_39_STABLE, php: "7.2", database: pgsql, suite: phpunit }
22+
# MariaDB (lowest php supported)
23+
- { branch: master, php: "7.3", database: mariadb, suite: phpunit }
24+
- { branch: MOODLE_311_STABLE, php: "7.3", database: mariadb, suite: phpunit }
25+
- { branch: MOODLE_310_STABLE, php: "7.2", database: mariadb, suite: phpunit }
26+
- { branch: MOODLE_39_STABLE, php: "7.2", database: mariadb, suite: phpunit }
27+
# Other databases (highest php supported)
28+
- { branch: master, php: "8.0", database: mssql, suite: phpunit }
29+
- { branch: MOODLE_311_STABLE, php: "8.0", database: mssql, suite: phpunit }
30+
- { branch: MOODLE_310_STABLE, php: "7.4", database: mssql, suite: phpunit }
31+
- { branch: MOODLE_39_STABLE, php: "7.4", database: mssql, suite: phpunit }
32+
- { branch: master, php: "8.0", database: mysql, suite: phpunit }
33+
- { branch: MOODLE_311_STABLE, php: "8.0", database: mysql, suite: phpunit }
34+
- { branch: MOODLE_310_STABLE, php: "7.4", database: mysql, suite: phpunit }
35+
- { branch: MOODLE_39_STABLE, php: "7.4", database: mysql, suite: phpunit }
36+
- { branch: master, php: "8.0", database: oracle, suite: phpunit }
37+
- { branch: MOODLE_311_STABLE, php: "8.0", database: oracle, suite: phpunit }
38+
- { branch: MOODLE_310_STABLE, php: "7.4", database: oracle, suite: phpunit }
39+
- { branch: MOODLE_39_STABLE, php: "7.4", database: oracle, suite: phpunit }
40+
41+
steps:
42+
- name: Checking out moodle-docker
43+
uses: actions/checkout@v2
44+
45+
- name: Checking out moodle
46+
uses: actions/checkout@v2
47+
with:
48+
repository: moodle/moodle
49+
path: moodle
50+
ref: ${{ matrix.branch }}
51+
52+
- name: Prepare moodle-docker environment
53+
run: |
54+
cp config.docker-template.php moodle/config.php
55+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
56+
export MOODLE_DOCKER_PHP_VERSION="${{ matrix.php }}"
57+
export SUITE="${{ matrix.suite }}"
58+
tests/phpunit-setup.sh
59+
60+
- name: Run moodle-docker tests
61+
run: |
62+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
63+
export SUITE="${{ matrix.suite }}"
64+
tests/phpunit-test.sh
65+
66+
- name: Stop moodle-docker
67+
run: |
68+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
69+
export SUITE="${{ matrix.suite }}"
70+
tests/phpunit-teardown.sh
71+
72+
Behat:
73+
runs-on: ubuntu-18.04
74+
75+
strategy:
76+
fail-fast: false
77+
matrix:
78+
include:
79+
# PostgreSQL (highest, lowest php supported)
80+
- { branch: master, php: "8.0", database: pgsql, browser: chrome, suite: behat }
81+
- { branch: master, php: "7.3", database: pgsql, browser: firefox, suite: behat }
82+
- { branch: MOODLE_311_STABLE, php: "8.0", database: pgsql, browser: chrome, suite: behat }
83+
- { branch: MOODLE_311_STABLE, php: "7.3", database: pgsql, browser: firefox, suite: behat }
84+
- { branch: MOODLE_310_STABLE, php: "7.4", database: pgsql, browser: chrome, suite: behat }
85+
- { branch: MOODLE_310_STABLE, php: "7.2", database: pgsql, browser: firefox, suite: behat }
86+
- { branch: MOODLE_39_STABLE, php: "7.4", database: pgsql, browser: chrome, suite: behat }
87+
- { branch: MOODLE_39_STABLE, php: "7.2", database: pgsql, browser: firefox, suite: behat }
88+
# MariaDB (lowest php supported)
89+
- { branch: master, php: "7.3", database: mariadb, browser: chrome, suite: behat }
90+
- { branch: MOODLE_311_STABLE, php: "7.3", database: mariadb, browser: firefox, suite: behat }
91+
- { branch: MOODLE_310_STABLE, php: "7.2", database: mariadb, browser: chrome, suite: behat }
92+
- { branch: MOODLE_39_STABLE, php: "7.2", database: mariadb, browser: firefox, suite: behat }
93+
# Other databases (highest php supported")
94+
- { branch: master, php: "8.0", database: mssql, browser: chrome, suite: behat }
95+
- { branch: MOODLE_311_STABLE, php: "8.0", database: mssql, browser: firefox, suite: behat }
96+
- { branch: MOODLE_310_STABLE, php: "7.4", database: mssql, browser: chrome, suite: behat }
97+
- { branch: MOODLE_39_STABLE, php: "7.4", database: mssql, browser: firefox, suite: behat }
98+
- { branch: master, php: "8.0", database: mysql, browser: chrome, suite: behat }
99+
- { branch: MOODLE_311_STABLE, php: "8.0", database: mysql, browser: firefox, suite: behat }
100+
- { branch: MOODLE_310_STABLE, php: "7.4", database: mysql, browser: chrome, suite: behat }
101+
- { branch: MOODLE_39_STABLE, php: "7.4", database: mysql, browser: firefox, suite: behat }
102+
- { branch: master, php: "8.0", database: oracle, browser: chrome, suite: behat }
103+
- { branch: MOODLE_311_STABLE, php: "8.0", database: oracle, browser: firefox, suite: behat }
104+
- { branch: MOODLE_310_STABLE, php: "7.4", database: oracle, browser: chrome, suite: behat }
105+
- { branch: MOODLE_39_STABLE, php: "7.4", database: oracle, browser: firefox, suite: behat }
106+
107+
steps:
108+
- name: Checking out moodle-docker
109+
uses: actions/checkout@v2
110+
111+
- name: Checking out moodle
112+
uses: actions/checkout@v2
113+
with:
114+
repository: moodle/moodle
115+
path: moodle
116+
ref: ${{ matrix.branch }}
117+
118+
- name: Prepare moodle-docker environment
119+
run: |
120+
cp config.docker-template.php moodle/config.php
121+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
122+
export MOODLE_DOCKER_PHP_VERSION="${{ matrix.php }}"
123+
export SUITE="${{ matrix.suite }}"
124+
export MOODLE_DOCKER_BROWSER="${{ matrix.browser }}"
125+
tests/behat-setup.sh
126+
127+
- name: Run moodle-docker tests
128+
run: |
129+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
130+
export SUITE="${{ matrix.suite }}"
131+
tests/behat-test.sh
132+
133+
- name: Stop moodle-docker
134+
run: |
135+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
136+
export SUITE="${{ matrix.suite }}"
137+
tests/behat-teardown.sh
138+
139+
App:
140+
runs-on: ubuntu-18.04
141+
142+
strategy:
143+
fail-fast: false
144+
matrix:
145+
include:
146+
# PostgreSQL (highest, lowest php supported)
147+
- { branch: master, php: "8.0", database: pgsql, suite: app-development, app-version: "3.9.0"}
148+
- { branch: master, php: "7.3", database: pgsql, suite: app-development, app-version: "3.9.0"}
149+
- { branch: master, php: "8.0", database: pgsql, suite: app, app-version: "3.9.0"}
150+
- { branch: master, php: "7.3", database: pgsql, suite: app, app-version: "3.9.0"}
151+
152+
steps:
153+
- name: Checking out moodle-docker
154+
uses: actions/checkout@v2
155+
156+
- name: Checking out moodle
157+
uses: actions/checkout@v2
158+
with:
159+
repository: moodle/moodle
160+
path: moodle
161+
ref: ${{ matrix.branch }}
162+
163+
- name: Prepare moodle-docker environment
164+
run: |
165+
cp config.docker-template.php moodle/config.php
166+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
167+
export MOODLE_DOCKER_PHP_VERSION="${{ matrix.php }}"
168+
export SUITE="${{ matrix.suite }}"
169+
export MOODLE_DOCKER_APP_VERSION="${{ matrix.app-version }}"
170+
tests/app-setup.sh
171+
172+
- name: Run moodle-docker tests
173+
run: |
174+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
175+
export SUITE="${{ matrix.suite }}"
176+
tests/app-test.sh
177+
178+
- name: Stop moodle-docker
179+
run: |
180+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
181+
export SUITE="${{ matrix.suite }}"
182+
export MOODLE_DOCKER_APP_VERSION="${{ matrix.app-version }}"
183+
tests/app-teardown.sh

bin/moodle-docker-wait-for-db

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ then
2020
sleep 15
2121
done
2222
else
23-
sleep 5
23+
sleep 10
2424
fi

tests/app-setup.sh

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
4+
5+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
6+
export MOODLE_DOCKER_BROWSER="chrome"
7+
8+
if [ "$SUITE" = "app-development" ];
9+
then
10+
export MOODLE_DOCKER_APP_PATH="${basedir}/app"
11+
git clone --branch "v$MOODLE_DOCKER_APP_VERSION" --depth 1 git://github.com/moodlehq/moodleapp $basedir/app
12+
git clone --branch "v$MOODLE_DOCKER_APP_VERSION" --depth 1 git://github.com/moodlehq/moodle-local_moodlemobileapp $basedir/moodle/local/moodlemobileapp
13+
14+
docker run --volume $basedir/app:/app --workdir /app node:11 npm run setup
15+
docker run --volume $basedir/app:/app --workdir /app node:11 npm ci
16+
17+
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
18+
elif [ "$SUITE" = "app" ];
19+
then
20+
git clone --branch "v$MOODLE_DOCKER_APP_VERSION" --depth 1 git://github.com/moodlehq/moodle-local_moodlemobileapp $basedir/moodle/local/moodlemobileapp
21+
22+
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
23+
else
24+
echo "Error, unknown suite '$SUITE'"
25+
exit 1
26+
fi
27+
28+
echo "Pulling docker images"
29+
$basedir/bin/moodle-docker-compose pull
30+
echo "Starting up container"
31+
$basedir/bin/moodle-docker-compose up -d
32+
echo "Waiting for DB to come up"
33+
$basedir/bin/moodle-docker-wait-for-db
34+
echo "Waiting for Moodle app to come up"
35+
$basedir/bin/moodle-docker-wait-for-app
36+
echo "Running: $initcmd"
37+
$basedir/$initcmd

tests/app-teardown.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
4+
5+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
6+
export MOODLE_DOCKER_BROWSER="chrome"
7+
8+
if [ "$SUITE" = "app-development" ];
9+
then
10+
export MOODLE_DOCKER_APP_PATH="${basedir}/app"
11+
elif [ "$SUITE" = "app" ];
12+
then
13+
echo
14+
else
15+
echo "Error, unknown suite '$SUITE'"
16+
exit 1
17+
fi
18+
19+
echo "Stopping down container"
20+
$basedir/bin/moodle-docker-compose down

tests/app-test.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
5+
6+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
7+
8+
if [ "$SUITE" = "app" ] || [ "$SUITE" = "app-development" ];
9+
then
10+
testcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/run.php --tags=@app&&@mod_login"
11+
else
12+
echo "Error, unknown suite '$SUITE'"
13+
exit 1
14+
fi
15+
16+
echo "Running: $testcmd"
17+
$basedir/$testcmd

tests/behat-setup.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
4+
5+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
6+
7+
if [ "$SUITE" = "behat" ];
8+
then
9+
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
10+
else
11+
echo "Error, unknown suite '$SUITE'"
12+
exit 1
13+
fi
14+
15+
echo "Pulling docker images"
16+
$basedir/bin/moodle-docker-compose pull
17+
echo "Starting up container"
18+
$basedir/bin/moodle-docker-compose up -d
19+
echo "Waiting for DB to come up"
20+
$basedir/bin/moodle-docker-wait-for-db
21+
echo "Running: $initcmd"
22+
$basedir/$initcmd

tests/behat-teardown.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
4+
5+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
6+
7+
if [ "$SUITE" = "behat" ];
8+
then
9+
echo
10+
else
11+
echo "Error, unknown suite '$SUITE'"
12+
exit 1
13+
fi
14+
15+
echo "Stopping down container"
16+
$basedir/bin/moodle-docker-compose down

tests/behat-test.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
5+
6+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
7+
8+
if [ "$SUITE" = "behat" ];
9+
then
10+
testcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/run.php --tags=@auth_manual"
11+
else
12+
echo "Error, unknown suite '$SUITE'"
13+
exit 1
14+
fi
15+
16+
echo "Running: $testcmd"
17+
$basedir/$testcmd

tests/phpunit-setup.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
4+
5+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
6+
7+
if [ "$SUITE" = "phpunit" ];
8+
then
9+
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/phpunit/cli/init.php"
10+
elif [ "$SUITE" = "phpunit-full" ];
11+
then
12+
export MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES=true
13+
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/phpunit/cli/init.php"
14+
else
15+
echo "Error, unknown suite '$SUITE'"
16+
exit 1
17+
fi
18+
19+
echo "Pulling docker images"
20+
$basedir/bin/moodle-docker-compose pull
21+
echo "Starting up container"
22+
$basedir/bin/moodle-docker-compose up -d
23+
echo "Waiting for DB to come up"
24+
$basedir/bin/moodle-docker-wait-for-db
25+
echo "Running: $initcmd"
26+
$basedir/$initcmd

tests/phpunit-teardown.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
4+
5+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
6+
7+
if [ "$SUITE" = "phpunit" ];
8+
then
9+
echo
10+
elif [ "$SUITE" = "phpunit-full" ];
11+
then
12+
export MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES=true
13+
else
14+
echo "Error, unknown suite '$SUITE'"
15+
exit 1
16+
fi
17+
18+
echo "Stopping down container"
19+
$basedir/bin/moodle-docker-compose down

tests/phpunit-test.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
5+
6+
export MOODLE_DOCKER_WWWROOT="${basedir}/moodle"
7+
8+
if [ "$SUITE" = "phpunit" ];
9+
then
10+
testcmd="bin/moodle-docker-compose exec -T webserver vendor/bin/phpunit --filter core_dml_testcase"
11+
elif [ "$SUITE" = "phpunit-full" ];
12+
then
13+
testcmd="bin/moodle-docker-compose exec -T webserver vendor/bin/phpunit --verbose"
14+
else
15+
echo "Error, unknown suite '$SUITE'"
16+
exit 1
17+
fi
18+
19+
echo "Running: $testcmd"
20+
$basedir/$testcmd

0 commit comments

Comments
 (0)