Skip to content

GitHub Actions

Callustian edited this page Jul 5, 2022 · 3 revisions

GitHub Actions

To make the system ready for a refactoring, it was necessary to add system tests to the static tests already present in the configuration.

It was necessary to install Moodle (the entire application) and connect the instance to Apache. After that I had to configure Moodle to accept the data and respond to REST POSTs and GETs.

A few comments to the commands I added to the configuration.

moosh installation

To interact with the system form console I had to install moosh

newman installation

newman is a Javascript library that allows you to run postman tests as they are exported. So it was necessary to add NodeJS to use this library

jq installation

jq is a program that allows the extraction of fields from a JSON string

moodle REST activation

REST is not available at the time Moodle is installed. It is necessary to set the appropriate capabilities. As moosh would work only in the moodle folder it is necessary to cd to that folder

cd moodle/mod/arete
          sudo -u www-data moosh -n config-set enablewebservices 1
          sudo -u www-data moosh -n config-set webserviceprotocols 'rest'
          sudo -u www-data moosh -n role-update-capability user moodle/webservice:createtoken allow 1
          sudo -u www-data moosh -n role-update-capability user webservice/rest:use allow 1

moodle apache configuration

It is necessary to configure apache to recognise the moodle installation

<VirtualHost *:80>
 ServerName www.example.com
  ServerAlias *
  DocumentRoot /home/runner/work/moodle-mod_arete/moodle-mod_arete/
<Directory "/home/runner/work/moodle-mod_arete/moodle-mod_arete/moodle">
    Options -Indexes +FollowSymLinks -MultiViews
    AllowOverride All
    Require all granted\n  </Directory>
</VirtualHost>

Then connect moodle and apache

sudo a2ensite moodle.conf

Then restart apache

sudo systemctl reload apache2 && sudo systemctl status apache2

For the versions we use of php with apache it is necessary to also add these setting

          sudo a2enmod proxy_fcgi setenvif
          sudo a2enconf php${{ matrix.php }}-fpm
          sudo service apache2 restart

Test user

A test user is generated using moosh

sudo -u www-data moosh -n user-create --password ${{ secrets.TEST_USER_PASSWORD }} --email [email protected] --city "Milton Keynes" --country GB --institution "Open University" --department "IET" --firstname "first" --lastname "last" testuser && sudo -u www-data moosh -n role-update-capability testuser moodle/webservice:createtoken allow 1

Running the postman tests

To run the test it is necessary to run

cd moodle/mod/arete/tests/postman/ && ./node_modules/newman/bin/newman.js run --verbose "Moodle Arete.postman_collection.json" --env-var USER_ID=3 --env-var TEST_USER_PASSWORD=${{ secrets.TEST_USER_PASSWORD }} --env-var TOKEN=$(curl -X GET 'http://localhost/moodle/login/token.php?username=testuser&password=${{ secrets.TEST_USER_PASSWORD }}&service=aretews'| jq ".token" | sed s/\"//g)

Three environment variables are passed, the USER_ID, the TEST_USER_PASSWORD and a token is generated using a curl command and passed to TOKEN