Skip to content

Commit f7cc49c

Browse files
authored
Merge pull request #144 from rollbar/added/v7-test-workflow
Added a workflow file for testing updates to the v7 branch
2 parents e2fc3fc + c3af14c commit f7cc49c

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

.github/workflows/ci-7.x.yml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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, master
14+
15+
# Fire this action on pushes to main branch (master) as well as other branches
16+
# or pull requests, excluding those in the next/ lineage. Also, run every day
17+
# at 02:42 GMT -- this catches failures from transitive dependencies.
18+
on:
19+
push:
20+
branches:
21+
- next/7.x/**
22+
tags:
23+
- v7.*
24+
pull_request:
25+
branches:
26+
- next/7.x/**
27+
schedule:
28+
- cron: '42 2 * * *'
29+
30+
jobs:
31+
# Check that this runs on all combinations of Laravel we claim to support.
32+
laravel-tests:
33+
strategy:
34+
matrix:
35+
os: [ubuntu]
36+
php: [8.1, 8.0, 7.4, 7.3, 7.2]
37+
laravel: [^9, ^8, ^7, ^6]
38+
exclude:
39+
# Laravel 6 requires php 7.2-8.0, so exclude all php versions after 8.1
40+
- laravel: ^6
41+
php: 8.1
42+
# Laravel 7 requires php 7.2-8.0, so exclude all php versions after 8.1
43+
- laravel: ^7
44+
php: 8.1
45+
# Laravel 8 requires php 7.3+, so exclude all PHP versions prior to 7.3
46+
- laravel: ^8
47+
php: 7.2
48+
# Laravel 9 requires php ^8.0.2, so exclude all PHP versions prior to 8.0.2
49+
- laravel: ^9
50+
php: 7.2
51+
- laravel: ^9
52+
php: 7.3
53+
- laravel: ^9
54+
php: 7.4
55+
env:
56+
ROLLBAR_TOKEN: "ad865e76e7fb496fab096ac07b1dbabb"
57+
name: Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }} (${{ matrix.os }})
58+
runs-on: ${{ matrix.os }}-latest
59+
steps:
60+
- name: Checkout the code
61+
uses: actions/checkout@v2
62+
63+
- name: Install PHP and composer environment
64+
uses: shivammathur/setup-php@v2
65+
with:
66+
php-version: ${{ matrix.php }}
67+
extensions: curl
68+
69+
- name: Create Laravel test app
70+
run: composer create-project laravel/laravel rollbar-test-app ${{ matrix.laravel }}
71+
72+
- name: Install that code using Composer rigged to look in the parent directory
73+
id: composer_require
74+
working-directory: rollbar-test-app
75+
continue-on-error: true
76+
run: |
77+
composer config repositories.local '{"type":"path", "url":".."}'
78+
composer config minimum-stability dev
79+
composer config prefer-stable true
80+
composer require rollbar/rollbar-laravel -W
81+
82+
- name: Setup .env
83+
working-directory: rollbar-test-app
84+
run: |
85+
echo "ROLLBAR_TOKEN=${ROLLBAR_TOKEN}" >> .env
86+
echo "GITHUB_RUN_ID=${GITHUB_RUN_ID}" >> .env
87+
chmod 400 .env
88+
89+
- name: Configure Laravel to use Rollbar and configure Rollbar to invoke logging callback
90+
working-directory: rollbar-test-app
91+
run: |
92+
> config/logging.php echo '<?php return array (
93+
"default" => "rollbar",
94+
"channels" => array (
95+
"rollbar" => array (
96+
"driver" => "monolog",
97+
"handler" => \Rollbar\Laravel\MonologHandler::class,
98+
"access_token" => env("ROLLBAR_TOKEN"),
99+
"level" => "debug",
100+
// use the check_ignore filter to capture log messages for verification
101+
"check_ignore" => "check_ignore",
102+
)
103+
)
104+
);
105+
'
106+
touch app/helpers.php
107+
> tmp-composer.json jq '.autoload += { "files": [ "app/helpers.php" ] }' composer.json
108+
mv tmp-composer.json composer.json
109+
composer dump-autoload
110+
111+
- name: Define logging callback that invokes when Laravel logs through Rollbar
112+
working-directory: rollbar-test-app
113+
run: |
114+
> app/helpers.php echo '<?php
115+
function temp_file() {
116+
return env("RUNNER_TEMP") . DIRECTORY_SEPARATOR . env("GITHUB_RUN_ID") . ".tmp.txt";
117+
}
118+
function check_ignore($isUncaught, $toLog, $payload) {
119+
// write log message to a file for inspection
120+
$ok = file_put_contents(temp_file(), (string)$toLog);
121+
// return indication that the log should be dropped
122+
return true;
123+
}
124+
'
125+
126+
- name: Define Laravel tests to exercise and verify logging
127+
working-directory: rollbar-test-app
128+
run: |
129+
> tests/Feature/LoggingTest.php echo '<?php
130+
namespace Tests\Feature;
131+
class LoggingTest extends \Tests\TestCase {
132+
public function test_log_call_invokes_rollbar_check_ignore()
133+
{
134+
// generate a random valued log message to check it is passed through the
135+
// Laravel logging mechanism into Rollbar
136+
$value = sprintf("%s-%s", env("GITHUB_RUN_ID"), rand());
137+
138+
\Log::error($value);
139+
140+
// check that we have our random value written into our local file
141+
$this->assertFileExists(temp_file(),
142+
"Rollbar check_ignore handler not invoked, suggesting an issue integrating Rollbar into Laravel.");
143+
$this->assertSame($value, file_get_contents(temp_file()),
144+
"check_ignore file did not contain expected value, suggesting file left by another process.");
145+
}
146+
}
147+
'
148+
149+
- name: Invoke the Laravel test suite
150+
working-directory: rollbar-test-app
151+
run: |
152+
./vendor/bin/phpunit

0 commit comments

Comments
 (0)