Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom dist and release has precedence over the pubspec name #139

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Support custom `dist` and `release` has precedence over the pubspec's `name` ([#139](https://github.com/getsentry/sentry-dart-plugin/pull/139))

### Dependencies

- Bump CLI from v2.19.1 to v2.19.4 ([#133](https://github.com/getsentry/sentry-dart-plugin/pull/133))
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ sentry:
wait_for_processing: false
log_level: error # possible values: trace, debug, info, warn, error
release: ...
dist: ...
web_build_path: ...
commits: auto
ignore_missing: true
Expand All @@ -72,6 +73,7 @@ sentry:
| wait_for_processing | Wait for server-side processing of uploaded files | false (boolean) | no | - |
| log_level | Configures the log level for sentry-cli | warn (string) | no | SENTRY_LOG_LEVEL |
| release | The release version for source maps, it should match the release set by the SDK | default: name@version from pubspec (string) | no | SENTRY_RELEASE |
| dist | The dist/build number for source maps, it should match the dist set by the SDK | default: the number after the '+' char from 'version' pubspec (string) | no | SENTRY_DIST |
| web_build_path | The web build folder | default: build/web (string) | no | - |
| commits | Release commits integration | default: auto | no | - |
| ignore_missing | Ignore missing commits previously used in the release | default: false | no | - |
Expand Down
69 changes: 50 additions & 19 deletions lib/sentry_dart_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ class SentryDartPlugin {
Log.info('uploadNativeSymbols is disabled.');
}

await _executeNewRelease();
final release = _release;

await _executeNewRelease(release);

if (_configuration.uploadSourceMaps) {
await _executeCliForSourceMaps();
await _executeCliForSourceMaps(release);
} else {
Log.info('uploadSourceMaps is disabled.');
}

if (_configuration.commits.toLowerCase() != 'false') {
await _executeSetCommits();
await _executeSetCommits(release);
} else {
Log.info('Commit integration is disabled.');
}

await _executeFinalizeRelease();
await _executeFinalizeRelease(release);
} on ExitError catch (e) {
return e.code;
}
Expand Down Expand Up @@ -90,21 +92,21 @@ class SentryDartPlugin {
return params;
}

Future<void> _executeNewRelease() async {
Future<void> _executeNewRelease(String release) async {
await _executeAndLog('Failed to create a new release',
[..._releasesCliParams(), 'new', _release]);
[..._releasesCliParams(), 'new', release]);
}

Future<void> _executeFinalizeRelease() async {
Future<void> _executeFinalizeRelease(String release) async {
await _executeAndLog('Failed to finalize the new release',
[..._releasesCliParams(), 'finalize', _release]);
[..._releasesCliParams(), 'finalize', release]);
}

Future<void> _executeSetCommits() async {
Future<void> _executeSetCommits(String release) async {
final params = [
..._releasesCliParams(),
'set-commits',
_release,
release,
];

if (['auto', 'true', ''].contains(_configuration.commits.toLowerCase())) {
Expand All @@ -121,7 +123,7 @@ class SentryDartPlugin {
await _executeAndLog('Failed to set commits', params);
}

Future<void> _executeCliForSourceMaps() async {
Future<void> _executeCliForSourceMaps(String release) async {
const taskName = 'uploading source maps';
Log.startingTask(taskName);

Expand All @@ -131,7 +133,7 @@ class SentryDartPlugin {
List<String> releaseJsFilesParams = [];
releaseJsFilesParams.addAll(params);

_addExtensionToParams(['map', 'js'], releaseJsFilesParams, _release,
_addExtensionToParams(['map', 'js'], releaseJsFilesParams, release,
_configuration.webBuildFilesFolder);

_addWait(releaseJsFilesParams);
Expand All @@ -142,7 +144,7 @@ class SentryDartPlugin {
List<String> releaseDartFilesParams = [];
releaseDartFilesParams.addAll(params);

_addExtensionToParams(['dart'], releaseDartFilesParams, _release,
_addExtensionToParams(['dart'], releaseDartFilesParams, release,
_configuration.buildFilesFolder);

_addWait(releaseDartFilesParams);
Expand Down Expand Up @@ -196,9 +198,9 @@ class SentryDartPlugin {
}

void _addExtensionToParams(
List<String> exts, List<String> params, String version, String folder) {
List<String> exts, List<String> params, String release, String folder) {
params.add('files');
params.add(version);
params.add(release);
params.add('upload-sourcemaps');
params.add(folder);

Expand All @@ -207,15 +209,44 @@ class SentryDartPlugin {
params.add(ext);
}

// TODO: add support to custom dist
if (version.contains('+')) {
if (release.contains('+')) {
params.add('--dist');
final values = version.split('+');
final values = release.split('+');
params.add(values.last);
}
}

String get _release => '${_configuration.name}@${_configuration.version}';
String get _release {
var release = '';

if (_configuration.release?.isNotEmpty ?? false) {
release = _configuration.release!;
} else {
release = _configuration.name;
}

if (!release.contains('@')) {
release += '@${_configuration.version}';
}

final dist = _dist;
if (!release.contains('+') && (dist?.isNotEmpty ?? false)) {
release += '+${dist!}';
}
return release;
}

String? get _dist {
if (_configuration.dist?.isNotEmpty ?? false) {
return _configuration.dist!;
}

if (_configuration.version.contains('+')) {
final values = _configuration.version.split('+');
return values.last;
}
return null;
}

void _addWait(List<String> params) {
if (_configuration.waitForProcessing) {
Expand Down
21 changes: 16 additions & 5 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ class Configuration {
// the Sentry CLI path, defaults to the assets folder
late String? cliPath;

/// The Apps version, defaults to version from pubspec
/// The Apps release name, defaults to 'name@version+buildNumber' from pubspec or set via env. var. SENTRY_RELEASE
/// Example, name: 'my_app', version: 2.0.0+1, in this case the release is my_app@2.0.0+1
/// This field has precedence over the [name] from pubspec
/// If this field has a build number, it has precedence over the [version]'s buid number from pubspec
late String? release;

/// The Apps dist/build number, defaults to the build number after the '+' char from [version]'s pubspec or ser via env. var. SENTRY_DIST
/// Example, version: 2.0.0+1, in this case the build number is 1
late String? dist;

/// The Apps version, defaults to [version] from pubspec
/// Example, version: 2.0.0+1, in this case the version is 2.0.0+1
late String version;

/// The Apps name, defaults to name from pubspec
/// The Apps name, defaults to [name] from pubspec
late String name;

/// the Web Build folder, defaults to build/web
Expand Down Expand Up @@ -90,9 +101,9 @@ class Configuration {
final pubspec = _getPubspec();
final config = pubspec['sentry'] as YamlMap?;

version = config?['release']?.toString() ??
environments['SENTRY_RELEASE'] ??
pubspec['version'].toString(); // or env. var. SENTRY_RELEASE
release = config?['release']?.toString() ?? environments['SENTRY_RELEASE'];
dist = config?['dist']?.toString() ?? environments['SENTRY_DIST'];
version = pubspec['version'].toString();
name = pubspec['name'].toString();

uploadDebugSymbols =
Expand Down
62 changes: 62 additions & 0 deletions test/plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,68 @@ $configIndented
]);
});
});

group('custom releases and dists', () {
test('custom release with a dist in it', () async {
final dist = 'myDist';
final customRelease = 'myRelease@myVersion+$dist';

final commandLog = await runWith('''
upload_debug_symbols: false
upload_source_maps: true
release: $customRelease
dist: anotherDist
''');
final args = commonArgs;
expect(commandLog, [
'$cli $args releases $orgAndProject new $customRelease',
'$cli $args releases $orgAndProject files $customRelease upload-sourcemaps $buildDir/build/web --ext map --ext js --dist $dist',
'$cli $args releases $orgAndProject files $customRelease upload-sourcemaps $buildDir --ext dart --dist $dist',
'$cli $args releases $orgAndProject set-commits $customRelease --auto',
'$cli $args releases $orgAndProject finalize $customRelease'
]);
});

test('custom release with a custom dist', () async {
final dist = 'myDist';
final customRelease = 'myRelease@myVersion';
final fullRelease = '$customRelease+$dist';

final commandLog = await runWith('''
upload_debug_symbols: false
upload_source_maps: true
release: $customRelease
dist: $dist
''');
final args = commonArgs;
expect(commandLog, [
'$cli $args releases $orgAndProject new $fullRelease',
'$cli $args releases $orgAndProject files $fullRelease upload-sourcemaps $buildDir/build/web --ext map --ext js --dist $dist',
'$cli $args releases $orgAndProject files $fullRelease upload-sourcemaps $buildDir --ext dart --dist $dist',
'$cli $args releases $orgAndProject set-commits $fullRelease --auto',
'$cli $args releases $orgAndProject finalize $fullRelease'
]);
});

test('custom dist', () async {
final dist = 'myDist';
final fullRelease = '$release+$dist';

final commandLog = await runWith('''
upload_debug_symbols: false
upload_source_maps: true
dist: $dist
''');
final args = commonArgs;
expect(commandLog, [
'$cli $args releases $orgAndProject new $fullRelease',
'$cli $args releases $orgAndProject files $fullRelease upload-sourcemaps $buildDir/build/web --ext map --ext js --dist $dist',
'$cli $args releases $orgAndProject files $fullRelease upload-sourcemaps $buildDir --ext dart --dist $dist',
'$cli $args releases $orgAndProject set-commits $fullRelease --auto',
'$cli $args releases $orgAndProject finalize $fullRelease'
]);
});
});
});
}
}
Expand Down