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