Skip to content

Commit

Permalink
Merge pull request #276 from stronk7/gha-php82
Browse files Browse the repository at this point in the history
Various changes towards CI passing with php82
  • Loading branch information
junpataleta authored Aug 4, 2023
2 parents 6ace05a + a893bbf commit 0baf895
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 84 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,23 @@ jobs:
git config --global user.email "local_ci@moodle.com"
git config --global user.name "Local CI"
- name: Setting up DB mysql
uses: moodlehq/mysql-action@v1
with:
collation server: utf8mb4_bin
mysql version: 8.0
mysql root password: test
use tmpfs: true
tmpfs size: '1024M'
extra conf: --skip-log-bin

- name: Setting up PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
ini-values: max_input_vars=5000
tools: composer

coverage: none

- name: Configuring node & npm
uses: actions/setup-node@v3
Expand All @@ -50,16 +60,6 @@ jobs:
composer install
npm install
- name: Setting up DB mysql
uses: moodlehq/mysql-action@v1
with:
collation server: utf8mb4_bin
mysql version: 8.0
mysql root password: test
use tmpfs: true
tmpfs size: '1024M'
extra conf: --skip-log-bin

- name: Setup Bats
uses: amdilabs/setup-bats@v1
with:
Expand Down
101 changes: 59 additions & 42 deletions tests/1-compare_databases.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ setup () {
if [ -z "${!var}" ]; then
# Only LOCAL_CI_TESTS_DBPASS can be set and empty (because some facilities and devs like it to be empty)
if [ "$var" != "LOCAL_CI_TESTS_DBPASS" ] || [ -z "${!var+x}" ]; then
skip "some required variables are not defined"
skip "some required variables are not defined (${var})"
fi
fi
done
Expand All @@ -27,6 +27,17 @@ setup () {
create_git_branch master 35d5053ba20432059b497d85e39175d356f44fb4
}

teardown () {
echo $BATS_TEST_NAME > /tmp/file
# Not all tests use the "compare_databases" branch.
if [[ $BATS_TEST_NAME =~ "problems_are_detected" ]]; then
cd $gitdir
git checkout master
git branch -D compare_databases -q
cd $OLDPWD
fi;
}

@test "compare_databases/compare_databases.sh: missing env variables" {
export gitbranchinstalled=master
export gitbranchupgraded=MOODLE_31_STABLE
Expand All @@ -37,83 +48,89 @@ setup () {
assert_output --partial 'Error: dbtype environment variable is not defined. See the script comments.'
}

@test "compare_databases/compare_databases.sh: single actual (>= 39_STABLE) branch runs work" {
export gitbranchinstalled=MOODLE_401_STABLE
export gitbranchupgraded=MOODLE_39_STABLE
@test "compare_databases/compare_databases.sh: single actual (> 401_STABLE) branch runs work" {
# TODO: Change this to stable branches when we have more supporting php82.
export gitbranchinstalled=master
export gitbranchupgraded=MOODLE_402_STABLE

ci_run compare_databases/compare_databases.sh
assert_success
assert_output --partial 'Info: Origin branches: (1) MOODLE_39_STABLE'
assert_output --partial 'Info: Target branch: MOODLE_401_STABLE'
assert_output --partial 'Info: Installing Moodle MOODLE_401_STABLE into ci_installed_'
assert_output --partial 'Info: Comparing MOODLE_401_STABLE and upgraded MOODLE_39_STABLE'
assert_output --partial 'Info: Installing Moodle MOODLE_39_STABLE into ci_upgraded_'
assert_output --partial 'Info: Upgrading Moodle MOODLE_39_STABLE to MOODLE_401_STABLE into ci_upgraded_'
assert_output --partial 'Info: Origin branches: (1) MOODLE_402_STABLE'
assert_output --partial 'Info: Target branch: master'
assert_output --partial 'Info: Installing Moodle master into ci_installed_'
assert_output --partial 'Info: Comparing master and upgraded MOODLE_402_STABLE'
assert_output --partial 'Info: Installing Moodle MOODLE_402_STABLE into ci_upgraded_'
assert_output --partial 'Info: Upgrading Moodle MOODLE_402_STABLE to master into ci_upgraded_'
assert_output --partial 'Info: Comparing databases ci_installed_'
assert_output --partial 'Info: OK. No problems comparing databases ci_installed_'
assert_output --partial 'Ok: Process ended without errors'
refute_output --partial 'Error: Process ended with'
run [ -f $WORKSPACE/compare_databases_MOODLE_401_STABLE_logfile.txt ]
run [ -f $WORKSPACE/compare_databases_master_logfile.txt ]
assert_success
}

@test "compare_databases/compare_databases.sh: single old (< 311_STABLE) branch runs work" {
export gitbranchinstalled=v3.11.8
export gitbranchupgraded=v3.11.1
@test "compare_databases/compare_databases.sh: single old (<= 402_STABLE) branch runs work" {
# TODO: Change this to versions corresponding to different branches when we have more supporting php82-
export gitbranchinstalled=v4.2.1
export gitbranchupgraded=v4.2.0

ci_run compare_databases/compare_databases.sh
assert_success
assert_output --partial 'Info: Origin branches: (1) v3.11.1'
assert_output --partial 'Info: Target branch: v3.11.8'
assert_output --partial 'Info: Installing Moodle v3.11.8 into ci_installed_'
assert_output --partial 'Info: Comparing v3.11.8 and upgraded v3.11.1'
assert_output --partial 'Info: Installing Moodle v3.11.1 into ci_upgraded_'
assert_output --partial 'Info: Upgrading Moodle v3.11.1 to v3.11.8 into ci_upgraded_'
assert_output --partial 'Info: Origin branches: (1) v4.2.0'
assert_output --partial 'Info: Target branch: v4.2.1'
assert_output --partial 'Info: Installing Moodle v4.2.1 into ci_installed_'
assert_output --partial 'Info: Comparing v4.2.1 and upgraded v4.2.0'
assert_output --partial 'Info: Installing Moodle v4.2.0 into ci_upgraded_'
assert_output --partial 'Info: Upgrading Moodle v4.2.0 to v4.2.1 into ci_upgraded_'
assert_output --partial 'Info: Comparing databases ci_installed_'
assert_output --partial 'Info: OK. No problems comparing databases ci_installed_'
assert_output --partial 'Ok: Process ended without errors'
refute_output --partial 'Error: Process ended with'
run [ -f $WORKSPACE/compare_databases_v3.11.8_logfile.txt ]
run [ -f $WORKSPACE/compare_databases_v4.2.1_logfile.txt ]
assert_success
}

@test "compare_databases/compare_databases.sh: multiple branch runs work" {
export gitbranchinstalled=MOODLE_401_STABLE
export gitbranchupgraded=MOODLE_39_STABLE,MOODLE_310_STABLE
# TODO: Change this to different stable branches when we have more supporting php82.
export gitbranchinstalled=master
export gitbranchupgraded=v4.2.1,MOODLE_402_STABLE

ci_run compare_databases/compare_databases.sh
assert_success
assert_output --partial 'Info: Origin branches: (2) MOODLE_39_STABLE,MOODLE_310_STABLE'
assert_output --partial 'Info: Target branch: MOODLE_401_STABLE'
assert_output --partial 'Info: Comparing MOODLE_401_STABLE and upgraded MOODLE_39_STABLE'
assert_output --partial 'Info: Comparing MOODLE_401_STABLE and upgraded MOODLE_310_STABLE'
assert_output --partial 'Info: Origin branches: (2) v4.2.1,MOODLE_402_STABLE'
assert_output --partial 'Info: Target branch: master'
assert_output --partial 'Info: Comparing master and upgraded v4.2.1'
assert_output --partial 'Info: Comparing master and upgraded MOODLE_402_STABLE'
assert_output --partial 'Ok: Process ended without errors'
refute_output --partial 'Error: Process ended with'
run [ -f $WORKSPACE/compare_databases_MOODLE_401_STABLE_logfile.txt ]
run [ -f $WORKSPACE/compare_databases_master_logfile.txt ]
assert_success
}

@test "compare_databases/compare_databases.sh: problems are detected" {
export gitbranchinstalled=3ba580e3f2a5f253365d33642b0bb6a94285ba2c
export gitbranchupgraded=MOODLE_311_STABLE
# Locally, patch master (4.3dev), as of 20230803, so we introduce some differences.
create_git_branch compare_databases a1d5d1b2f758a3178bff4c42883a477f4b1ea50c
git_apply_fixture compare_databases_wrong.patch

export gitbranchinstalled=compare_databases
export gitbranchupgraded=MOODLE_402_STABLE

ci_run compare_databases/compare_databases.sh
assert_failure
assert_output --partial 'Info: Origin branches: (1) MOODLE_311_STABLE'
assert_output --partial 'Info: Target branch: 3ba580e3f2a5f253365d33642b0bb6a94285ba2c'
assert_output --partial 'Info: Comparing 3ba580e3f2a5f253365d33642b0bb6a94285ba2c and upgraded MOODLE_311_STABLE'
assert_output --partial 'Info: Origin branches: (1) MOODLE_402_STABLE'
assert_output --partial 'Info: Target branch: compare_databases'
assert_output --partial 'Info: Comparing compare_databases and upgraded MOODLE_402_STABLE'
assert_output --partial 'Problems found comparing databases!'
assert_output --partial 'Number of errors: 7'
assert_output --partial 'Column status of table enrol_lti_app_registration difference found in has_default: true !== false'
assert_output --partial 'Column status of table enrol_lti_app_registration difference found in default_value: 0 !== null'
assert_output --partial 'Column hidden of table grade_categories difference found in type: tinyint !== bigint'
assert_output --regexp 'Column hidden of table grade_categories difference found in max_length: 2 !== 1[89]'
assert_output --partial 'Column hidden of table grade_categories_history difference found in type: tinyint !== bigint'
assert_output --regexp 'Column hidden of table grade_categories_history difference found in max_length: 2 !== 1[89]'
assert_output --partial 'Index (pathnamehash) of table h5p only available in second DB'
assert_output --partial 'Number of errors: 6'
assert_output --partial 'Column username of table user difference found in max_length: 200 !== 100'
assert_output --partial 'Column firstaccess of table user difference found in not_null: false !== true'
assert_output --partial 'Column firstaccess of table user difference found in default_value: 1 !== 0'
assert_output --partial 'Column trackforums of table user difference found in type: varchar !== tinyint'
assert_output --partial 'Column trackforums of table user difference found in max_length: 1 !== 2'
assert_output --partial 'Column trackforums of table user difference found in meta_type: C !== I'
assert_output --partial 'Error: Problem comparing databases ci_installed_'
assert_output --partial 'Error: Process ended with 1 errors'
refute_output --partial 'Ok: Process ended without errors'
run [ -f $WORKSPACE/compare_databases_3ba580e3f2a5f253365d33642b0bb6a94285ba2c_logfile.txt ]
run [ -f $WORKSPACE/compare_databases_compare_databases_logfile.txt ]
assert_success
}
10 changes: 5 additions & 5 deletions tests/1-php_lint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
load libs/shared_setup

setup () {
create_git_branch MOODLE_31_STABLE v3.1.0
create_git_branch MOODLE_402_STABLE v4.2.1
}

@test "php_lint: lib/moodlelib.php lint free" {
# Set up.
git_apply_fixture 31-php_lint-ok.patch
git_apply_fixture 402-php_lint-ok.patch
export GIT_PREVIOUS_COMMIT=$FIXTURE_HASH_BEFORE
export GIT_COMMIT=$FIXTURE_HASH_AFTER

Expand All @@ -23,7 +23,7 @@ setup () {

@test "php_lint: lib/moodlelib.php lint error detected" {
# Set up.
git_apply_fixture 31-php_lint-bad.patch
git_apply_fixture 402-php_lint-bad.patch
export GIT_PREVIOUS_COMMIT=$FIXTURE_HASH_BEFORE
export GIT_COMMIT=$FIXTURE_HASH_AFTER

Expand All @@ -38,7 +38,7 @@ setup () {

@test "php_lint: Ensure vendor directories aren't checked ever" {
# Set up.
git_apply_fixture 31-php_lint-vendor.patch
git_apply_fixture 402-php_lint-vendor.patch
export GIT_PREVIOUS_COMMIT=$FIXTURE_HASH_BEFORE
export GIT_COMMIT=$FIXTURE_HASH_AFTER

Expand All @@ -53,7 +53,7 @@ setup () {

@test "php_lint: shows the php version being used" {
# Set up.
git_apply_fixture 31-php_lint-ok.patch
git_apply_fixture 402-php_lint-ok.patch
export GIT_PREVIOUS_COMMIT=$FIXTURE_HASH_BEFORE
export GIT_COMMIT=$FIXTURE_HASH_AFTER

Expand Down
22 changes: 0 additions & 22 deletions tests/fixtures/31-php_lint-bad.patch

This file was deleted.

25 changes: 25 additions & 0 deletions tests/fixtures/402-php_lint-bad.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From dbe6c7fffdbb08918094540289bf6c1365f161cc Mon Sep 17 00:00:00 2001
From: "Eloy Lafuente (stronk7)" <stronk7@moodle.org>
Date: Fri, 4 Aug 2023 08:28:39 +0200
Subject: [PATCH] MDLSITE-4211 fixture: for php_lint tests

This should be applied on top of v4.1.0
---
lib/moodlelib.php | 1 +
1 file changed, 1 insertion(+)

diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 7b7e462219..56ffe31218 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -10882,6 +10882,7 @@ class lang_string {
$this->forcedstring = true;
return array('forcedstring', 'string', 'lang');
}
+die('oh this is gonna be a problem!

/**
* Returns the identifier.
--
2.40.0

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ From: Dan Poltawski <dan@moodle.com>
Date: Wed, 15 Jun 2016 22:51:00 +0100
Subject: [PATCH 1/1] MDLSITE-4211 OK fixture: for php_lint tests

This should be applied on top of v3.1.0
This should be applied on top of v4.1.0
---
lib/moodlelib.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Expand Down
File renamed without changes.
44 changes: 44 additions & 0 deletions tests/fixtures/compare_databases_wrong.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From cf4705ca3622530482459f681559d1300cbb9799 Mon Sep 17 00:00:00 2001
From: "Eloy Lafuente (stronk7)" <stronk7@moodle.org>
Date: Thu, 3 Aug 2023 14:37:20 +0200
Subject: [PATCH] MDL-12345 install: Force some differences in DB schema for
testing

---
lib/db/install.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/db/install.xml b/lib/db/install.xml
index e18b9a07e03..f70d8899bbc 100644
--- a/lib/db/install.xml
+++ b/lib/db/install.xml
@@ -865,7 +865,7 @@
<FIELD NAME="deleted" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="suspended" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="suspended flag prevents users to log in"/>
<FIELD NAME="mnethostid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
- <FIELD NAME="username" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
+ <FIELD NAME="username" TYPE="char" LENGTH="200" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="password" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="idnumber" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="firstname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
@@ -883,7 +883,7 @@
<FIELD NAME="calendartype" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="gregorian" SEQUENCE="false"/>
<FIELD NAME="theme" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="timezone" TYPE="char" LENGTH="100" NOTNULL="true" DEFAULT="99" SEQUENCE="false"/>
- <FIELD NAME="firstaccess" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
+ <FIELD NAME="firstaccess" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="lastaccess" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="lastlogin" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="currentlogin" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
@@ -896,7 +896,7 @@
<FIELD NAME="maildigest" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="maildisplay" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="2" SEQUENCE="false"/>
<FIELD NAME="autosubscribe" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
- <FIELD NAME="trackforums" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
+ <FIELD NAME="trackforums" TYPE="char" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="trustbitmask" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
--
2.40.0

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<description>This section shows php lint problems in the code detected by php -l</description>
<mess>
<problem file="help.php" linefrom="59" lineto="59" method="" class="" package="" api="" diffurl="https://git.in.moodle.com/integration/prechecker/blob/a108efda67467c48bbc9a4c8a5f4c4497a3e51bd/help.php#L59" ruleset="moodle" rule="" url="http://php.net/docs.php" type="error" weight="5">
<message>PHP Parse error: syntax error, unexpected end of file, expecting ';' or ',' in /help.php on line 59 </message>
<message>PHP Parse error: syntax error, unexpected end of file, expecting "," or ";" in /help.php on line 59 </message>
<description/>
<code/>
</problem>
Expand Down
2 changes: 1 addition & 1 deletion verify_commit_messages/amoslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function print_error($message) {

public static function print_message($message, $severity = 'info') {
global $COMMIT;
echo "${COMMIT}*${severity}*AMOS - ${message}\n";
echo "{$COMMIT}*{$severity}*AMOS - {$message}\n";
}

/**
Expand Down

0 comments on commit 0baf895

Please sign in to comment.