-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci-template.yml
136 lines (120 loc) · 5.49 KB
/
.gitlab-ci-template.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
## Gitlab CI/CD template for Moodle plugins By Ldesign Media.
## Author: Hamza Tamyachte
## Copyright 17/07/2024 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
services:
- mysql:latest
- name: selenium/standalone-chrome:3
alias: selenium-standalone-chrome
variables:
PHP_VERSION: "8.0"
TRAVIS_BUILD_DIR: "$CI_PROJECT_DIR"
MOODLE_REPO: "https://github.com/moodle/moodle.git"
# Workplace branches
MOODLE_BRANCH_WORKPLACE405S: WORKPLACE_405_0
MOODLE_BRANCH_WORKPLACE404S: WORKPLACE_404_3
MOODLE_BRANCH_WORKPLACE403S: WORKPLACE_403_7
MOODLE_BRANCH_WORKPLACE402S: WORKPLACE_402_10
MOODLE_BRANCH_WORKPLACE401S: WORKPLACE_401_13
# Moodle branches
MOODLE_BRANCH_LMS405: MOODLE_405_STABLE
MOODLE_BRANCH_LMS404: MOODLE_404_STABLE
MOODLE_BRANCH_LMS403: MOODLE_403_STABLE
MOODLE_BRANCH_LMS402: MOODLE_402_STABLE
MOODLE_BRANCH_LMS401: MOODLE_401_STABLE
MOODLE_BRANCH_LMS400: MOODLE_400_STABLE
MOODLE_BRANCH_LMS39: MOODLE_39_STABLE
# Selenium configuration
MOODLE_BEHAT_WDHOST: "http://selenium-standalone-chrome:4444/wd/hub"
MOODLE_START_BEHAT_SERVERS: "NO"
# Database configuration
DB: "mysqli"
MYSQL_ROOT_PASSWORD: "superrootpass"
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
.scriptshorttest: &scriptshorttest
image: moodlehq/moodle-workplace-plugin-ci:$PHP_VERSION
script:
- echo -e "section_start:$(date +%s):env[collapsed=true]\r"
# Prevent checking styles.scss and styles.css files, as they are incorrectly formatted by PHPStorm, and there is no reliable way to validate them.
- if [ -f styles.scss ]; then echo "Removing styles.scss"; rm -f styles.scss; else echo "styles.scss not found, skipping."; fi
- if [ -f styles.css ]; then echo "Removing styles.css"; rm -f styles.css; else echo "styles.css not found, skipping."; fi
- apt update && apt install -y mariadb-client
- cd $CI_PROJECT_DIR/..
- echo $MOODLE_REPO
- rm -rf moodle
# Install Moodle includes the setup of PHPUnit and Behat when tests exist in the plugin directory.
- export IPADDRESS=`grep "${HOSTNAME}$" /etc/hosts |awk '{print $1}'`
- export MOODLE_BEHAT_WWWROOT="http://${IPADDRESS}:8000"
- moodle-plugin-ci install --db-user=root --db-pass=superrootpass --db-host=mysql -vvv
- cd moodle
- php -S ${IPADDRESS}:8000 -t $CI_PROJECT_DIR/../moodle > /dev/null 2>&1 &
- echo -e "section_end:$(date +%s):env\r"
- |
GREEN='\033[32m'
ORANGE='\033[38;5;214m'
RED='\033[31m'
RESET='\033[0m'
# Highlight function for WARNING and ERROR
highlight_errors() {
declare -A patterns
# Define colors for the different patterns.
patterns=(
["FOUND 0 ERRORS"]=$GREEN
["ERROR"]=$RED
["WARNING"]=$ORANGE
["File is stale and needs to be rebuilt"]=$RED
)
# Define the order explicitly, needed for the correct coloring.
order=(
"FOUND 0 ERRORS"
"ERROR"
"WARNING"
"File is stale and needs to be rebuilt"
)
# Read input line by line
while IFS= read -r line; do
matched=false
for pattern in "${order[@]}"; do
if [[ "$line" == *"$pattern"* ]]; then
echo -e "${patterns[$pattern]}${line}${RESET}"
matched=true
break
fi
done
# If no pattern matches, print the line as-is
if [[ $matched == false ]]; then
echo "$line"
fi
done
}
declare -f highlight_errors
run_with_error_handling() {
local test_command="$1"
local allow_errors_var="$2"
local allow_errors="${!allow_errors_var}"
echo -e "${ORANGE}Running test ${test_command}:${RESET}"
if [ "$allow_errors" = "true" ]; then
eval "$test_command" 2>&1 | highlight_errors || true
echo -e "${ORANGE}Test ${test_command} completed with errors (ignored).${RESET}"
else
eval "$test_command" 2>&1 | highlight_errors
echo -e "${ORANGE}Test ${test_command} completed successfully.${RESET}"
fi
}
echo -e "${ORANGE}Setup completed. Running the tests now:${RESET}"
run_with_error_handling "moodle-plugin-ci phplint" "ALLOW_ERRORS_PHPLINT"
run_with_error_handling "moodle-plugin-ci phpcpd" "ALLOW_ERRORS_PHPCPD"
run_with_error_handling "moodle-plugin-ci phpmd" "ALLOW_ERRORS_PHPMD"
run_with_error_handling "moodle-plugin-ci codechecker" "ALLOW_ERRORS_CODECHECKER"
run_with_error_handling "moodle-plugin-ci mustache" "ALLOW_ERRORS_MUSTACHE"
run_with_error_handling "moodle-plugin-ci validate" "ALLOW_ERRORS_VALIDATE"
run_with_error_handling "moodle-plugin-ci savepoints" "ALLOW_ERRORS_SAVEPOINTS"
run_with_error_handling "moodle-plugin-ci grunt --tasks=amd" "ALLOW_ERRORS_GRUNT"
run_with_error_handling "moodle-plugin-ci grunt --tasks=yui" "ALLOW_ERRORS_GRUNT"
run_with_error_handling "moodle-plugin-ci grunt --tasks=gherkinlint" "ALLOW_ERRORS_GRUNT"
# we skip stylelint check as it is not reliable, and not support css on other places.
run_with_error_handling "moodle-plugin-ci phpdoc" "ALLOW_ERRORS_PHPDOC"
run_with_error_handling "moodle-plugin-ci phpunit" "ALLOW_ERRORS_PHPUNIT"
run_with_error_handling "moodle-plugin-ci behat --suite default --profile chrome" "ALLOW_ERRORS_BEHAT"
allow_failure: true
except:
- tags