Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 182 additions & 8 deletions .github/workflows/celest_auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ concurrency:
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || ''}}
cancel-in-progress: true

env:
CELEST: ${{ github.workspace }}/apps/cli/bin/celest.dart
defaults:
run:
shell: bash

jobs:
build:
test:
runs-on: macos-latest-xlarge
timeout-minutes: 15
steps:
Expand All @@ -39,12 +45,180 @@ jobs:
# - name: Test
# working-directory: packages/celest_auth
# run: dart test
- name: Test (Example)
working-directory: packages/celest_auth/example/celest
run: dart test
- name: Build Example (iOS)
test_darwin:
needs: [test]
runs-on: macos-latest-xlarge
timeout-minutes: 20
steps:
- name: Git Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: Setup Flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
with:
cache: true
- name: Get Packages
working-directory: apps/cli
run: dart pub get
- name: Get Packages (Example)
working-directory: packages/celest_auth/example
run: flutter pub get
- name: Setup iOS Simulator
run: |
RUNTIME=$(xcrun simctl list runtimes | grep 'iOS 18' | tail -n 1 | cut -d' ' -f 7)
echo "Using runtime: $RUNTIME"
xcrun simctl create ios 'iPhone 16 Pro Max' $RUNTIME
echo "Booting simulator"
xcrun simctl boot ios
echo "Booted simulator"
- name: Integration Test (iOS)
working-directory: packages/celest_auth/example
run: dart run $CELEST start --verbose -- flutter test -d ios integration_test
- name: Integration Test (macOS)
working-directory: packages/celest_auth/example
run: flutter build ios --no-codesign
- name: Build Example (Web)
run: dart run $CELEST start --verbose -- flutter test -d macos integration_test
# TODO: Keeps timing out on Linux. Fails hard on macOS...
# test_android:
# needs: [test]
# runs-on: macos-latest-xlarge
# timeout-minutes: 30
# steps:
# - name: Git Checkout
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
# - name: Setup Flutter
# uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
# with:
# cache: true
# - name: Get Packages
# working-directory: apps/cli
# run: dart pub get
# - name: Get Packages (Example)
# working-directory: packages/celest_auth/example
# run: flutter pub get
# - name: Start Celest
# working-directory: packages/celest_auth/example
# run: dart run $CELEST start --verbose &
# - name: Build APK
# working-directory: packages/celest_auth/example
# run: flutter build apk --debug
# # - name: Enable KVM
# # run: |
# # echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
# # sudo udevadm control --reload-rules
# # sudo udevadm trigger --name-match=kvm
# - name: Test (API 31)
# uses: ReactiveCircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d # 2.33.0
# with:
# # Matches `package:jni` compileSdkVersion
# # https://github.com/dart-lang/native/blob/001910c9f40d637cb25c19bb500fb89cebdf7450/pkgs/jni/android/build.gradle#L57C23-L57C25
# api-level: 31
# arch: arm64-v8a
# working-directory: packages/celest_auth/example
# script: flutter test -d emulator integration_test
# - name: Test (API 21)
# uses: ReactiveCircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d # 2.33.0
# with:
# # Minimum supported API level
# # Should match build.gradle: https://github.com/celest-dev/celest/blob/main/packages/native/storage/android/build.gradle#L49
# api-level: 21
# arch: arm64-v8a
# working-directory: packages/celest_auth/example
# script: flutter test -d emulator integration_test
test_linux:
needs: [test]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Git Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: Setup Flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
with:
cache: true
- name: Install Build Dependencies
run: |
sudo apt-get update && \
sudo apt-get install -y clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev
- name: Setup Test Environment
run: tool/setup-ci.sh
- name: Get Packages
working-directory: apps/cli
run: dart pub get
- name: Get Packages (Example)
working-directory: packages/celest_auth/example
run: flutter build web
run: flutter pub get
- name: Integration Test (Linux)
working-directory: packages/celest_auth/example
run: |
# Headless tests require virtual display for the linux tests to run.
export DISPLAY=:99
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
dart run $CELEST start --verbose -- flutter test -d linux integration_test
test_windows:
needs: [test]
runs-on: windows-latest
timeout-minutes: 15
steps:
- name: Git Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: Setup Flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
with:
cache: true
- name: Get Packages
working-directory: apps/cli
run: dart pub get
- name: Get Packages (Example)
working-directory: packages/celest_auth/example
run: flutter pub get
- name: Test (Windows)
working-directory: packages/celest_auth/example
run: dart run "$CELEST" start --verbose -- flutter test -d windows integration_test
test_web:
needs: [test]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Git Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
- name: Setup Flutter
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
with:
cache: true
- name: Setup Chromedriver
uses: nanasess/setup-chromedriver@v2
- name: Get Packages
working-directory: apps/cli
run: dart pub get
- name: Get Packages (Example)
working-directory: packages/celest_auth/example
run: flutter pub get
- name: Start Chromedriver
run: |
# Headless tests require virtual display for the chromedriver tests to run.
export DISPLAY=:99
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &

chromedriver --port=4444 &
- name: Test (Web/JS)
working-directory: packages/celest_auth/example
run: |
dart run "$CELEST" start --verbose -- \
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/integration_test.dart \
-d web-server \
--debug \
--browser-name=chrome \
--no-headless
- name: Test (Web/WASM)
working-directory: packages/celest_auth/example
run: |
dart run "$CELEST" start --verbose -- \
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/integration_test.dart \
-d web-server \
--debug \
--browser-name=chrome \
--no-headless \
--wasm
2 changes: 2 additions & 0 deletions packages/celest_auth/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
Expand Down
1 change: 1 addition & 0 deletions packages/celest_auth/example/android/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/celest_auth/example/android/settings.gradle

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ enum CelestEnvironment {

Uri get baseUri => switch (this) {
local => _$celest.kIsWeb || !Platform.isAndroid
? Uri.parse('http://localhost:51375')
: Uri.parse('http://10.0.2.2:51375'),
? Uri.parse('http://localhost:61552')
: Uri.parse('http://10.0.2.2:61552'),
};
}

Expand All @@ -48,7 +48,7 @@ class Celest with _$celest.CelestBase {

final _functions = CelestFunctions();

late final CelestAuth _auth = CelestAuth(
late CelestAuth _auth = CelestAuth(
this,
storage: nativeStorage,
);
Expand All @@ -75,15 +75,22 @@ class Celest with _$celest.CelestBase {
CelestEnvironment environment = CelestEnvironment.local,
_$celest.Serializers? serializers,
}) {
if (_initialized && environment != _currentEnvironment) {
_auth.signOut();
if (_initialized) {
_reset();
}
_currentEnvironment = environment;
_baseUri = environment.baseUri;
scheduleMicrotask(_auth.init);
if (!_initialized) {
initSerializers(serializers: serializers);
}
scheduleMicrotask(() => _auth.init());
initSerializers(serializers: serializers);
_initialized = true;
}

void _reset() {
_auth.close().ignore();
_auth = CelestAuth(
this,
storage: nativeStorage,
);
_initialized = false;
}
}
5 changes: 3 additions & 2 deletions packages/celest_auth/example/celest/client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ description: The Celest client for celest_auth_example.
publish_to: none

environment:
sdk: ^3.4.0
sdk: ^3.5.0

dependencies:
celest: ^1.0.0
celest_backend:
path: ../
celest_core: ^1.0.0
http: ^1.0.0
meta: ^1.12.0
native_storage: ^0.2.2

dev_dependencies:
lints: ^4.0.0
lints: ^5.0.0
test: ^1.25.0
dependency_overrides:
celest:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
// it can be checked into version control.
// ignore_for_file: type=lint, unused_local_variable, unnecessary_cast, unnecessary_import, deprecated_member_use, invalid_use_of_internal_member

library;
library; // ignore_for_file: no_leading_underscores_for_library_prefixes

import 'package:celest/celest.dart';
import 'package:celest/src/core/context.dart';
import 'package:celest_cloud_auth/celest_cloud_auth.dart';
import 'package:drift/native.dart';
import 'package:drift/src/runtime/api/runtime_api.dart';
import 'package:drift/src/runtime/executor/executor.dart';
import 'package:drift_hrana/drift_hrana.dart';
import 'package:celest/celest.dart' as _$celest;
import 'package:celest/src/core/context.dart' as _$celest;
import 'package:celest/src/runtime/data/connect.dart' as _$celest;
import 'package:celest_cloud_auth/celest_cloud_auth.dart' as _$celest;

/// The auth service for the Celest backend.
///
Expand All @@ -20,59 +17,22 @@ class CelestAuth {
const CelestAuth();

/// Initializes the Celest Auth service in the given [context].
static Future<void> init(Context context) async {
final database = await _connect(
static Future<void> init(_$celest.Context context) async {
final database = await _$celest.connect(
context,
name: 'CelestAuthDatabase',
factory: AuthDatabase.new,
hostnameVariable: const env('CELEST_AUTH_DATABASE_HOST'),
tokenSecret: const secret('CELEST_AUTH_DATABASE_TOKEN'),
factory: _$celest.AuthDatabase.new,
hostnameVariable: const _$celest.env('CELEST_AUTH_DATABASE_HOST'),
tokenSecret: const _$celest.secret('CELEST_AUTH_DATABASE_TOKEN'),
);
final service = await CelestCloudAuth.create(database: database);
final service = await _$celest.CelestCloudAuth.create(database: database);
context.router.mount(
'/v1alpha1/auth/',
service.handler,
);
context.put(
CelestCloudAuth.contextKey,
_$celest.CelestCloudAuth.contextKey,
service,
);
}
}

/// Checks the connection to the database by running a simple query.
Future<Database> _checkConnection<Database extends GeneratedDatabase>(
Database db) async {
await db.transaction(() async {
await db.customSelect('SELECT 1').get();
});
return db;
}

/// Constructs a new [Database] and connects to it using the provided
/// [hostnameVariable] and [tokenSecret] configuration values.
Future<Database> _connect<Database extends GeneratedDatabase>(
Context context, {
required String name,
required Database Function(QueryExecutor) factory,
required env hostnameVariable,
required secret tokenSecret,
}) async {
if (context.environment == Environment.local) {
return _checkConnection(factory(NativeDatabase.memory()));
}
final host = context.get(hostnameVariable);
final token = context.get(tokenSecret);
if (host == null || token == null) {
throw StateError(
'Missing database hostname or token for $name. '
'Please set the `$hostnameVariable` and `$tokenSecret` values '
'in the environment or Celest configuration file.',
);
}
final connector = HranaDatabase(
Uri(scheme: 'libsql', host: host),
jwtToken: token,
);
return _checkConnection(factory(connector));
}
Loading
Loading