Skip to content

Commit

Permalink
Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Barabas5532 committed Aug 4, 2024
1 parent 2544d90 commit 54002d7
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 68 deletions.
39 changes: 23 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ env:
CCACHE_DIR: /ccache
FLUTTER_VERSION: '3.16.9'
FLUTTER_CHANNEL: 'stable'
MELOS_VERSION: '^6.1.0'
COVERDE_VERSION: '^0.2.0+2'
COVERAGE_VERSION: '^0.2.0+2'

jobs:
build-firmware:
Expand Down Expand Up @@ -192,7 +195,7 @@ jobs:
defaults:
run:
working-directory:
frontend
dart
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -205,10 +208,11 @@ jobs:
channel: ${{ env.FLUTTER_CHANNEL }}
cache: true

- run: flutter pub get
- run: dart pub global activate melos ${{ env.MELOS_VERSION }}
- run: dart run melos bootstrap

- name: Generate code
run: flutter pub run build_runner build
run: dart run melos run generate_code

- name: Analyze
run: flutter analyze
Expand All @@ -218,7 +222,7 @@ jobs:
defaults:
run:
working-directory:
frontend
dart
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -231,17 +235,18 @@ jobs:
channel: ${{ env.FLUTTER_CHANNEL }}
cache: true

- run: flutter pub get
- run: dart pub global activate melos ${{ env.MELOS_VERSION }}
- run: dart run melos bootstrap

- name: Format
run: dart format -o none --set-exit-if-changed lib test
run: dart format -o none --set-exit-if-changed .

flutter-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory:
frontend
dart
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -254,25 +259,27 @@ jobs:
channel: ${{ env.FLUTTER_CHANNEL }}
cache: true

- run: flutter pub get
- run: dart pub global activate melos ${{ env.MELOS_VERSION }}
- run: dart pub global activate coverde ${{ env.COVERDE_VERSION }}
- run: dart pub global activate coverage ${{ env.COVERAGE_VERSION }}
- run: melos bootstrap

- name: Generate code
run: flutter pub run build_runner build
run: melos run generate_code

- name: Test
run: flutter test --coverage --exclude-tags=api
run: |
dart run melos run test
dart run melos run test-dart
- name: Coverage clean-up
run: >
flutter pub run
remove_from_coverage --remove="\.g\.dart$"
--file=coverage/lcov.info
run: dart run melos run coverage

- name: Coveralls
uses: coverallsapp/github-action@master
with:
path-to-lcov: frontend/coverage/lcov.info
base-path: frontend
path-to-lcov: coverage/filtered.lcov.info
base-path: dart
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel: true
flag-name: "flutter"
Expand Down
2 changes: 2 additions & 0 deletions dart/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

# https://melos.invertase.dev/getting-started#configure-the-workspace
pubspec_overrides.yaml

coverage
3 changes: 2 additions & 1 deletion dart/frontend/lib/api/api_websocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import 'package:logging/logging.dart';
import 'package:rxdart/rxdart.dart';

import 'package:shrapnel_common/api_data/api_message.dart';
import 'package:shrapnel_common/api_data/generated/shrapnel.pb.dart' as shrapnel_pb;
import 'package:shrapnel_common/api_data/generated/shrapnel.pb.dart'
as shrapnel_pb;
import 'package:shrapnel_common/api_data/proto_extension.dart';
import '../core/message_transport.dart';
import '../core/stream_extensions.dart';
Expand Down
8 changes: 0 additions & 8 deletions dart/frontend/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -563,14 +563,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.3"
remove_from_coverage:
dependency: "direct main"
description:
name: remove_from_coverage
sha256: "5b5745f6b692c80e3d7903fb83f9e789dc4575e6db5443a1b391ca25c10bad06"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
rxdart:
dependency: "direct main"
description:
Expand Down
1 change: 0 additions & 1 deletion dart/frontend/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies:
pausable_timer: ^3.1.0+3
protobuf: ^3.1.0
provider: ^6.0.0
remove_from_coverage: ^2.0.0
rxdart: ^0.27.7
shrapnel_common:
path: ../shrapnel_common
Expand Down
16 changes: 16 additions & 0 deletions dart/melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@ packages:
- shrapnel_common
- shrapnel_test_lib
- shrapnel_test_tool

scripts:
generate_code:
run: melos exec --depends-on=build_runner -- "dart run build_runner build -d"

test:
run: melos exec -c 1 --depends-on=flutter_test -- "flutter test --coverage --exclude-tags=api"

test-dart:
run: melos exec -c 1 --depends-on=test -- "dart run coverage:test_with_coverage"

coverage:
description: Merge all packages coverage trace files ignoring data related to generated files.
run: >
coverde rm MELOS_ROOT_PATH/coverage/filtered.lcov.info &&
melos exec --file-exists=coverage/lcov.info -- "coverde filter --input ./coverage/lcov.info --output MELOS_ROOT_PATH/coverage/filtered.lcov.info --paths-parent MELOS_PACKAGE_PATH --filters '\.g\.dart'"
1 change: 0 additions & 1 deletion dart/shrapnel_common/lib/api_data/presets_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ class PresetData with _$PresetData {
required String name,
required PresetParametersData parameters,
}) = _PresetData;

}
4 changes: 2 additions & 2 deletions dart/shrapnel_common/lib/api_data/selected_preset_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ sealed class SelectedPresetMessage with _$SelectedPresetMessage {
factory SelectedPresetMessage.read() = ReadSelectedPresetMessage;

factory SelectedPresetMessage.notify({required int selectedPreset}) =
NotifySelectedPresetMessage;
NotifySelectedPresetMessage;

factory SelectedPresetMessage.write({required int selectedPreset}) =
WriteSelectedPresetMessage;
WriteSelectedPresetMessage;
}
2 changes: 1 addition & 1 deletion dart/shrapnel_test_lib/lib/shrapnel_test_lib.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Testing utilities.
library;

export 'src/shrapnel_test_lib_base.dart';
export 'src/shrapnel_test_lib_base.dart';
72 changes: 36 additions & 36 deletions dart/shrapnel_test_lib/lib/src/shrapnel_test_lib_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Future<void> setUpWiFi({required String ssid, required String password}) async {
});

var success =
await provisioning.sendWifiConfig(ssid: ssid, password: password);
await provisioning.sendWifiConfig(ssid: ssid, password: password);
if (!success) {
throw StateError('send wifi config failed');
}
Expand Down Expand Up @@ -101,7 +101,7 @@ Future<void> _eraseFlash({required String port}) async {

List<int> _getMacAddressFromEsptoolStdout(String espToolStdout) {
final macRegex =
RegExp(r'^MAC: (([0-9a-f]{2}:){5}([0-9a-f]{2}))$', multiLine: true);
RegExp(r'^MAC: (([0-9a-f]{2}:){5}([0-9a-f]{2}))$', multiLine: true);
final macString = macRegex.allMatches(espToolStdout).single.group(1)!;
return macString.split(':').map((e) => int.parse(e, radix: 16)).toList();
}
Expand Down Expand Up @@ -172,10 +172,10 @@ Future<(bool, MacAddress)> _checkIfAlreadyFlashed({
// https://docs.espressif.com/projects/esptool/en/latest/esp32/#quick-start
const command = 'esptool.py';
final args = '-p $port '
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'verify_flash 0x10000 $expectedHeaderFilePath'
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'verify_flash 0x10000 $expectedHeaderFilePath'
.split(' ');

final result = await Process.run(command, args);
Expand All @@ -188,14 +188,14 @@ Future<(bool, MacAddress)> _checkIfAlreadyFlashed({
_log.info(result.stdout);

return (
switch (result.exitCode) {
0 => true,
2 => false,
_ => throw StateError(
'esptool.py exited with unexpected code ${result.exitCode}',
),
},
_getMacAddressFromEsptoolStdout(result.stdout as String)
switch (result.exitCode) {
0 => true,
2 => false,
_ => throw StateError(
'esptool.py exited with unexpected code ${result.exitCode}',
),
},
_getMacAddressFromEsptoolStdout(result.stdout as String)
);
}

Expand All @@ -206,13 +206,13 @@ Future<void> _flashFirmware(String path, {required String port}) async {
// https://docs.espressif.com/projects/esptool/en/latest/esp32/#quick-start
const command = 'esptool.py';
final args = '-p $port '
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m '
'0x1000 $path/bootloader.bin '
'0x8000 $path/partition-table.bin '
'0x10000 $path/esp32-dsp.bin'
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m '
'0x1000 $path/bootloader.bin '
'0x8000 $path/partition-table.bin '
'0x10000 $path/esp32-dsp.bin'
.split(' ');

final result = await Process.run(command, args);
Expand All @@ -230,10 +230,10 @@ Future<void> nvsErase({required String port}) async {
// https://docs.espressif.com/projects/esptool/en/latest/esp32/#quick-start
const command = 'esptool.py';
final args = '-p $port '
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'erase_region 0x9000 0x6000'
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'erase_region 0x9000 0x6000'
.split(' ');

final result = await Process.run(command, args);
Expand All @@ -251,11 +251,11 @@ Future<void> nvsLoad(String binaryPath, {required String port}) async {
// https://docs.espressif.com/projects/esptool/en/latest/esp32/#quick-start
const command = 'esptool.py';
final args = '-p $port '
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m '
'0x9000 $binaryPath'
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'write_flash --flash_mode dio --flash_size 4MB --flash_freq 80m '
'0x9000 $binaryPath'
.split(' ');

final result = await Process.run(command, args);
Expand All @@ -273,11 +273,11 @@ Future<void> nvsSave(String binaryPath, {required String port}) async {
// https://docs.espressif.com/projects/esptool/en/latest/esp32/#quick-start
const command = 'esptool.py';
final args = '-p $port '
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'read_flash '
'0x9000 0x6000 $binaryPath'
'-b 2000000 '
'--before default_reset --after hard_reset '
'--chip esp32 '
'read_flash '
'0x9000 0x6000 $binaryPath'
.split(' ');

final result = await Process.run(command, args);
Expand Down Expand Up @@ -369,7 +369,7 @@ class ShrapnelUart {
String escapeCommandArg(String arg) {
return arg.replaceAllMapped(
RegExp(r'[\\" ]'),
(match) => '\\${match.group(0)!}',
(match) => '\\${match.group(0)!}',
);
}

Expand Down
2 changes: 1 addition & 1 deletion dart/shrapnel_test_lib/test/shrapnel_test_lib_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() {
};

final result =
testCases.map((key, value) => MapEntry(key, escapeCommandArg(key)));
testCases.map((key, value) => MapEntry(key, escapeCommandArg(key)));

expect(result, testCases);
});
Expand Down
3 changes: 2 additions & 1 deletion dart/shrapnel_test_tool/bin/shrapnel_test_tool.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:shrapnel_test_tool/shrapnel_test_tool.dart' as shrapnel_test_tool;
import 'package:shrapnel_test_tool/shrapnel_test_tool.dart'
as shrapnel_test_tool;

void main(List<String> arguments) {
shrapnel_test_tool.main(arguments);
Expand Down

0 comments on commit 54002d7

Please sign in to comment.