Skip to content

Commit 36fe4b0

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 36fe4b0

11 files changed

+371
-1
lines changed

.github/workflows/ci.yml

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
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_WWWROOT="${PWD}/moodle"
56+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
57+
export MOODLE_DOCKER_PHP_VERSION="${{ matrix.php }}"
58+
export SUITE="${{ matrix.suite }}"
59+
tests/phpunit-setup.sh
60+
61+
- name: Run moodle-docker tests
62+
run: |
63+
export MOODLE_DOCKER_WWWROOT="${PWD}/moodle"
64+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
65+
export SUITE="${{ matrix.suite }}"
66+
tests/phpunit-test.sh
67+
68+
- name: Stop moodle-docker
69+
run: |
70+
export MOODLE_DOCKER_WWWROOT="${PWD}/moodle"
71+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
72+
export SUITE="${{ matrix.suite }}"
73+
tests/phpunit-teardown.sh
74+
75+
Behat:
76+
runs-on: ubuntu-18.04
77+
78+
strategy:
79+
fail-fast: false
80+
matrix:
81+
include:
82+
# PostgreSQL (highest, lowest php supported)
83+
- { branch: master, php: "8.0", database: pgsql, browser: chrome, suite: behat }
84+
- { branch: master, php: "7.3", database: pgsql, browser: firefox, suite: behat }
85+
- { branch: MOODLE_311_STABLE, php: "8.0", database: pgsql, browser: chrome, suite: behat }
86+
- { branch: MOODLE_311_STABLE, php: "7.3", database: pgsql, browser: firefox, suite: behat }
87+
- { branch: MOODLE_310_STABLE, php: "7.4", database: pgsql, browser: chrome, suite: behat }
88+
- { branch: MOODLE_310_STABLE, php: "7.2", database: pgsql, browser: firefox, suite: behat }
89+
- { branch: MOODLE_39_STABLE, php: "7.4", database: pgsql, browser: chrome, suite: behat }
90+
- { branch: MOODLE_39_STABLE, php: "7.2", database: pgsql, browser: firefox, suite: behat }
91+
# MariaDB (lowest php supported)
92+
- { branch: master, php: "7.3", database: mariadb, browser: chrome, suite: behat }
93+
- { branch: MOODLE_311_STABLE, php: "7.3", database: mariadb, browser: firefox, suite: behat }
94+
- { branch: MOODLE_310_STABLE, php: "7.2", database: mariadb, browser: chrome, suite: behat }
95+
- { branch: MOODLE_39_STABLE, php: "7.2", database: mariadb, browser: firefox, suite: behat }
96+
# Other databases (highest php supported")
97+
- { branch: master, php: "8.0", database: mssql, browser: chrome, suite: behat }
98+
- { branch: MOODLE_311_STABLE, php: "8.0", database: mssql, browser: firefox, suite: behat }
99+
- { branch: MOODLE_310_STABLE, php: "7.4", database: mssql, browser: chrome, suite: behat }
100+
- { branch: MOODLE_39_STABLE, php: "7.4", database: mssql, browser: firefox, suite: behat }
101+
- { branch: master, php: "8.0", database: mysql, browser: chrome, suite: behat }
102+
- { branch: MOODLE_311_STABLE, php: "8.0", database: mysql, browser: firefox, suite: behat }
103+
- { branch: MOODLE_310_STABLE, php: "7.4", database: mysql, browser: chrome, suite: behat }
104+
- { branch: MOODLE_39_STABLE, php: "7.4", database: mysql, browser: firefox, suite: behat }
105+
- { branch: master, php: "8.0", database: oracle, browser: chrome, suite: behat }
106+
- { branch: MOODLE_311_STABLE, php: "8.0", database: oracle, browser: firefox, suite: behat }
107+
- { branch: MOODLE_310_STABLE, php: "7.4", database: oracle, browser: chrome, suite: behat }
108+
- { branch: MOODLE_39_STABLE, php: "7.4", database: oracle, browser: firefox, suite: behat }
109+
110+
steps:
111+
- name: Checking out moodle-docker
112+
uses: actions/checkout@v2
113+
114+
- name: Checking out moodle
115+
uses: actions/checkout@v2
116+
with:
117+
repository: moodle/moodle
118+
path: moodle
119+
ref: ${{ matrix.branch }}
120+
121+
- name: Prepare moodle-docker environment
122+
run: |
123+
cp config.docker-template.php moodle/config.php
124+
export MOODLE_DOCKER_WWWROOT="${PWD}/moodle"
125+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
126+
export MOODLE_DOCKER_PHP_VERSION="${{ matrix.php }}"
127+
export SUITE="${{ matrix.suite }}"
128+
export MOODLE_DOCKER_BROWSER="${{ matrix.browser }}"
129+
tests/behat-setup.sh
130+
131+
- name: Run moodle-docker tests
132+
run: |
133+
export MOODLE_DOCKER_WWWROOT="${PWD}/moodle"
134+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
135+
export SUITE="${{ matrix.suite }}"
136+
tests/behat-test.sh
137+
138+
- name: Stop moodle-docker
139+
run: |
140+
export MOODLE_DOCKER_WWWROOT="${PWD}/moodle"
141+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
142+
export SUITE="${{ matrix.suite }}"
143+
tests/behat-teardown.sh
144+
145+
App:
146+
runs-on: ubuntu-18.04
147+
148+
strategy:
149+
fail-fast: false
150+
matrix:
151+
include:
152+
# PostgreSQL (highest, lowest php supported)
153+
- { branch: master, php: "8.0", database: pgsql, suite: app-development, app-version: "3.9.0"}
154+
- { branch: master, php: "7.3", database: pgsql, suite: app-development, app-version: "3.9.0"}
155+
- { branch: master, php: "8.0", database: pgsql, suite: app, app-version: "3.9.0"}
156+
- { branch: master, php: "7.3", database: pgsql, suite: app, app-version: "3.9.0"}
157+
158+
steps:
159+
- name: Checking out moodle-docker
160+
uses: actions/checkout@v2
161+
162+
- name: Checking out moodle
163+
uses: actions/checkout@v2
164+
with:
165+
repository: moodle/moodle
166+
path: moodle
167+
ref: ${{ matrix.branch }}
168+
169+
- name: Prepare moodle-docker environment
170+
run: |
171+
cp config.docker-template.php moodle/config.php
172+
export MOODLE_DOCKER_WWWROOT="${PWD}/moodle"
173+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
174+
export MOODLE_DOCKER_PHP_VERSION="${{ matrix.php }}"
175+
export SUITE="${{ matrix.suite }}"
176+
export MOODLE_DOCKER_APP_VERSION="${{ matrix.app-version }}"
177+
tests/app-setup.sh
178+
179+
- name: Run moodle-docker tests
180+
run: |
181+
export MOODLE_DOCKER_WWWROOT="${PWD}/moodle"
182+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
183+
export SUITE="${{ matrix.suite }}"
184+
tests/app-test.sh
185+
186+
- name: Stop moodle-docker
187+
run: |
188+
export MOODLE_DOCKER_WWWROOT="${PWD}/moodle"
189+
export MOODLE_DOCKER_DB="${{ matrix.database }}"
190+
export SUITE="${{ matrix.suite }}"
191+
export MOODLE_DOCKER_APP_VERSION="${{ matrix.app-version }}"
192+
tests/app-teardown.sh

bin/moodle-docker-wait-for-db

Lines changed: 1 addition & 1 deletion
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

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

tests/app-teardown.sh

Lines changed: 19 additions & 0 deletions
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_BROWSER="chrome"
6+
7+
if [ "$SUITE" = "app-development" ];
8+
then
9+
export MOODLE_DOCKER_APP_PATH="${basedir}/app"
10+
elif [ "$SUITE" = "app" ];
11+
then
12+
echo
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/app-test.sh

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

tests/behat-setup.sh

Lines changed: 20 additions & 0 deletions
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+
if [ "$SUITE" = "behat" ];
6+
then
7+
initcmd="bin/moodle-docker-compose exec -T webserver php admin/tool/behat/cli/init.php"
8+
else
9+
echo "Error, unknown suite '$SUITE'"
10+
exit 1
11+
fi
12+
13+
echo "Pulling docker images"
14+
$basedir/bin/moodle-docker-compose pull
15+
echo "Starting up container"
16+
$basedir/bin/moodle-docker-compose up -d
17+
echo "Waiting for DB to come up"
18+
$basedir/bin/moodle-docker-wait-for-db
19+
echo "Running: $initcmd"
20+
$basedir/$initcmd

tests/behat-teardown.sh

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

tests/behat-test.sh

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

tests/phpunit-setup.sh

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

tests/phpunit-teardown.sh

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

tests/phpunit-test.sh

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

0 commit comments

Comments
 (0)