Skip to content

Commit

Permalink
add workflow for analyze, fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Grodien committed Oct 30, 2024
1 parent 61680fe commit 6b2d6db
Show file tree
Hide file tree
Showing 73 changed files with 349 additions and 295 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/flutter_android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand All @@ -52,8 +52,6 @@ jobs:
echo "ANDROID_KEY_PASSWORD=$ANDROID_KEY_PASSWORD" >> "$GITHUB_ENV"
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
- run: flutter pub run custom_lint
- run: flutter test
- run: flutter build appbundle --flavor dev -t lib/main_dev.dart
- run: flutter build appbundle --flavor inte -t lib/main_inte.dart
- run: flutter build appbundle --flavor prod -t lib/main_prod.dart
59 changes: 59 additions & 0 deletions .github/workflows/flutter_build_test_analyze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Flutter Android Build

defaults:
run:
working-directory: das_client

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on:
push:
paths:
- 'das_client/**'
pull_request:
paths:
- 'das_client/**'
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.24.3'
- name: Prepare Flutter Build
env:
ANDROID_KEYSTORE_STRING: ${{ secrets.ANDROID_KEYSTORE }}
ANDROID_KEYSTORE: ${{ github.workspace }}/das_client/android/das.keystore
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: |
echo $ANDROID_KEYSTORE_STRING | base64 -d > $ANDROID_KEYSTORE
echo "ANDROID_KEYSTORE=$ANDROID_KEYSTORE" >> "$GITHUB_ENV"
echo "ANDROID_KEYSTORE_PASSWORD=$ANDROID_KEYSTORE_PASSWORD" >> "$GITHUB_ENV"
echo "ANDROID_KEY_ALIAS=$ANDROID_KEY_ALIAS" >> "$GITHUB_ENV"
echo "ANDROID_KEY_PASSWORD=$ANDROID_KEY_PASSWORD" >> "$GITHUB_ENV"
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
- run: flutter pub run custom_lint
- run: flutter test
- run: flutter build appbundle --flavor dev -t lib/main_dev.dart
- run: flutter build appbundle --flavor inte -t lib/main_inte.dart
- run: flutter build appbundle --flavor prod -t lib/main_prod.dart
1 change: 0 additions & 1 deletion .github/workflows/flutter_ios_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
run: |
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
- run: flutter test
- name: Build iOS App DEV
run: flutter build ipa --flavor dev -t lib/main_dev.dart --release --no-codesign
- name: Build iOS App INTE
Expand Down
5 changes: 2 additions & 3 deletions das_client/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ linter:
# producing the lint.
rules:
always_use_package_imports: true
prefer_single_quotes: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Expand All @@ -31,6 +32,4 @@ analyzer:
- custom_lint
exclude:
- lib/**.g.dart
- test/**.mocks.dart
errors:
invalid_annotation_target: ignore
- test/**.mocks.dart
12 changes: 6 additions & 6 deletions das_client/das_custom_lints/lib/dont_use_src_folder_imports.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ class DontUseSrcFolderImports extends DartLintRule {
CustomLintContext context,
) {

// A call back fn that runs on all variable declarations in a file
// A call back fn that runs on all import declarations in a file
context.registry.addImportDirective((importDirective) {
var importUri = importDirective.uri.stringValue;

if (importUri == null || !importUri.contains('/src/')) return;

var filePath = importDirective.element!.source.fullName;
if (!filePath.contains("/lib/")) return;
if (!filePath.contains('/lib/')) return;

importUri = importUri.substring(importUri.indexOf("/") + 1);
filePath = filePath.substring(filePath.indexOf("/lib/") + 5);
importUri = importUri.substring(importUri.indexOf('/') + 1);
filePath = filePath.substring(filePath.indexOf('/lib/') + 5);

final importParts = importUri.split("/src/");
final fileParts = filePath.split("/src/");
final importParts = importUri.split('/src/');
final fileParts = filePath.split('/src/');
if (fileParts[0].startsWith(importParts[0])) return;

// report a lint error with the `code` and the respective import directive
Expand Down
1 change: 0 additions & 1 deletion das_client/das_custom_lints/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ dependencies:
analyzer: ^6.7.0
analyzer_plugin: ^0.11.2
custom_lint_builder: ^0.7.0
# path: ../../../dart_custom_lint/packages/custom_lint_builder
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IntegrationtestAuthenticator implements Authenticator {

@override
Future<String> userId({String? tokenId}) async {
return "tester@testeee.com";
return 'tester@testeee.com';
}

OidcToken _token() {
Expand Down
16 changes: 8 additions & 8 deletions das_client/integration_test/auth/mqtt_client_user_connector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ import 'package:fimber/fimber.dart';
import 'package:mqtt_client/mqtt_client.dart';

class MqttClientUserConnector implements MqttClientConnector {
static const mqttUsername = "MQTT_USERNAME";
static const mqttPassword = "MQTT_PASSWORD";
static const mqttUsername = 'MQTT_USERNAME';
static const mqttPassword = 'MQTT_PASSWORD';

@override
Future<bool> connect(MqttClient client, String company, String train) async {
Fimber.i("Connecting to mqtt using static login and password");
Fimber.i('Connecting to mqtt using static login and password');

if (!const bool.hasEnvironment(mqttUsername) || !const bool.hasEnvironment(mqttPassword)) {
Fimber.e("$mqttUsername or $mqttPassword not defined");
Fimber.e('$mqttUsername or $mqttPassword not defined');
return false;
}

try {
var mqttClientConnectionStatus =
await client.connect(const String.fromEnvironment(mqttUsername), const String.fromEnvironment(mqttPassword));
Fimber.i("mqttClientConnectionStatus=$mqttClientConnectionStatus");
Fimber.i('mqttClientConnectionStatus=$mqttClientConnectionStatus');

if (mqttClientConnectionStatus?.state == MqttConnectionState.connected) {
Fimber.i("Successfully connected to MQTT broker");
Fimber.i('Successfully connected to MQTT broker');
return true;
}
} catch (e) {
Fimber.e("Exception during connect", ex: e);
Fimber.e('Exception during connect', ex: e);
}

Fimber.w("Failed to connect to MQTT broker");
Fimber.w('Failed to connect to MQTT broker');
return false;
}
}
2 changes: 1 addition & 1 deletion das_client/lib/auth/token_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:meta/meta.dart';
@sealed
@immutable
class TokenSpec {
static const String defaultTokenId = "T1";
static const String defaultTokenId = 'T1';

const TokenSpec({
required this.id,
Expand Down
4 changes: 2 additions & 2 deletions das_client/lib/bloc/fahrbild_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FahrbildCubit extends Cubit<FahrbildState> {
final company = currentState.company;
final trainNumber = currentState.trainNumber;
if (company == null || trainNumber == null) {
Fimber.i("company or trainNumber null");
Fimber.i('company or trainNumber null');
return;
}

Expand Down Expand Up @@ -81,7 +81,7 @@ class FahrbildCubit extends Cubit<FahrbildState> {

void reset() {
if (state is BaseFahrbildState) {
Fimber.i("Reseting fahrbild cubit in state $state");
Fimber.i('Reseting fahrbild cubit in state $state');
emit(SelectingFahrbildState(
trainNumber: (state as BaseFahrbildState).trainNumber, company: (state as BaseFahrbildState).company));
}
Expand Down
2 changes: 1 addition & 1 deletion das_client/lib/bloc/fahrbild_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class BaseFahrbildState extends FahrbildState {

@override
String toString() {
return "${runtimeType.toString()}(company=$company, trainNumber=$trainNumber, date=$date)";
return '${runtimeType.toString()}(company=$company, trainNumber=$trainNumber, date=$date)';
}
}

Expand Down
8 changes: 4 additions & 4 deletions das_client/lib/flavor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ enum Flavor {

const _authenticatorConfigTmsDev = AuthenticatorConfig(
discoveryUrl:
"https://login.microsoftonline.com/2cda5d11-f0ac-46b3-967d-af1b2e1bd01a/v2.0/.well-known/openid-configuration",
'https://login.microsoftonline.com/2cda5d11-f0ac-46b3-967d-af1b2e1bd01a/v2.0/.well-known/openid-configuration',
clientId: '8af8281c-4f1d-47b5-ad77-526b1da61b2b',
redirectUrl: 'ch.sbb.das://sbbauth/redirect',
tokenSpecs: TokenSpecProvider([
Expand All @@ -70,7 +70,7 @@ const _authenticatorConfigTmsDev = AuthenticatorConfig(
);

const _authenticatorConfigMockDev = AuthenticatorConfig(
discoveryUrl: "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration",
discoveryUrl: 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration',
clientId: '6025180f-123b-4f2f-9703-16e08fc221f0',
redirectUrl: 'ch.sbb.das://sbbauth/redirect',
tokenSpecs: TokenSpecProvider([
Expand All @@ -83,7 +83,7 @@ const _authenticatorConfigMockDev = AuthenticatorConfig(
);

const _authenticatorConfigInte = AuthenticatorConfig(
discoveryUrl: "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration",
discoveryUrl: 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration',
clientId: '6025180f-123b-4f2f-9703-16e08fc221f0',
redirectUrl: 'ch.sbb.das://sbbauth/redirect',
tokenSpecs: TokenSpecProvider([
Expand All @@ -96,7 +96,7 @@ const _authenticatorConfigInte = AuthenticatorConfig(
);

const _authenticatorConfigProd = AuthenticatorConfig(
discoveryUrl: "https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration",
discoveryUrl: 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration',
clientId: '6025180f-123b-4f2f-9703-16e08fc221f0',
redirectUrl: 'ch.sbb.das://sbbauth/redirect',
tokenSpecs: TokenSpecProvider([
Expand Down
22 changes: 11 additions & 11 deletions das_client/lib/logging/src/das_log_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DasLogTree extends LogTree {
}

void _processAndroidDeviceInfo(AndroidDeviceInfo deviceInfo) {
metadata['systemName'] = "android";
metadata['systemName'] = 'android';
metadata['systemVersion'] = deviceInfo.version.sdkInt.toString();
metadata['model'] = deviceInfo.model;
}
Expand All @@ -46,7 +46,7 @@ class DasLogTree extends LogTree {

@override
List<String> getLevels() {
return ["I", "W", "E"];
return ['I', 'W', 'E'];
}

@override
Expand All @@ -57,32 +57,32 @@ class DasLogTree extends LogTree {
void logInternal(String level, String message, {String? tag, ex, StackTrace? stacktrace}) async {
await _initialized;

final messageBuilder = StringBuffer("$tag:\t $message");
final messageBuilder = StringBuffer('$tag:\t $message');

if (ex != null) {
messageBuilder.write("\n$ex");
messageBuilder.write('\n$ex');
}
if (stacktrace != null) {
final tmpStacktrace = stacktrace.toString().split('\n');
final stackTraceMessage =
tmpStacktrace.map((stackLine) => "\t$stackLine").join("\n");
messageBuilder.write("\n$stackTraceMessage");
tmpStacktrace.map((stackLine) => '\t$stackLine').join('\n');
messageBuilder.write('\n$stackTraceMessage');
}

_logService.save(LogEntry(messageBuilder.toString(), _getLogLevel(level), metadata));
}

LogLevel _getLogLevel(String level) {
switch (level) {
case "D":
case 'D':
return LogLevel.debug;
case "W":
case 'W':
return LogLevel.warning;
case "E":
case 'E':
return LogLevel.error;
case "V":
case 'V':
return LogLevel.trace;
case "I":
case 'I':
default:
return LogLevel.info;
}
Expand Down
2 changes: 1 addition & 1 deletion das_client/lib/logging/src/log_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:das_client/logging/src/log_level.dart';
class LogEntry {
LogEntry(this.message, this.level, this.metadata)
: time = DateTime.now().millisecondsSinceEpoch / 1000,
source = "das_client";
source = 'das_client';

final double time;
final String source;
Expand Down
16 changes: 8 additions & 8 deletions das_client/lib/logging/src/log_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:synchronized/synchronized.dart';
class LogService {
static const _rolloverTimeMinutes = 1;
static const _maxFileSize = 50 * 1024;
static const _prefix = "das-log";
static const _lastSavedFileName = "$_prefix-lastSavedFile.json";
static const _prefix = 'das-log';
static const _lastSavedFileName = '$_prefix-lastSavedFile.json';
final _lock = Lock();
final _senderLock = Lock();

Expand All @@ -31,7 +31,7 @@ class LogService {
}

Future<String> _getLogPath() async {
return "${(await getApplicationSupportDirectory()).path}/logs";
return '${(await getApplicationSupportDirectory()).path}/logs';
}

void save(LogEntry log) {
Expand All @@ -41,16 +41,16 @@ class LogService {
void _saveInternal(LogEntry log) async {
await _initialized;
_lock.synchronized(() {
var lastSavedFile = File("$_logPath/$_lastSavedFileName");
var lastSavedFile = File('$_logPath/$_lastSavedFileName');
if (!(lastSavedFile.existsSync())) {
lastSavedFile.createSync(recursive: true);
}
lastSavedFile.writeAsStringSync("${jsonEncode(log)},", mode: FileMode.append);
lastSavedFile.writeAsStringSync('${jsonEncode(log)},', mode: FileMode.append);

// Check rollover
if (lastSavedFile.lengthSync() > _maxFileSize || _nextRolloverTimeStamp.isBefore(DateTime.now())) {
Fimber.d("Rolling over log file");
lastSavedFile.renameSync("$_logPath/$_prefix-${DateTime.now().millisecondsSinceEpoch}.json");
Fimber.d('Rolling over log file');
lastSavedFile.renameSync('$_logPath/$_prefix-${DateTime.now().millisecondsSinceEpoch}.json');
_nextRolloverTimeStamp = DateTime.now().add(const Duration(minutes: _rolloverTimeMinutes));
_sendLogs();
}
Expand All @@ -64,7 +64,7 @@ class LogService {
Fimber.d('Found ${files.length} log files in log directory: $_logPath');

for (var file in files) {
if (file is File && file.path.endsWith(".json") && !file.path.contains(_lastSavedFileName)) {
if (file is File && file.path.endsWith('.json') && !file.path.contains(_lastSavedFileName)) {
Fimber.d('Sending ${file.path} to backend');

var content = file.readAsStringSync();
Expand Down
2 changes: 1 addition & 1 deletion das_client/lib/model/db/journey_profile_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:isar/isar.dart';

part 'journey_profile_entity.g.dart';

@Collection(accessor: "journeyProfile")
@Collection(accessor: 'journeyProfile')
class JourneyProfileEntity {
JourneyProfileEntity(
{required this.id,
Expand Down
2 changes: 1 addition & 1 deletion das_client/lib/model/db/segment_profile_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:isar/isar.dart';

part 'segment_profile_entity.g.dart';

@Collection(accessor: "segmentProfile")
@Collection(accessor: 'segmentProfile')
class SegmentProfileEntity {
SegmentProfileEntity(
{required this.id,
Expand Down
Loading

0 comments on commit 6b2d6db

Please sign in to comment.