Skip to content

Commit

Permalink
add env generate (#1674)
Browse files Browse the repository at this point in the history
  • Loading branch information
boyan01 authored Dec 17, 2024
1 parent 2615319 commit 66d4494
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ jobs:
- name: Install dependencies
run: flutter pub get

- name: Generator ENV
run: |
tee .env &>/dev/null << EOF
SENTRY_DSN=${{ secrets.SENTRY_DSN }}
EOF
- name: Run Build Runner
run: dart run build_runner build --delete-conflicting-outputs

- name: Verify formatting
run: dart format --set-exit-if-changed .

Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/manual-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ jobs:

- run: flutter config --enable-linux-desktop

- name: Generator ENV
run: |
tee .env &>/dev/null << EOF
SENTRY_DSN=${{ secrets.SENTRY_DSN }}
EOF
- name: Run Build Runner
run: dart run build_runner build --delete-conflicting-outputs

# setup webcrypto for unit test
- run: dart run webcrypto:setup

Expand Down Expand Up @@ -231,6 +240,13 @@ jobs:

- run: flutter --version

- name: Generator ENV
run: |
echo SENTRY_DSN=${{ secrets.SENTRY_DSN }} >> .env
- name: Run Build Runner
run: dart run build_runner build --delete-conflicting-outputs

# https://stackoverflow.com/questions/22575662/filename-too-long-in-git-for-windows/22575737#22575737
- run: git config --system core.longpaths true

Expand All @@ -246,10 +262,8 @@ jobs:
$version_str=$(gc .\pubspec.yaml | select-string '(?<=^version: ).*' -AllMatches | Select-Object -Expand Matches | %{$_.Value})
$version=$version_str.Split("+")[0]
$build_number=$version_str.Split("+")[1]
flutter build windows --dart-define="APP_VERSION=$version" --dart-define="APP_BUILD_NUMBER=$build_number" --dart-define SENTRY_DSN=$env:SENTRY_DSN
flutter build windows --dart-define="APP_VERSION=$version" --dart-define="APP_BUILD_NUMBER=$build_number"
echo "MSIX_PACKAGE_VERSION=$version.0" >> $Env:GITHUB_OUTPUT
env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Build Installer
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ dist/flatpak/build-dir*
dist/flatpak/.flatpak-builder
dist/flatpak/mixin-desktop-linux-portable.tar.gz
/lib/constants/resources.preview.dart

*.env
env.g.dart
11 changes: 11 additions & 0 deletions lib/constants/env.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:envied/envied.dart';

part 'env.g.dart';

@Envied(path: '.env', allowOptionalFields: true)
abstract class Env {
@EnviedField(varName: 'SENTRY_DSN')
static const String? _sentryDsn = _Env._sentryDsn;

static const String sentryDsn = _sentryDsn ?? '';
}
6 changes: 4 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:window_size/window_size.dart';

import 'app.dart';
import 'bloc/custom_bloc_observer.dart';
import 'constants/env.dart';
import 'ui/home/home.dart';
import 'ui/setting/log_page.dart';
import 'utils/app_lifecycle.dart';
Expand All @@ -34,11 +35,12 @@ import 'utils/web_view/web_view_desktop.dart';
import 'widgets/protocol_handler.dart';

Future<void> main(List<String> args) async {
if (const String.fromEnvironment('SENTRY_DSN').isEmpty) {
if (Env.sentryDsn.isEmpty) {
await _runApp(args);
} else {
await SentryFlutter.init((options) {
options
..dsn = Env.sentryDsn
..tracesSampleRate = 1.0
..profilesSampleRate = 1.0;
}, appRunner: () => _runApp(args));
Expand Down Expand Up @@ -97,7 +99,7 @@ Future<void> _runApp(List<String> args) async {
return true;
};

if (const String.fromEnvironment('SENTRY_DSN').isNotEmpty) {
if (Env.sentryDsn.isNotEmpty) {
i('app running with sentry');
} else {
e('app running without sentry');
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
envied:
dependency: "direct dev"
description:
name: envied
sha256: bbff9c76120e4dc5e2e36a46690cf0a26feb65e7765633f4e8d916bcd173a450
url: "https://pub.dev"
source: hosted
version: "0.5.4+1"
envied_generator:
dependency: "direct overridden"
description:
name: envied_generator
sha256: "517b70de08d13dcd40e97b4e5347e216a0b1c75c99e704f3c85c0474a392d14a"
url: "https://pub.dev"
source: hosted
version: "0.5.4+1"
equatable:
dependency: "direct main"
description:
Expand Down
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ dependencies:
url: https://github.com/MixinNetwork/flutter-plugins.git
ref: 08c1ce40eb6abfad6049fb6aad8bd30312ec5319
path: packages/data_detector
envied: ^0.5.2

dev_dependencies:
build_runner: ^2.4.8
Expand All @@ -186,13 +187,11 @@ dev_dependencies:
flutter_lints: ^5.0.0
very_good_analysis: ^6.0.0
sentry_flutter: ^8.10.1
envied_generator: ^0.5.2

dependency_overrides:
very_good_analysis: ^6.0.0
collection: ^1.18.0
# pixel_snap 0.1.3 not compat with latest flutter master channel.
# pixel_snap: 0.1.2
# intl: ^0.19.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down

0 comments on commit 66d4494

Please sign in to comment.