Skip to content

Commit

Permalink
GitHub Workflows for more modern versions. (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaboesch authored Oct 7, 2024
1 parent 5c8c7f0 commit bc6ddfa
Show file tree
Hide file tree
Showing 33 changed files with 386 additions and 271 deletions.
115 changes: 102 additions & 13 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04

services:
postgres:
image: postgres:12
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
mariadb:
image: mariadb:10.5
image: mariadb:10.6
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
Expand All @@ -27,13 +27,107 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0']
moodle-branch: ['master']
database: [pgsql, mariadb]
include:
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: pgsql
plugin-ci: 4
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: mariadb
plugin-ci: 4
- php: 8.2
moodle-branch: MOODLE_404_STABLE
database: pgsql
plugin-ci: 4
- php: 8.2
moodle-branch: MOODLE_404_STABLE
database: mariadb
plugin-ci: 4
- php: 8.1
moodle-branch: MOODLE_404_STABLE
database: pgsql
plugin-ci: 4
- php: 8.1
moodle-branch: MOODLE_404_STABLE
database: mariadb
plugin-ci: 4
- php: 8.2
moodle-branch: MOODLE_403_STABLE
database: pgsql
plugin-ci: 4
- php: 8.2
moodle-branch: MOODLE_403_STABLE
database: mariadb
plugin-ci: 4
- php: 8.1
moodle-branch: MOODLE_403_STABLE
database: pgsql
plugin-ci: 4
- php: 8.1
moodle-branch: MOODLE_403_STABLE
database: mariadb
plugin-ci: 4
- php: 8.0
moodle-branch: MOODLE_403_STABLE
database: pgsql
plugin-ci: 4
- php: 8.0
moodle-branch: MOODLE_403_STABLE
database: mariadb
plugin-ci: 4
- php: 8.2
moodle-branch: MOODLE_402_STABLE
database: pgsql
plugin-ci: 4
- php: 8.2
moodle-branch: MOODLE_402_STABLE
database: mariadb
plugin-ci: 4
- php: 8.1
moodle-branch: MOODLE_402_STABLE
database: pgsql
plugin-ci: 4
- php: 8.1
moodle-branch: MOODLE_402_STABLE
database: mariadb
plugin-ci: 4
- php: 8.0
moodle-branch: MOODLE_402_STABLE
database: pgsql
plugin-ci: 4
- php: 8.0
moodle-branch: MOODLE_402_STABLE
database: mariadb
plugin-ci: 4
- php: 8.1
moodle-branch: MOODLE_401_STABLE
database: pgsql
plugin-ci: 4
- php: 8.1
moodle-branch: MOODLE_401_STABLE
database: mariadb
plugin-ci: 4
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: pgsql
plugin-ci: 4
- php: 8.0
moodle-branch: MOODLE_401_STABLE
database: mariadb
plugin-ci: 4
- php: 7.4
moodle-branch: MOODLE_401_STABLE
database: pgsql
plugin-ci: 4
- php: 7.4
moodle-branch: MOODLE_401_STABLE
database: mariadb
plugin-ci: 4

steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: plugin

Expand All @@ -46,7 +140,7 @@ jobs:

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^${{ matrix.plugin-ci }}
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
Expand All @@ -63,11 +157,6 @@ jobs:
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
Expand Down
14 changes: 7 additions & 7 deletions backup/moodle2/backup_quizgame_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');

// Define each element separated.
$quizgame = new backup_nested_element('quizgame', array('id'), array(
'course', 'name', 'intro', 'introformat', 'timecreated',
'timemodified', 'questioncategory', 'grade', 'completionscore'));
$quizgame = new backup_nested_element('quizgame', ['id'],
['course', 'name', 'intro', 'introformat', 'timecreated',
'timemodified', 'questioncategory', 'grade', 'completionscore', ]);

$scores = new backup_nested_element('scores');

$score = new backup_nested_element('score', array('id'), array(
'quizgameid', 'userid', 'score', 'timecreated'));
$score = new backup_nested_element('score', ['id'],
['quizgameid', 'userid', 'score', 'timecreated']);
// Build the tree.

$quizgame->add_child($scores);
$scores->add_child($score);

// Define sources.

$quizgame->set_source_table('quizgame', array('id' => backup::VAR_ACTIVITYID));
$quizgame->set_source_table('quizgame', ['id' => backup::VAR_ACTIVITYID]);

// All the rest of elements only happen if we are including user info.
if ($userinfo) {
Expand All @@ -67,7 +67,7 @@ protected function define_structure() {
SELECT *
FROM {quizgame_scores}
WHERE quizgameid = ?',
array(backup::VAR_PARENTID));
[backup::VAR_PARENTID]);

}

Expand Down
8 changes: 4 additions & 4 deletions backup/moodle2/restore_quizgame_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ protected function define_my_steps() {
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents = [];

$contents[] = new restore_decode_content('quizgame', array('intro'), 'quizgame');
$contents[] = new restore_decode_content('quizgame', ['intro'], 'quizgame');

return $contents;
}
Expand All @@ -68,7 +68,7 @@ public static function define_decode_contents() {
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
$rules = array();
$rules = [];

$rules[] = new restore_decode_rule('QUIZVENTUREVIEWBYID', '/mod/quizgame/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('QUIZVENTUREINDEX', '/mod/quizgame/index.php?id=$1', 'course');
Expand All @@ -88,7 +88,7 @@ public static function define_decode_rules() {
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules = [];

// Fix old wrong uses (missing extension).
$rules[] = new restore_log_rule('quizgame', 'view all', 'index?id={course}', null,
Expand Down
6 changes: 3 additions & 3 deletions backup/moodle2/restore_quizgame_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class restore_quizgame_activity_structure_step extends restore_activity_structur
*/
protected function define_structure() {

$paths = array();
$paths = [];
$userinfo = $this->get_setting_value('userinfo');

$paths[] = new restore_path_element('quizgame', '/activity/quizgame');
Expand Down Expand Up @@ -70,10 +70,10 @@ protected function process_quizgame($data) {
// Get the new mapping to the category.
$newcat = $this->get_mappingid('question_category', $category[0]);
// Now get the context for this category.
$newcontext = $DB->get_field('question_categories', 'contextid', array('id' => $newcat));
$newcontext = $DB->get_field('question_categories', 'contextid', ['id' => $newcat]);
// Assemble the field data.
if (!empty($newcat)) {
$data->questioncategory = implode(',', array($newcat, $newcontext));
$data->questioncategory = implode(',', [$newcat, $newcontext]);
} else {
if (!$this->task->is_samesite() || $data->course != $oldcourse) {
// We cannot map to the question category.
Expand Down
4 changes: 2 additions & 2 deletions classes/completion/custom_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public function get_state(string $rule): int {
$completionscore = $this->cm->customdata['customcompletionrules']['completionscore'];

$where = ' quizgameid = :quizgameid AND userid = :userid AND score >= :score';
$params = array(
$params = [
'quizgameid' => $quizgameid,
'userid' => $userid,
'score' => $completionscore,
);
];
$highscore = $DB->count_records_select('quizgame_scores', $where, $params) > 0;

return ($highscore >= 1) ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
Expand Down
4 changes: 2 additions & 2 deletions classes/event/course_module_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function init() {
* @return \moodle_url
*/
public function get_url() {
$params = array('id' => $this->contextinstanceid);
$params = ['id' => $this->contextinstanceid];
if (!empty($this->other['mode'])) {
$params['mode'] = $this->other['mode'];
}
Expand All @@ -60,7 +60,7 @@ public function get_url() {
* @return array
*/
public static function get_objectid_mapping() {
return array('db' => 'quizgame', 'restore' => 'quizgame');
return ['db' => 'quizgame', 'restore' => 'quizgame'];
}
}

4 changes: 2 additions & 2 deletions classes/event/game_score_added.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function get_name() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/quizgame/view.php', array('id' => $this->contextinstanceid));
return new \moodle_url('/mod/quizgame/view.php', ['id' => $this->contextinstanceid]);
}

/**
Expand All @@ -75,6 +75,6 @@ public function get_description() {
* @return array
*/
public static function get_objectid_mapping() {
return array('db' => 'quizgame_scores', 'restore' => 'quizgame_scores');
return ['db' => 'quizgame_scores', 'restore' => 'quizgame_scores'];
}
}
4 changes: 2 additions & 2 deletions classes/event/game_scores_viewed.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function get_name() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/quizgame/scores.php', array('id' => $this->objectid));
return new \moodle_url('/mod/quizgame/scores.php', ['id' => $this->objectid]);
}

/**
Expand All @@ -75,6 +75,6 @@ public function get_description() {
* @return array
*/
public static function get_objectid_mapping() {
return array('db' => 'quizgame', 'restore' => 'quizgame');
return ['db' => 'quizgame', 'restore' => 'quizgame'];
}
}
4 changes: 2 additions & 2 deletions classes/event/game_started.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function get_name() {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/quizgame/view.php', array('id' => $this->contextinstanceid));
return new \moodle_url('/mod/quizgame/view.php', ['id' => $this->contextinstanceid]);
}

/**
Expand All @@ -74,6 +74,6 @@ public function get_description() {
* @return array
*/
public static function get_objectid_mapping() {
return array('db' => 'quizgame', 'restore' => 'quizgame');
return ['db' => 'quizgame', 'restore' => 'quizgame'];
}
}
26 changes: 13 additions & 13 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public static function update_score_parameters() {
// The external_function_parameters constructor expects an array of external_description.
return new external_function_parameters(
// An external_description can be: external_value, external_single_structure or external_multiple structure.
array('quizgameid' => new external_value(PARAM_INT, 'quizgame instance ID'),
['quizgameid' => new external_value(PARAM_INT, 'quizgame instance ID'),
'score' => new external_value(PARAM_INT, 'Player final score'),
)
]
);
}

Expand All @@ -65,18 +65,18 @@ public static function update_score_parameters() {
public static function update_score($quizgameid, $score) {

global $DB;
$warnings = array();
$warnings = [];
$params = self::validate_parameters(self::update_score_parameters(),
array(
[
'quizgameid' => $quizgameid,
'score' => $score
));
if (!$quizgame = $DB->get_record("quizgame", array("id" => $params['quizgameid']))) {
'score' => $score,
]);
if (!$quizgame = $DB->get_record("quizgame", ["id" => $params['quizgameid']])) {
throw new moodle_exception("invalidcoursemodule", "error");
}

$cm = get_coursemodule_from_instance('quizgame', $quizgame->id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);

// Validate the context and check capabilities.
$context = context_module::instance($cm->id);
Expand Down Expand Up @@ -109,7 +109,7 @@ public static function start_game_parameters() {
// The external_function_parameters constructor expects an array of external_description.
return new external_function_parameters(
// An external_description can be: external_value, external_single_structure or external_multiple structure.
array('quizgameid' => new external_value(PARAM_INT, 'quizgame instance ID'))
['quizgameid' => new external_value(PARAM_INT, 'quizgame instance ID')]
);
}

Expand All @@ -121,16 +121,16 @@ public static function start_game_parameters() {
public static function start_game($quizgameid) {

global $DB;
$warnings = array();
$warnings = [];
$params = self::validate_parameters(self::start_game_parameters(),
array('quizgameid' => $quizgameid)
['quizgameid' => $quizgameid]
);
if (!$quizgame = $DB->get_record("quizgame", array("id" => $params['quizgameid']))) {
if (!$quizgame = $DB->get_record("quizgame", ["id" => $params['quizgameid']])) {
throw new moodle_exception("invalidcoursemodule", "error");
}

$cm = get_coursemodule_from_instance('quizgame', $quizgame->id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);

// Validate the context and check capabilities.
$context = context_module::instance($cm->id);
Expand Down
Loading

0 comments on commit bc6ddfa

Please sign in to comment.