Skip to content

Commit

Permalink
Merge pull request #20 from ilios/github-actions
Browse files Browse the repository at this point in the history
Adds Github Actions integration.
  • Loading branch information
stopfstedt authored Jun 4, 2024
2 parents 7d279d9 + 6b4a54a commit 0ce4dcc
Show file tree
Hide file tree
Showing 17 changed files with 782 additions and 403 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
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'
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>
62 changes: 40 additions & 22 deletions classes/form/create_sync_job.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,57 @@
<?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/>.

/**
* Form for creating a new sync job.
*
* @package tool_ilioscategoryassignment
* @category form
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_ilioscategoryassignment\form;

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

use core_course_category;
use Exception;
use moodle_page;
use moodleform;
use tool_ilioscategoryassignment\manager;
use tool_ilioscategoryassignment\output\renderer;

/* @global $CFG */
require_once($CFG->libdir . '/accesslib.php');
require_once($CFG->libdir . '/formslib.php');

/**
* Form for creating a new sync job.
* New sync job form class.
*
* @package tool_ilioscategoryassignment
* @category form
* @package tool_ilioscategoryassignment
* @copyright The Regents of the University of California
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class create_sync_job extends moodleform {

/**
* @inheritdoc
* Form definition.
*/
public function definition() {
/* @var \moodle_page $PAGE */
public function definition(): void {
/* @var moodle_page $PAGE The current page. */
global $PAGE;

/* @var renderer $renderer */
/* @var renderer $renderer The plugin renderer. */
$renderer = $PAGE->get_renderer('tool_ilioscategoryassignment');

$mform = $this->_form;
Expand All @@ -53,37 +70,38 @@ public function definition() {
return;
}

$role_options = array();
$roleoptions = [];
foreach ($roles as $role) {
$role_options[$role->id] = $role->localname;
$roleoptions[$role->id] = $role->localname;
}

try {
$ilios_client = manager::instantiate_ilios_client();
$access_token = manager::get_config('apikey', '');
$ilios_schools = $ilios_client->get($access_token, 'schools');
if (!empty($ilios_schools)) {
$ilios_schools = array_column($ilios_schools, 'title', 'id');
$iliosclient = manager::instantiate_ilios_client();
$accesstoken = manager::get_config('apikey', '');
$iliosschools = $iliosclient->get($accesstoken, 'schools');
if (!empty($iliosschools)) {
$iliosschools = array_column($iliosschools, 'title', 'id');
}
} catch (\Exception $e) {
} catch (Exception $e) {
$warning = $renderer->notify_error(get_string('ilioserror', 'tool_ilioscategoryassignment'));
$mform->addElement('html', $warning);
return;
}

$mform->addElement('text', 'title', get_string('title', 'tool_ilioscategoryassignment')); // Add elements to your form
// Add elements to your form.
$mform->addElement('text', 'title', get_string('title', 'tool_ilioscategoryassignment'));
$mform->setType('title', PARAM_NOTAGS);
$mform->addRule('title', null, 'required', null, 'client');
$mform->addRule('title', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');

$mform->addElement('select', 'categoryid', get_string('selectcategory', 'tool_ilioscategoryassignment'), $categories);
$mform->addRule('categoryid', null, 'required', null, 'client');

$mform->addElement('select', 'roleid', get_string('selectrole', 'tool_ilioscategoryassignment'), $role_options);
$mform->addElement('select', 'roleid', get_string('selectrole', 'tool_ilioscategoryassignment'), $roleoptions);
$mform->addRule('roleid', null, 'required', null, 'client');

$mform->addElement('select', 'iliosschoolid', get_string('selectiliosschool', 'tool_ilioscategoryassignment'),
$ilios_schools);
$iliosschools);
$mform->addRule('iliosschoolid', null, 'required', null, 'client');

$this->add_action_buttons(false, get_string('submit'));
Expand Down
Loading

0 comments on commit 0ce4dcc

Please sign in to comment.