diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 46aaace..2a3b6cb 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -11,12 +11,46 @@ on: - '**' jobs: + define-matrix: + runs-on: ubuntu-latest + + outputs: + include_list: ${{ steps.include_list.outputs.include_list }} + + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Define matrix + id: include_list + run: | + # Generates a json array with include entries for all possible combinations of PHP, Moodle branch and database + include_str="[" + first_entry=true + for i in $(cat plugin_compatibility.json | jq -c '.[]'); do + moodle=$(echo "$i" | jq -r '.moodle') + for php in $(echo "$i" | jq -r '.PHP[]'); do + for database in pgsql mariadb; do + if [ "$first_entry" = true ]; then + first_entry=false + else + include_str="$include_str," + fi + next_entry="{\"php\": \"$php\", \"moodle-branch\": \"$moodle\", \"database\": \"$database\", \"experimental\": false}" + include_str="$include_str$next_entry" + done + done + done + include_str="$include_str]" + echo "include_list=$include_str" >> "$GITHUB_OUTPUT" + test: runs-on: ubuntu-22.04 + needs: define-matrix services: postgres: - image: postgres:13 + image: postgres:16 env: POSTGRES_USER: 'postgres' POSTGRES_HOST_AUTH_METHOD: 'trust' @@ -38,15 +72,11 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.1', '8.2', '8.3'] - moodle-branch: ['MOODLE_404_STABLE', 'MOODLE_405_STABLE'] + php: ['8.3'] + moodle-branch: ['main'] database: [pgsql, mariadb] - experimental: [false] - include: - - php: '8.3' - moodle-branch: 'main' - database: mariadb - experimental: true + experimental: [true] + include: ${{ fromJSON(needs.define-matrix.outputs.include_list) }} continue-on-error: ${{ matrix.experimental }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 656156a..fb012c1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Moodle Plugin CI +name: Create release on: release: @@ -24,45 +24,46 @@ jobs: # - release is marked as pre-release on github, then MATURITY_BETA # - release name contains 'rc', then MATURITY_RC if [[ "${{ github.ref_name }}" == *"rc"* ]]; then - sed -i "s/^\$plugin->maturity\s=\sMATURITY_STABLE;/\$plugin->maturity = MATURITY_RC;/" version.php + sed -i "s/^\$plugin->maturity\s=\sMATURITY_[A-Z]*;/\$plugin->maturity = MATURITY_RC;/" version.php elif [[ "${{ github.event_name }}" == "release" && "${{ github.event.release.prerelease }}" == "true" ]]; then - sed -i "s/^\$plugin->maturity\s=\sMATURITY_STABLE;/\$plugin->maturity = MATURITY_BETA;/" version.php - else - sed -i "s/^\$plugin->maturity\s=\sMATURITY_STABLE;/\$plugin->maturity = MATURITY_STABLE;/" version.php + sed -i "s/^\$plugin->maturity\s=\sMATURITY_[A-Z]*;/\$plugin->maturity = MATURITY_BETA;/" version.php + else + sed -i "s/^\$plugin->maturity\s=\sMATURITY_[A-Z]*;/\$plugin->maturity = MATURITY_STABLE;/" version.php fi - name: remove files not needed for release run: | - rm -rf .github tests vendor .gitignore composer.json composer.lock phpunit.xml dev_utils + rm -rf .github tests vendor .gitignore composer.json composer.lock phpunit.xml dev_utils phpunit.xml infection.json5 - - name: Create release archives + - name: Create release archive run: | - tar --exclude='.git' -czf /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.tgz * - zip -x .git -r /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip * + FOLDER_NAME=$(echo ${{ env.PLUGIN_NAME }} | cut -d'_' -f2) + mkdir -p /tmp/$FOLDER_NAME + cp -r * /tmp/$FOLDER_NAME + cd /tmp + zip -r moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip $FOLDER_NAME - - name: Upload release archives + - name: Calculate MD5 hash + run: | + cd /tmp + md5sum /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip > /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip.md5 + + - name: Upload release archive (ZIP) uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip tag: ${{ github.ref_name }} - - name: Upload release archives + - name: Upload MD5 hash files (ZIP) uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.tgz + file: /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip.md5 tag: ${{ github.ref_name }} - - name: Prepare release body (description) - id: prep_body + - name: Upload to package registry run: | - echo "${{ github.event.release.body }}" > changes.md - - - name: Discord notification - uses: appleboy/discord-action@master - with: - webhook_id: ${{ secrets.DISCORD_RELEASE_CHANNEL_WEBHOOK_ID }} - webhook_token: ${{ secrets.DISCORD_RELEASE_CHANNEL_WEBHOOK_TOKEN }} - username: GitHub Releases - message: "New release of **${{ github.repository }}**\nVersion: ${{ github.ref_name }} (${{github.event.release.name}})\n<${{ github.event.release.html_url }}>" - file: changes.md \ No newline at end of file + cd /tmp + MD5_CONTENT=$(awk '{print $1 " '${{ github.ref_name }}.zip'"}' /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip.md5) + curl --fail-with-body -u upload:${{ secrets.PACKAGE_REGISTRY_UPLOAD_PASSWORD }} -T /tmp/moodle-${{ env.PLUGIN_NAME }}-${{ github.ref_name }}.zip https://packages.projekt-adler.eu/upload/moodle/${{ env.PLUGIN_NAME }}/${{ github.ref_name }}.zip + curl --fail-with-body -u upload:${{ secrets.PACKAGE_REGISTRY_UPLOAD_PASSWORD }} -X PUT --data "$MD5_CONTENT" https://packages.projekt-adler.eu/upload/moodle/${{ env.PLUGIN_NAME }}/${{ github.ref_name }}.zip.md5 diff --git a/README.md b/README.md index 1947319..c63449b 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,9 @@ Das Local Logging Plugin ermöglicht eine einfache Protokollierung von Ereignissen in Moodle. Es stellt eine Logger-Klasse zur Verfügung, die es Entwicklern ermöglicht, Nachrichten verschiedener Schweregrade zu protokollieren. ## Kompabilität +Folgende Versionen werden unterstützt (mit mariadb und postresql getestet): -| Moodle Branch | PHP Version | -|-------------------------|-------------| -| MOODLE_404_STABLE | 8.1 | -| MOODLE_404_STABLE | 8.2 | -| MOODLE_404_STABLE | 8.3 | -| MOODLE_405_STABLE (LTS) | 8.1 | -| MOODLE_405_STABLE (LTS) | 8.2 | -| MOODLE_405_STABLE (LTS) | 8.3 | - +siehe [plugin_compatibility.json](plugin_compatibility.json) ## Funktionsweise diff --git a/classes/hook_listener.php b/classes/hook_listener.php index f7ad380..ee81131 100644 --- a/classes/hook_listener.php +++ b/classes/hook_listener.php @@ -2,9 +2,11 @@ namespace local_logging; +use core\di; use core\hook\di_configuration; use local_logging\local\output\log_output; use local_logging\local\output\log_output_db; +use local_logging\local\output\log_output_mtrace; use local_logging\local\output\log_output_stdout; class hook_listener { @@ -12,11 +14,13 @@ public static function inject_dependencies(di_configuration $hook): void { $hook->add_definition( id: log_output::class, definition: function (): log_output { - if (defined('CLI_SCRIPT') || defined('PHPUNIT_TEST')) { - return new log_output_stdout(); - } else { - return new log_output_db(); - } + return di::get(log_output_mtrace::class); +// if (defined('CLI_SCRIPT') || defined('PHPUNIT_TEST')) { +// return new log_output_stdout(); +// return di::get(log_output_mtrace::class); +// } else { +// return di::get(log_output_db::class); +// } } ); } diff --git a/classes/local/output/log_output_mtrace.php b/classes/local/output/log_output_mtrace.php new file mode 100644 index 0000000..64282e8 --- /dev/null +++ b/classes/local/output/log_output_mtrace.php @@ -0,0 +1,13 @@ +dirroot . '/local/logging/tests/lib/adler_testcase.php'); + +class log_output_mtrace_test extends adler_testcase { + public function test_output() { + // Create an instance of log_output_stdout. + $logOutput = new log_output_mtrace(); + + // Define test data. + $message = 'Test message'; + $level = util::LEVEL_TRACE; // Assuming 100 corresponds to TRACE level + $component = 'testcomponent'; + $title = 'testtitle'; + $time = time(); + $user_id = null; + + // Start output buffering. + ob_start(); + + // Call the output method. + $logOutput->output($message, $level, $component, $title, $time, $user_id); + + // Get the output and clean the buffer. + $output = ob_get_clean(); + + // Assert that the output contains the expected components. + $this->assertStringContainsString('[' . date('Y-m-d H:i:s', $time) . ']', $output); + $this->assertStringContainsString('TRACE', $output); + $this->assertStringContainsString($component, $output); + $this->assertStringContainsString($title . ':', $output); + $this->assertStringContainsString($message, $output); + } +} \ No newline at end of file diff --git a/tests/local/output/log_output_stdout_test.php b/tests/local/output/log_output_stdout_test.php index 5a87bed..22fdd00 100644 --- a/tests/local/output/log_output_stdout_test.php +++ b/tests/local/output/log_output_stdout_test.php @@ -1,7 +1,8 @@