diff --git a/.github/workflows/analyze.yml b/.github/workflows/analyze.yml index 2ebce36cac..9b418a78d9 100644 --- a/.github/workflows/analyze.yml +++ b/.github/workflows/analyze.yml @@ -24,7 +24,6 @@ jobs: access_token: ${{ github.token }} analyze: - name: Format, fix & analyze Code if: ${{ !startsWith(github.ref, 'refs/heads/release/') }} runs-on: ubuntu-latest timeout-minutes: 20 @@ -39,17 +38,8 @@ jobs: if: ${{ inputs.sdk == 'flutter' }} - run: ${{ inputs.sdk }} pub get - - - run: dart format . - - - run: dart fix --apply - - # actions/checkout fetches only a single commit in a detached HEAD state. Therefore - # we need to pass the current branch, otherwise we can't commit the changes. - # GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs. - - run: ../scripts/commit-formatted-code.sh $GITHUB_HEAD_REF - if: env.GITHUB_HEAD_REF != null - + - run: dart format --set-exit-if-changed ./ + - name: dart analyze uses: invertase/github-action-dart-analyzer@1cda5922c6369263b1c7e2fbe281f69704f4d63e # pin@v2.0.0 with: diff --git a/.github/workflows/format-and-fix.yml b/.github/workflows/format-and-fix.yml new file mode 100644 index 0000000000..fa77a33098 --- /dev/null +++ b/.github/workflows/format-and-fix.yml @@ -0,0 +1,54 @@ +on: + workflow_dispatch: + +jobs: + cancel-previous-workflow: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # pin@0.11.0 + with: + access_token: ${{ github.token }} + + format-and-fix: + name: Format & fix code + if: ${{ !startsWith(github.ref, 'refs/heads/release/') }} + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + matrix: + package: [ + {name: dart, sdk: dart}, + {name: dio, sdk: dart}, + {name: file, sdk: dart}, + {name: flutter, sdk: flutter}, + {name: logging, sdk: dart}, + {name: sqflite, sdk: flutter}, + ] + defaults: + run: + working-directory: ${{ matrix.package.name }} + steps: + - uses: actions/checkout@v3 + - uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d # pin@v1 + if: ${{ matrix.package.sdk == 'dart' }} + - uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa # pin@v2.10.0 + if: ${{ matrix.package.sdk == 'flutter' }} + + - run: ${{ matrix.package.sdk }} pub get + + - run: dart format . + + - run: dart fix --apply + + # Source: https://stackoverflow.com/a/58035262 + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + + # actions/checkout fetches only a single commit in a detached HEAD state. Therefore + # we need to pass the current branch, otherwise we can't commit the changes. + # GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs. + - name: Commit & push + run: ./scripts/commit-formatted-code.sh ${{ steps.extract_branch.outputs.branch }} diff --git a/dio/test/dio_event_processor_test.dart b/dio/test/dio_event_processor_test.dart index af45d0c681..3cd060ea8e 100644 --- a/dio/test/dio_event_processor_test.dart +++ b/dio/test/dio_event_processor_test.dart @@ -67,7 +67,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -96,7 +96,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -125,7 +125,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -177,7 +177,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -207,7 +207,7 @@ void main() { data: 'foobar', headers: Headers.fromMap(>{ 'foo': ['bar'], - 'set-cookie': ['foo=bar'] + 'set-cookie': ['foo=bar'], }), requestOptions: request, isRedirect: true, @@ -219,7 +219,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -248,7 +248,7 @@ void main() { response: Response( data: 'foobar', headers: Headers.fromMap(>{ - 'foo': ['bar'] + 'foo': ['bar'], }), requestOptions: request, isRedirect: true, @@ -260,7 +260,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -320,7 +320,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; @@ -338,7 +338,7 @@ void main() { final dataByType = { ResponseType.plain: ['plain'], ResponseType.bytes: [ - [1337] + [1337], ], ResponseType.json: [ 9001, @@ -347,7 +347,7 @@ void main() { true, ['list'], {'map-key': 'map-value'}, - ] + ], }; for (final entry in dataByType.entries) { @@ -375,7 +375,7 @@ void main() { throwable: throwable, exceptions: [ fixture.sentryError(throwable), - fixture.sentryError(dioError) + fixture.sentryError(dioError), ], ); final processedEvent = sut.apply(event) as SentryEvent; diff --git a/dio/test/failed_request_interceptor_test.dart b/dio/test/failed_request_interceptor_test.dart index 80eede8803..e7fb5a63e1 100644 --- a/dio/test/failed_request_interceptor_test.dart +++ b/dio/test/failed_request_interceptor_test.dart @@ -113,7 +113,7 @@ class Fixture { FailedRequestInterceptor getSut({ List failedRequestStatusCodes = const [ - SentryStatusCode.defaultRange() + SentryStatusCode.defaultRange(), ], List failedRequestTargets = const ['.*'], }) { diff --git a/dio/test/mocks.dart b/dio/test/mocks.dart index 83454cbfb3..5ed6dcd00a 100644 --- a/dio/test/mocks.dart +++ b/dio/test/mocks.dart @@ -42,7 +42,7 @@ final fakeEvent = SentryEvent( type: 'navigation', data: {'screen': 'MainActivity', 'state': 'created'}, level: SentryLevel.info, - ) + ), ], contexts: Contexts( operatingSystem: const SentryOperatingSystem( diff --git a/flutter/test/sentry_navigator_observer_test.dart b/flutter/test/sentry_navigator_observer_test.dart index d3871b4390..d4c2499efc 100644 --- a/flutter/test/sentry_navigator_observer_test.dart +++ b/flutter/test/sentry_navigator_observer_test.dart @@ -756,6 +756,7 @@ class _MockHub extends MockHub { @override final options = SentryOptions(dsn: fakeDsn); + @override late final scope = Scope(options); @override diff --git a/sqflite/lib/src/sentry_database.dart b/sqflite/lib/src/sentry_database.dart index 71147c3464..d148eb7ded 100644 --- a/sqflite/lib/src/sentry_database.dart +++ b/sqflite/lib/src/sentry_database.dart @@ -58,8 +58,11 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database { @internal Hub? hub, }) : _hub = hub ?? HubAdapter(), dbName = p.basenameWithoutExtension(_database.path), - super(_database, - hub: hub, dbName: p.basenameWithoutExtension(_database.path)) { + super( + _database, + hub: hub, + dbName: p.basenameWithoutExtension(_database.path), + ) { // ignore: invalid_use_of_internal_member final options = _hub.options; options.sdk.addIntegration('SentrySqfliteTracing'); @@ -132,8 +135,12 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database { setDatabaseAttributeData(span, dbName); Future newAction(Transaction txn) async { - final executor = SentryDatabaseExecutor(txn, - parentSpan: span, hub: _hub, dbName: dbName); + final executor = SentryDatabaseExecutor( + txn, + parentSpan: span, + hub: _hub, + dbName: dbName, + ); final sentrySqfliteTransaction = SentrySqfliteTransaction(executor, hub: _hub, dbName: dbName); diff --git a/sqflite/test/mocks/mocks.dart b/sqflite/test/mocks/mocks.dart index 3f0af8274c..bcafb94302 100644 --- a/sqflite/test/mocks/mocks.dart +++ b/sqflite/test/mocks/mocks.dart @@ -34,7 +34,8 @@ ISentrySpan startTransactionShim( ], customMocks: [ MockSpec( - fallbackGenerators: {#startTransaction: startTransactionShim}), + fallbackGenerators: {#startTransaction: startTransactionShim}, + ), ], ) void main() {} diff --git a/sqflite/test/sentry_batch_test.dart b/sqflite/test/sentry_batch_test.dart index ce6f59e0d5..e3b24d811a 100644 --- a/sqflite/test/sentry_batch_test.dart +++ b/sqflite/test/sentry_batch_test.dart @@ -296,7 +296,9 @@ SELECT * FROM Product'''; final span = fixture.tracer.children.last; expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem); expect( - span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName); + span.data[SentryDatabase.dbNameKey], + (db as SentryDatabase).dbName, + ); await db.close(); }); @@ -313,7 +315,9 @@ SELECT * FROM Product'''; final span = fixture.tracer.children.last; expect(span.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem); expect( - span.data[SentryDatabase.dbNameKey], (db as SentryDatabase).dbName); + span.data[SentryDatabase.dbNameKey], + (db as SentryDatabase).dbName, + ); await db.close(); }); diff --git a/sqflite/test/sentry_database_test.dart b/sqflite/test/sentry_database_test.dart index e05bd2367c..5c954426bb 100644 --- a/sqflite/test/sentry_database_test.dart +++ b/sqflite/test/sentry_database_test.dart @@ -112,7 +112,9 @@ void main() { expect(insertSpan.context.parentSpanId, trSpan.context.spanId); expect(insertSpan.status, SpanStatus.ok()); expect( - insertSpan.data[SentryDatabase.dbSystemKey], SentryDatabase.dbSystem); + insertSpan.data[SentryDatabase.dbSystemKey], + SentryDatabase.dbSystem, + ); expect(insertSpan.data[SentryDatabase.dbNameKey], inMemoryDatabasePath); expect(