|
| 1 | +# Primary CI checks for Rollbar-PHP-Laravel. |
| 2 | +# We're checking that logging within Laravel passes through the Rollbar Laravel |
| 3 | +# integration when that integration is properly installed. We make this check |
| 4 | +# for all supported combinations of Laravel, Rollbar, and PHP. We are not |
| 5 | +# checking that messages are properly sent to Rollbar: that's handled by |
| 6 | +# rollbar-php. |
| 7 | +# |
| 8 | +# Test with act: |
| 9 | +# brew install act |
| 10 | +# act -P ubuntu-latest=shivammathur/node:latest |
| 11 | +# |
| 12 | +# @see https://github.com/nektos/act/issues/329 |
| 13 | +name: Rollbar-PHP-Laravel CI, version 4.x |
| 14 | + |
| 15 | +# Fire this action on pushes to 4.x legacy branches (the official one, as well |
| 16 | +# as development branches within it -- hence the wildcard), and also tags for |
| 17 | +# the legacy lineage. Also, run every day at 02:42 GMT to catch failures from |
| 18 | +# transitive dependencies. |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + branches: |
| 23 | + - next/4.x/** |
| 24 | + tags: |
| 25 | + - v4.* |
| 26 | + pull_request: |
| 27 | + branches: |
| 28 | + - next/4.x/** |
| 29 | + schedule: |
| 30 | + - cron: '42 2 * * *' |
| 31 | + |
| 32 | +jobs: |
| 33 | + # Check that this runs on all combinations of Laravel we claim to support. |
| 34 | + laravel-tests: |
| 35 | + strategy: |
| 36 | + matrix: |
| 37 | + os: [ubuntu] |
| 38 | + php: [7.4, 7.3, 7.2, 7.1] |
| 39 | + laravel: [^5.8, ^5.7, ^5.6] |
| 40 | + env: |
| 41 | + ROLLBAR_TOKEN: "ad865e76e7fb496fab096ac07b1dbabb" |
| 42 | + name: Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }} (${{ matrix.os }}) |
| 43 | + runs-on: ${{ matrix.os }}-latest |
| 44 | + steps: |
| 45 | + - name: Checkout the code |
| 46 | + uses: actions/checkout@v2 |
| 47 | + |
| 48 | + - name: Install PHP and composer environment |
| 49 | + uses: shivammathur/setup-php@v2 |
| 50 | + with: |
| 51 | + php-version: ${{ matrix.php }} |
| 52 | + extensions: curl |
| 53 | + |
| 54 | + - name: Create Laravel test app |
| 55 | + run: composer create-project laravel/laravel rollbar-test-app ${{ matrix.laravel }} |
| 56 | + |
| 57 | + - name: Install that code using Composer rigged to look in the parent directory |
| 58 | + working-directory: rollbar-test-app |
| 59 | + run: | |
| 60 | + composer config repositories.local '{"type":"path", "url":".."}' |
| 61 | + composer require rollbar/rollbar-laravel |
| 62 | + echo "ROLLBAR_TOKEN=${ROLLBAR_TOKEN}" >> .env |
| 63 | + echo "GITHUB_RUN_ID=${GITHUB_RUN_ID}" >> .env |
| 64 | + chmod 400 .env |
| 65 | +
|
| 66 | + - name: Configure Laravel to use Rollbar and configure Rollbar to invoke logging callback |
| 67 | + working-directory: rollbar-test-app |
| 68 | + run: | |
| 69 | + > config/logging.php echo '<?php return array ( |
| 70 | + "default" => "rollbar", |
| 71 | + "channels" => array ( |
| 72 | + "rollbar" => array ( |
| 73 | + "driver" => "monolog", |
| 74 | + "handler" => \Rollbar\Laravel\MonologHandler::class, |
| 75 | + "access_token" => env("ROLLBAR_TOKEN"), |
| 76 | + "level" => "debug", |
| 77 | + // use the check_ignore filter to capture log messages for verification |
| 78 | + "check_ignore" => "check_ignore", |
| 79 | + ) |
| 80 | + ) |
| 81 | + ); |
| 82 | + ' |
| 83 | + touch app/helpers.php |
| 84 | + > tmp-composer.json jq '.autoload += { "files": [ "app/helpers.php" ] }' composer.json |
| 85 | + mv tmp-composer.json composer.json |
| 86 | + composer dump-autoload |
| 87 | +
|
| 88 | + - name: Define logging callback that invokes when Laravel logs through Rollbar |
| 89 | + working-directory: rollbar-test-app |
| 90 | + run: | |
| 91 | + > app/helpers.php echo '<?php |
| 92 | + function temp_file() { |
| 93 | + return env("RUNNER_TEMP") . DIRECTORY_SEPARATOR . env("GITHUB_RUN_ID") . ".tmp.txt"; |
| 94 | + } |
| 95 | + function check_ignore($isUncaught, $toLog, $payload) { |
| 96 | + // write log message to a file for inspection |
| 97 | + $ok = file_put_contents(temp_file(), (string)$toLog); |
| 98 | + // return indication that the log should be dropped |
| 99 | + return true; |
| 100 | + } |
| 101 | + ' |
| 102 | +
|
| 103 | + - name: Define Laravel tests to exercise and verify logging |
| 104 | + working-directory: rollbar-test-app |
| 105 | + run: | |
| 106 | + > tests/Feature/LoggingTest.php echo '<?php |
| 107 | + namespace Tests\Feature; |
| 108 | + class LoggingTest extends \Tests\TestCase { |
| 109 | + public function test_log_call_invokes_rollbar_check_ignore() |
| 110 | + { |
| 111 | + // generate a random valued log message to check it is passed through the |
| 112 | + // Laravel logging mechanism into Rollbar |
| 113 | + $value = sprintf("%s-%s", env("GITHUB_RUN_ID"), rand()); |
| 114 | +
|
| 115 | + \Log::error($value); |
| 116 | +
|
| 117 | + // check that we have our random value written into our local file |
| 118 | + $this->assertFileExists(temp_file(), |
| 119 | + "Rollbar check_ignore handler not invoked, suggesting an issue integrating Rollbar into Laravel."); |
| 120 | + $this->assertSame($value, file_get_contents(temp_file()), |
| 121 | + "check_ignore file did not contain expected value, suggesting file left by another process."); |
| 122 | + } |
| 123 | + } |
| 124 | + ' |
| 125 | +
|
| 126 | + - name: Invoke the Laravel test suite |
| 127 | + working-directory: rollbar-test-app |
| 128 | + run: | |
| 129 | + ./vendor/bin/phpunit |
0 commit comments