Skip to content

Commit

Permalink
Merge branch 'main' into revert-to-core22
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez authored Oct 3, 2024
2 parents 096a4c3 + 1c1c1f3 commit 8b13356
Show file tree
Hide file tree
Showing 67 changed files with 4,618 additions and 791 deletions.
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.24.3"
}
32 changes: 20 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v3
- run: melos analyze

format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v3
- run: melos format

mocks:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v3
- run: melos generate
- name: Check for outdated mocks
Expand All @@ -48,7 +48,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v3
- run: melos gen-l10n
- name: Check for outdated l10n
Expand All @@ -68,7 +68,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v3
- run: sudo apt update && sudo apt install -y lcov
- run: melos coverage
Expand All @@ -80,22 +80,30 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: asdf-vm/actions/install@v3
- uses: Atsumi3/actions[email protected]
- uses: bluefireteam/melos-action@v3
- run: sudo apt update
- run: sudo apt install -y clang cmake curl dbus dbus-x11 fwupd fwupd-tests gsettings-desktop-schemas libgtk-3-dev ninja-build pkg-config unzip upower xvfb
env:
DEBIAN_FRONTEND: noninteractive

- name: Flutter version
run: flutter --version

- name: Prepare environment
run: |
sudo sed -i 's/DisabledPlugins=.*/DisabledPlugins=invalid;bios/g' /etc/fwupd/daemon.conf
echo "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$UID/bus" >> $GITHUB_ENV
echo "XDG_RUNTIME_DIR=/run/user/$UID" >> $GITHUB_ENV
echo "FLUTTER_ROOT=$(asdf where flutter)" >> $GITHUB_ENV
gsettings set org.gnome.desktop.interface gtk-theme 'Yaru'
- run: sudo fwupdmgr enable-remote fwupd-tests
- run: sudo fwupdmgr get-devices
- run: |
- name: Setup fwupd tests
run: |
sudo fwupdmgr enable-remote fwupd-tests
sudo fwupdmgr get-devices
- name: Run integration tests
run: |
cd packages/firmware_updater && \
sudo -E xvfb-run -a -s '-screen 0 1024x768x24 +extension GLX' \
$FLUTTER_ROOT/bin/flutter test integration_test
sudo -E env PATH=$PATH xvfb-run -a -s '-screen 0 1024x768x24 +extension GLX' \
flutter test integration_test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

# FVM Version Cache
.fvm/
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

51 changes: 30 additions & 21 deletions melos.yaml
Original file line number Diff line number Diff line change
@@ -1,64 +1,73 @@
name: firmware_updater_workspace
sdkPath: .fvm/flutter_sdk

packages:
- packages/**
- packages/*

command:
bootstrap:
environment:
sdk: ">=3.0.0 <4.0.0"
flutter: '>=3.13.7'
sdk: '>=3.1.0 <4.0.0'
flutter: '>=3.24.3'

dev_dependencies:
ubuntu_lints: ^0.3.0
ubuntu_lints: ^0.4.0

scripts:
# analyze all packages
analyze: >
melos exec -c 1 -- \
flutter analyze --fatal-infos .
# build all packages
build: >
melos exec -c 1 --fail-fast --flutter --dir-exists=linux -- \
flutter build linux
fvm flutter build linux
# collect coverage information for all packages
coverage: >
melos exec -c 1 --fail-fast --dir-exists=test --ignore='*builder*' -- \
flutter test --coverage && melos run coverage:cleanup
melos exec -c 1 --fail-fast --dir-exists=test -- \
fvm flutter test --coverage && melos run coverage:cleanup
# cleanup generated files from coverage
coverage:cleanup: >
melos exec --file-exists=coverage/lcov.info -- \
lcov --remove coverage/lcov.info '**/*.g.dart' -o coverage/lcov.info
lcov --remove coverage/lcov.info \
'**/*.freezed.dart' \
'**/*.g.dart' \
'**/*.mocks.dart' \
'**/l10n/*.dart' \
'**/*.pb*.dart' \
-o coverage/lcov.info

# format all packages
format: >
format:exclude: >
find . -name '*.dart' \
! -name '*.freezed.dart' \
! -name '*.g.dart' \
! -name '*.mocks.dart' \
! -path '*/l10n/*.dart' \
! -name '*.pb*.dart' \
! -path '*/.*/*' \
| xargs dart format
| xargs fvm dart format --set-exit-if-changed

# run build_runner to generate code in all packages
generate: >
melos exec -c 1 --fail-fast --depends-on=build_runner -- \
dart run build_runner build --delete-conflicting-outputs
fvm dart run build_runner build --delete-conflicting-outputs
# run gen-l10n to generate localizations in all packages
gen-l10n: >
melos exec -c 1 --fail-fast --dir-exists=lib/l10n -- \
flutter gen-l10n
melos exec -c 1 --fail-fast --depends-on=flutter_localizations -- \
fvm flutter gen-l10n
# run integration tests in all packages
integration_test: >
melos exec -c 1 --fail-fast --dir-exists=integration_test -- \
flutter test integration_test
fvm flutter test integration_test
# runs "flutter pub <arg(s)>" in all packages
pub: melos exec -c 1 -- flutter pub "$@"
pub: melos exec -c 1 -- fvm flutter pub "$@"

# run tests in all packages
test: >
melos exec -c 1 --fail-fast --dir-exists=test -- \
flutter test
fvm flutter test
# run pub upgrade in all packages
upgrade: melos pub upgrade
1 change: 1 addition & 0 deletions packages/firmware_notifier/.fvmrc
37 changes: 24 additions & 13 deletions packages/firmware_notifier/lib/firmware_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:fwupd/fwupd.dart';
import 'package:meta/meta.dart';

Future<Map<FwupdDevice, FwupdRelease>> getUpdates(
[@visibleForTesting FwupdClient? client]) async {
Future<Map<FwupdDevice, FwupdRelease>> getUpdates([
@visibleForTesting FwupdClient? client,
]) async {
final fwupdClient = client ?? FwupdClient();
await fwupdClient.connect();

Expand All @@ -15,27 +16,37 @@ Future<Map<FwupdDevice, FwupdRelease>> getUpdates(
final updates = {
for (final device in devices)
device: (await fwupdClient.getReleases(device.deviceId).catchError(
(_) => <FwupdRelease>[],
test: (e) =>
e is FwupdNothingToDoException ||
e is FwupdNotSupportedException))
(_) => <FwupdRelease>[],
test: (e) =>
e is FwupdNothingToDoException ||
e is FwupdNotSupportedException,
))
.firstWhereOrNull(
(r) => r.flags.contains(FwupdReleaseFlag.isUpgrade),
)
),
}..removeWhere((_, update) => update == null);
await fwupdClient.close();
return Map<FwupdDevice, FwupdRelease>.from(updates);
}

Future<List<Notification>> sendUpdateNotifications(
NotificationsClient client, Map<FwupdDevice, FwupdRelease> updates) async {
return Future.wait(updates.entries.map(
(e) => client.notify('Firmware update available for ${e.key.name}',
NotificationsClient client,
Map<FwupdDevice, FwupdRelease> updates,
) async {
return Future.wait(
updates.entries.map(
(e) => client.notify(
'Firmware update available for ${e.key.name}',
body:
'${e.key.name} can be upgraded from version ${e.key.version} to ${e.value.version}.',
appIcon: 'software-update-available',
actions: [
NotificationAction('${e.key.deviceId}, ${e.value.version}', 'Install')
]),
));
NotificationAction(
'${e.key.deviceId}, ${e.value.version}',
'Install',
),
],
),
),
);
}
6 changes: 3 additions & 3 deletions packages/firmware_notifier/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: firmware_notifier
description: A desktop notification service for fwupd.
publish_to: 'none'
environment:
sdk: '>=3.0.0 <4.0.0'
sdk: ">=3.1.0 <4.0.0"

dependencies:
collection: ^1.17.0
Expand All @@ -13,7 +13,7 @@ dependencies:

dev_dependencies:
build_runner: ^2.3.2
mockito: 5.4.2
mockito: ^5.4.2
test: ^1.16.0
ubuntu_lints: ^0.3.0
ubuntu_lints: ^0.4.0

40 changes: 26 additions & 14 deletions packages/firmware_notifier/test/firmware_notifier_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
),
FwupdRelease(
name: 'oldRelease',
)
),
],
};

Expand All @@ -33,29 +33,41 @@ void main() {
expect(updates.length, 1);
expect(updates.entries.first.key, devices.first);
expect(
updates.entries.first.value, releases[devices.first.deviceId]!.first);
updates.entries.first.value,
releases[devices.first.deviceId]!.first,
);
});

test('show notifications', () {
final client = MockNotificationsClient();
when(client.notify(any,
actions: anyNamed('actions'),
appIcon: 'software-update-available',
body: anyNamed('body')))
.thenAnswer((_) async => Notification(NotificationsClient(), 0));
when(
client.notify(
any,
actions: anyNamed('actions'),
appIcon: 'software-update-available',
body: anyNamed('body'),
),
).thenAnswer((_) async => Notification(NotificationsClient(), 0));
final updates = {
FwupdDevice(deviceId: '0', name: 'a', plugin: ''): FwupdRelease(
name: 'newRelease_a', flags: const {FwupdReleaseFlag.isUpgrade}),
name: 'newRelease_a',
flags: const {FwupdReleaseFlag.isUpgrade},
),
FwupdDevice(deviceId: '1', name: 'b', plugin: ''): FwupdRelease(
name: 'newRelease_b', flags: const {FwupdReleaseFlag.isUpgrade}),
name: 'newRelease_b',
flags: const {FwupdReleaseFlag.isUpgrade},
),
};

sendUpdateNotifications(client, updates);
verify(client.notify(any,
actions: anyNamed('actions'),
appIcon: 'software-update-available',
body: anyNamed('body')))
.called(2);
verify(
client.notify(
any,
actions: anyNamed('actions'),
appIcon: 'software-update-available',
body: anyNamed('body'),
),
).called(2);
});

test('no detected devices', () async {
Expand Down
Loading

0 comments on commit 8b13356

Please sign in to comment.