Skip to content

Commit 0195e65

Browse files
authored
ref: Use constant for the SDK version (#1374)
1 parent d1916d1 commit 0195e65

File tree

8 files changed

+38
-15
lines changed

8 files changed

+38
-15
lines changed

.craft.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ statusProvider:
77
name: github
88
artifactProvider:
99
name: none
10-
preReleaseCommand: ""
1110
targets:
1211
- name: github
1312
- name: registry

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Use constant for the SDK version (#1367)
6+
57
## 3.8.1 (2022-09-21)
68

79
- fix: Do not throw an TypeError on numeric HTTP headers (#1370)

scripts/bump-version.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -eux
3+
4+
if [ "$(uname -s)" != "Linux" ]; then
5+
echo "Please use the GitHub Action."
6+
exit 1
7+
fi
8+
9+
SCRIPT_DIR="$( dirname "$0" )"
10+
cd $SCRIPT_DIR/..
11+
12+
OLD_VERSION="${1}"
13+
NEW_VERSION="${2}"
14+
15+
echo "Current version: $OLD_VERSION"
16+
echo "Bumping version: $NEW_VERSION"
17+
18+
function replace() {
19+
! grep "$2" $3
20+
perl -i -pe "s/$1/$2/g" $3
21+
grep "$2" $3 # verify that replacement was successful
22+
}
23+
24+
replace "SDK_VERSION = '[0-9.]+'" "SDK_VERSION = '$NEW_VERSION'" ./src/Client.php

src/Client.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Sentry;
66

77
use GuzzleHttp\Promise\PromiseInterface;
8-
use Jean85\PrettyVersions;
98
use Psr\Log\LoggerInterface;
109
use Psr\Log\NullLogger;
1110
use Sentry\Integration\IntegrationInterface;
@@ -33,6 +32,11 @@ final class Client implements ClientInterface
3332
*/
3433
public const SDK_IDENTIFIER = 'sentry.php';
3534

35+
/**
36+
* The version of the SDK.
37+
*/
38+
public const SDK_VERSION = '3.8.0';
39+
3640
/**
3741
* @var Options The client options
3842
*/
@@ -102,7 +106,7 @@ public function __construct(
102106
$this->representationSerializer = $representationSerializer ?? new RepresentationSerializer($this->options);
103107
$this->stacktraceBuilder = new StacktraceBuilder($options, $this->representationSerializer);
104108
$this->sdkIdentifier = $sdkIdentifier ?? self::SDK_IDENTIFIER;
105-
$this->sdkVersion = $sdkVersion ?? PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
109+
$this->sdkVersion = $sdkVersion ?? self::SDK_VERSION;
106110
}
107111

108112
/**

src/ClientBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Sentry;
66

77
use Http\Discovery\Psr17FactoryDiscovery;
8-
use Jean85\PrettyVersions;
98
use Psr\Log\LoggerInterface;
109
use Sentry\HttpClient\HttpClientFactory;
1110
use Sentry\Serializer\RepresentationSerializerInterface;
@@ -59,7 +58,7 @@ final class ClientBuilder implements ClientBuilderInterface
5958
/**
6059
* @var string The SDK version of the Client
6160
*/
62-
private $sdkVersion;
61+
private $sdkVersion = Client::SDK_VERSION;
6362

6463
/**
6564
* Class constructor.
@@ -69,7 +68,6 @@ final class ClientBuilder implements ClientBuilderInterface
6968
public function __construct(Options $options = null)
7069
{
7170
$this->options = $options ?? new Options();
72-
$this->sdkVersion = PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
7371
}
7472

7573
/**

src/Event.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Sentry;
66

7-
use Jean85\PrettyVersions;
87
use Sentry\Context\OsContext;
98
use Sentry\Context\RuntimeContext;
109
use Sentry\Tracing\Span;
@@ -153,7 +152,7 @@ final class Event
153152
/**
154153
* @var string The Sentry SDK version
155154
*/
156-
private $sdkVersion;
155+
private $sdkVersion = Client::SDK_VERSION;
157156

158157
/**
159158
* @var EventType The type of the Event
@@ -164,7 +163,6 @@ private function __construct(?EventId $eventId, EventType $eventType)
164163
{
165164
$this->id = $eventId ?? EventId::generate();
166165
$this->timestamp = microtime(true);
167-
$this->sdkVersion = PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
168166
$this->type = $eventType;
169167
}
170168

tests/ClientBuilderTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Sentry\Tests;
66

7-
use Jean85\PrettyVersions;
87
use PHPUnit\Framework\TestCase;
98
use Sentry\Client;
109
use Sentry\ClientBuilder;
@@ -38,14 +37,13 @@ public function testNullTransportIsUsedWhenNoServerIsConfigured(): void
3837
public function testClientBuilderFallbacksToDefaultSdkIdentifierAndVersion(): void
3938
{
4039
$callbackCalled = false;
41-
$expectedVersion = PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
4240

4341
$options = new Options();
44-
$options->setBeforeSendCallback(function (Event $event) use ($expectedVersion, &$callbackCalled) {
42+
$options->setBeforeSendCallback(function (Event $event) use (&$callbackCalled) {
4543
$callbackCalled = true;
4644

4745
$this->assertSame(Client::SDK_IDENTIFIER, $event->getSdkIdentifier());
48-
$this->assertSame($expectedVersion, $event->getSdkVersion());
46+
$this->assertSame(Client::SDK_VERSION, $event->getSdkVersion());
4947

5048
return null;
5149
});

tests/Serializer/PayloadSerializerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Sentry\Tests\Serializer;
66

7-
use Jean85\PrettyVersions;
87
use PHPUnit\Framework\TestCase;
98
use Sentry\Breadcrumb;
9+
use Sentry\Client;
1010
use Sentry\Context\OsContext;
1111
use Sentry\Context\RuntimeContext;
1212
use Sentry\Event;
@@ -65,7 +65,7 @@ public function serializeDataProvider(): iterable
6565
{
6666
ClockMock::withClockMock(1597790835);
6767

68-
$sdkVersion = PrettyVersions::getVersion('sentry/sentry')->getPrettyVersion();
68+
$sdkVersion = Client::SDK_VERSION;
6969

7070
yield [
7171
Event::createEvent(new EventId('fc9442f5aef34234bb22b9a615e30ccd')),

0 commit comments

Comments
 (0)