Skip to content

Commit

Permalink
Merge pull request #11 from ucsf-education/gh_actions
Browse files Browse the repository at this point in the history
CI integration
  • Loading branch information
stopfstedt authored Mar 16, 2024
2 parents 5028f8b + 56dce61 commit 10f6b35
Show file tree
Hide file tree
Showing 14 changed files with 436 additions and 118 deletions.
115 changes: 115 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Moodle Plugin CI

on:
push:
pull_request:
schedule:
- cron: '33 2 * * 1' # weekly, on Monday morning

jobs:
test:
runs-on: ubuntu-latest

services:
mariadb:
image: mariadb:10
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

strategy:
fail-fast: false
matrix:
include:
- php: '8.2'
moodle-branch: 'main'
database: 'mariadb'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
path: plugin

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ matrix.extensions }}
ini-values: max_input_vars=5000
# If you are not using code coverage, keep "none". Otherwise, use "pcov" (Moodle 3.10 and up) or "xdebug".
# If you try to use code coverage with "none", it will fallback to phpdbg (which has known problems).
coverage: none

- name: Initialise moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
sudo locale-gen en_AU.UTF-8
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
- name: Install moodle-plugin-ci
run: |
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: PHP Lint
if: ${{ !cancelled() }}
run: moodle-plugin-ci phplint

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpcs --max-warnings 0

- name: Moodle PHPDoc Checker
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpdoc --max-warnings 0

- name: Validating
if: ${{ !cancelled() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ !cancelled() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ !cancelled() }}
run: moodle-plugin-ci mustache

- name: Grunt
if: ${{ !cancelled() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpunit --fail-on-warning

- name: Behat features
if: ${{ !cancelled() }}
run: moodle-plugin-ci behat --profile chrome

- name: Mark cancelled jobs as failed.
if: ${{ cancelled() }}
run: exit 1
4 changes: 4 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="MoodleCore">
<rule ref="moodle-extra"/>
</ruleset>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

A custom question type for Moodle.

Copyright (c) 2016 by The Regents of the University of California
Copyright (c) by The Regents of the University of California

This is Open Source Software, published under the GPL v3 license.
19 changes: 9 additions & 10 deletions backup/moodle2/backup_qtype_knowledgecheck_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package knowledgecheck
* Backup plugin for the Knowledge check question type.
*
* @package qtype_knowledgecheck
* @subpackage backup-moodle2
* @copyright 2016 The Regents of the University of California
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


defined('MOODLE_INTERNAL') || die();


/**
* Provides the information to backup knowledge check questions.
* Provides the information to backup knowledgecheck questions.
*
* @copyright 2016 The Regents of the University of California
* @package qtype_knowledgecheck
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_qtype_knowledgecheck_plugin extends backup_qtype_plugin {
Expand All @@ -52,14 +51,14 @@ protected function define_question_plugin_structure() {
$this->add_question_question_answers($pluginwrapper);

// Now create the qtype own structures.
$knowledgecheck = new backup_nested_element('knowledgecheck', array('id'), array('responsetemplate'));
$knowledgecheck = new backup_nested_element('knowledgecheck', ['id'], ['responsetemplate']);

// Now the own qtype tree.
$pluginwrapper->add_child($knowledgecheck);

// Set source to populate the data.
$knowledgecheck->set_source_table('qtype_knowledgecheck_options',
array('questionid' => backup::VAR_PARENTID));
['questionid' => backup::VAR_PARENTID]);

// Don't need to annotate ids nor files.

Expand Down
21 changes: 10 additions & 11 deletions backup/moodle2/restore_qtype_knowledgecheck_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package knowledgecheck
* Restore plugin for the Knowledge check question type.
*
* @package qtype_knowledgecheck
* @subpackage backup-moodle2
* @copyright 2016 The Regents of the University of California
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


defined('MOODLE_INTERNAL') || die();


/**
* restore plugin class that provides the necessary information
* needed to restore one knowledgecheck qtype plugin
* Restore plugin class that provides the necessary information needed to restore one knowledgecheck qtype plugin.
*
* @copyright 2016 The Regents of the University of California
* @package qtype_knowledgecheck
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restore_qtype_knowledgecheck_plugin extends restore_qtype_plugin {
Expand All @@ -39,7 +37,7 @@ class restore_qtype_knowledgecheck_plugin extends restore_qtype_plugin {
*/
protected function define_question_plugin_structure() {

$paths = array();
$paths = [];

// This qtype uses question_answers, add them.
$this->add_question_question_answers($paths);
Expand All @@ -55,6 +53,7 @@ protected function define_question_plugin_structure() {

/**
* Process the qtype/knowledgecheck element
* @param array $data The data to restore.
*/
public function process_knowledgecheck($data) {
global $DB;
Expand All @@ -79,7 +78,7 @@ public function process_knowledgecheck($data) {

// It is possible for old backup files to contain unique key violations.
// We need to check to avoid that.
if (!$DB->record_exists('qtype_knowledgecheck_options', array('questionid' => $data->questionid))) {
if (!$DB->record_exists('qtype_knowledgecheck_options', ['questionid' => $data->questionid])) {
$newitemid = $DB->insert_record('qtype_knowledgecheck_options', $data);
$this->set_mapping('qtype_knowledgecheck_options', $oldid, $newitemid);
}
Expand Down
65 changes: 65 additions & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy Subsystem implementation for qtype_knowledgecheck.
*
* @package qtype_knowledgecheck
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace qtype_knowledgecheck\privacy;

use core_privacy\local\metadata\collection;
use core_privacy\local\metadata\provider as base_provider;
use core_privacy\local\request\user_preference_provider;
use core_privacy\local\request\writer;

/**
* Privacy Subsystem for qtype_knowledgecheck implementing user_preference_provider.
*
* @package qtype_knowledgecheck
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements base_provider, user_preference_provider {


/**
* Returns meta-data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
$collection->add_user_preference('qtype_knowledgecheck_defaultmark', 'privacy:preference:defaultmark');
return $collection;
}

/**
* Export all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
$preference = get_user_preferences('qtype_knowledgecheck_defaultmark', null, $userid);
if (null !== $preference) {
$desc = get_string('privacy:preference:defaultmark', 'qtype_knowledgecheck');
writer::export_user_preference('qtype_knowledgecheck', 'defaultmark', $preference, $desc);
}
}
}
38 changes: 24 additions & 14 deletions edit_knowledgecheck_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,39 @@
/**
* Defines the editing form for the knowledge check question type.
*
* @package qtype
* @subpackage knowledgecheck
* @copyright 2016 The Regents of the University of California
* @package qtype_knowledgecheck
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


defined('MOODLE_INTERNAL') || die();


/**
* Knowledge check question editing form definition.
*
* @copyright 2016 The Regents of the University of California
* @package qtype_knowledgecheck
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_knowledgecheck_edit_form extends question_edit_form {

/**
* {@inheritdoc}
*
* @param object $mform The form being built.
*/
protected function definition_inner($mform) {
$mform->addElement('editor', 'responsetemplate', get_string('responsetemplate', 'qtype_knowledgecheck'),
array('rows' => 10), array_merge($this->editoroptions, array('maxfiles' => 0)));
['rows' => 10], array_merge($this->editoroptions, ['maxfiles' => 0]));
$mform->addHelpButton('responsetemplate', 'responsetemplate', 'qtype_knowledgecheck');
$this->add_per_answer_fields($mform, get_string('answerno', 'qtype_knowledgecheck', '{no}'),
array('1.0' => '100%'), 1, 0);
['1.0' => '100%'], 1, 0);
}

/**
* {@inheritdoc}
*
* @param object $question The data being passed to the form.
* @return object $question The modified data.
*/
protected function data_preprocessing($question) {
$question = parent::data_preprocessing($question);
$question = $this->data_preprocessing_answers($question);
Expand All @@ -53,14 +58,19 @@ protected function data_preprocessing($question) {
if (empty($question->options)) {
return $question;
}
$question->responsetemplate = array(
$question->responsetemplate = [
'text' => $question->options->responsetemplate,
'format' => 1,
);
];

return $question;
}

/**
* {@inheritdoc}
*
* @return string The question type name.
*/
public function qtype() {
return 'knowledgecheck';
}
Expand Down
10 changes: 5 additions & 5 deletions lang/en/qtype_knowledgecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Strings for component 'qtype_knowledgecheck', language 'en', branch 'MOODLE_20_STABLE'
* Strings for component 'qtype_knowledgecheck'.
*
* @package qtype
* @subpackage knowledgecheck
* @copyright 2016 The Regents of the University of California
* @package qtype_knowledgecheck
* @copyright (c) The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['answerno'] = 'Answer {$a}';
Expand All @@ -30,6 +28,8 @@
$string['pluginnameadding'] = 'Adding a knowledge check question';
$string['pluginnameediting'] = 'Editing a knowledge check question';
$string['pluginnamesummary'] = 'Students can check their knowledge and get immediate or delayed feedback (depending on the question settings). All answers are automatically graded and assumed to be correct. The main purpose of this question type is to automatically provide students with feedback on their responses.';
$string['privacy:metadata'] = 'Knowledgecheck question type plugin allows question authors to set default options as user preferences.';
$string['privacy:preference:defaultmark'] = 'The default mark set for a given question.';
$string['responsetemplate'] = 'Response template';
$string['responsetemplate_help'] = 'Any text entered here will be displayed in the response input box when a new attempt at the question starts.';

Loading

0 comments on commit 10f6b35

Please sign in to comment.