Skip to content

Commit

Permalink
Refactor: ci and code quality (#222)
Browse files Browse the repository at this point in the history
* chore(release): publish packages

 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]

* refactor(ci): Reintroduce publishing pipeline and some code changes

* postgres setup

* No longer supporting nullable map elements
  • Loading branch information
j4qfrost authored May 3, 2024
1 parent 5423ae9 commit d6e6063
Show file tree
Hide file tree
Showing 36 changed files with 114 additions and 96 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ jobs:
strategy:
fail-fast: false
matrix:
runner_args: [melos test-unit, dart tool/generated_test_runner.dart]
runner_args: [melos test-unit --no-select, dart tool/generated_test_runner.dart]
sdk: [stable, main]
env:
TEST_DIR: packages/core
services:
postgres:
image: postgres:14.5
image: postgres:16.2
env:
POSTGRES_USER: conduit_test_user
POSTGRES_PASSWORD: conduit!
Expand Down
22 changes: 8 additions & 14 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
strategy:
fail-fast: false
matrix:
runner_args: [melos test-unit, dart tool/generated_test_runner.dart]
runner_args: [melos test-unit --no-select, dart tool/generated_test_runner.dart]
sdk: [stable, main]
env:
TEST_DIR: packages/core
Expand All @@ -56,19 +56,13 @@ jobs:
TEST_VALUE: 1
TEST_BOOL: true
steps:
- name: Start PostgreSQL
run: |
mkdir -p $HOME/datadir
initdb -U postgres -D $HOME/datadir
pg_ctl -o "-p ${{ env.POSTGRES_PORT }}" -D $HOME/datadir start
- name: Create database
env:
PGUSER: postgres
PGPORT: 15432
run: |
createuser -s -e -g postgres ${{ env.POSTGRES_USER }}
psql --command="ALTER USER ${{ env.POSTGRES_USER }} WITH PASSWORD '${{ env.POSTGRES_PASSWORD }}'"
createdb --owner=${{ env.POSTGRES_USER }} ${{ env.POSTGRES_DB }}
- name: Setup PostgreSQL for Linux/macOS/Windows
uses: ikalnytskyi/action-setup-postgres@v6
with:
username: conduit_test_user
password: conduit!
database: conduit_test_db
port: 15432
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ jobs:
run: melos cache-source
- name: Publish package
run: melos publish --no-dry-run --git-tag-version --yes
- name: Push tags
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.CONDUIT_PAT }}
tags: true
branch: master
- name: Compute the release tag
run: |
echo "release_tag=v`cat packages/cli/pubspec.yaml | sed -nre 's/^version: [^0-9]*(([0-9]+\.)*[0-9]+).*/\1/p'`" >> $GITHUB_ENV
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.release_tag }}
body_path: CHANGES.txt
docker:
if: |
startsWith(github.event.head_commit.message, 'feat')
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
runner_args: [melos test-unit, dart tool/generated_test_runner.dart]
runner_args: [melos test-unit --no-select, dart tool/generated_test_runner.dart]
env:
TEST_DIR: packages/core
POSTGRES_HOST: localhost
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/src/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ abstract class CLICommand {
throw CLIException('Invalid integer value "$val" for argument "$key".');
}
return RuntimeContext.current.coerce<T>(val);
} on TypeCoercionException catch (_) {
} on TypeCoercionException {
throw CLIException(
'The value "$val" for argument "$key" could not be coerced to a $T.',
);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/src/mixins/openapi_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mixin CLIDocumentOptions implements CLICommand {
try {
final uri = Uri.parse(str);
return uri;
} on FormatException catch (_) {
} on FormatException {
throw CLIException(
"Invalid Host Option",
instructions: [
Expand Down
3 changes: 3 additions & 0 deletions packages/config/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
analyzer:
errors:
empty_catches: ignore
include: package:lints/recommended.yaml
2 changes: 1 addition & 1 deletion packages/config/lib/src/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:conduit_runtime/runtime.dart';

class ConfigurationCompiler extends Compiler {
@override
Map<String, dynamic> compile(MirrorContext context) {
Map<String, Object> compile(MirrorContext context) {
return Map.fromEntries(
context.getSubclassesOf(Configuration).map((c) {
return MapEntry(
Expand Down
2 changes: 1 addition & 1 deletion packages/config/test/config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ void main() {
try {
final _ = OptionalEmbeddedContainer.fromString(yamlString);
fail('unreachable');
} on ConfigurationException catch (_) {}
} on ConfigurationException {}
});

test("Database configuration can come from string", () {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
include: package:lints/recommended.yaml

analyzer:
errors:
empty_catches: ignore
exclude:
- tmp/**
- templates/**
2 changes: 1 addition & 1 deletion packages/core/lib/src/application/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,5 @@ abstract class ChannelRuntime {

ApplicationChannel instantiateChannel();

Future? runGlobalInitialization(ApplicationOptions config);
Future runGlobalInitialization(ApplicationOptions config);
}
2 changes: 1 addition & 1 deletion packages/core/lib/src/auth/auth_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AuthController extends ResourceController {
AuthBasicCredentials basicRecord;
try {
basicRecord = _parser.parse(authHeader);
} on AuthorizationParserException catch (_) {
} on AuthorizationParserException {
return _responseForError(AuthRequestError.invalidClient);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/src/db/managed/validation/metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum Validating { update, insert }
/// Information about a validation being performed.
class ValidationContext {
/// Whether this validation is occurring during update or insert.
Validating? event;
late Validating event;

/// The property being validated.
ManagedPropertyDescription? property;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/src/runtime/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import 'package:yaml/yaml.dart';

class ConduitCompiler extends Compiler {
@override
Map<String, dynamic> compile(MirrorContext context) {
final m = <String, dynamic>{};
Map<String, Object> compile(MirrorContext context) {
final m = <String, Object>{};

m.addEntries(
context
Expand Down
10 changes: 4 additions & 6 deletions packages/core/lib/src/runtime/impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ class ChannelRuntimeImpl extends ChannelRuntime implements SourceCompiler {
}

@override
Future? runGlobalInitialization(ApplicationOptions config) {
Future runGlobalInitialization(ApplicationOptions config) async {
if (hasGlobalInitializationMethod) {
return type.invoke(_globalStartSymbol, [config]).reflectee as Future?;
return type.invoke(_globalStartSymbol, [config]).reflectee as Future;
}

return null;
}

@override
Iterable<APIComponentDocumenter?> getDocumentableChannelComponents(
Iterable<APIComponentDocumenter> getDocumentableChannelComponents(
ApplicationChannel channel,
) {
final documenter = reflectType(APIComponentDocumenter);
Expand All @@ -65,7 +63,7 @@ class ChannelRuntimeImpl extends ChannelRuntime implements SourceCompiler {
.map((dm) {
return reflect(channel).getField(dm.simpleName).reflectee
as APIComponentDocumenter?;
}).where((o) => o != null);
}).whereType<APIComponentDocumenter>();
}

@override
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/src/runtime/orm/data_model_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:conduit_core/src/runtime/orm/entity_builder.dart';
import 'package:conduit_runtime/runtime.dart';

class DataModelCompiler {
Map<String, dynamic> compile(MirrorContext context) {
final m = <String, dynamic>{};
Map<String, Object> compile(MirrorContext context) {
final m = <String, Object>{};

final instanceTypes = context.types
.where(_isTypeManagedObjectSubclass)
Expand Down
12 changes: 6 additions & 6 deletions packages/core/lib/src/runtime/orm/entity_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class EntityBuilder {
final Table? metadata;
final ResponseModel? responseModel;

ManagedEntityRuntime? runtime;
late final ManagedEntityRuntime runtime;

late final String name = _getName();
late ManagedEntity entity;
late final ManagedEntity entity;
List<String>? uniquePropertySet;
late PropertyBuilder primaryKeyProperty;
List<PropertyBuilder> properties = [];
Map<String?, ManagedAttributeDescription?> attributes = {};
Map<String?, ManagedRelationshipDescription?> relationships = {};
late final PropertyBuilder primaryKeyProperty;
late final List<PropertyBuilder> properties;
final Map<String, ManagedAttributeDescription?> attributes = {};
final Map<String, ManagedRelationshipDescription?> relationships = {};

String get instanceTypeName => MirrorSystem.getName(instanceType.simpleName);

Expand Down
15 changes: 8 additions & 7 deletions packages/core/lib/src/runtime/orm_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ class ManagedEntityRuntimeImpl extends ManagedEntityRuntime

@override
ManagedObject instanceOfImplementation({ManagedBacking? backing}) {
final object =
instanceType.newInstance(Symbol.empty, []).reflectee as ManagedObject?;
try {
final object =
instanceType.newInstance(Symbol.empty, []).reflectee as ManagedObject;

if (object == null) {
if (backing != null) {
object.backing = backing;
}
return object;
} on TypeError {
throw StateError('No implementation found for $instanceType');
}
if (backing != null) {
object.backing = backing;
}
return object;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void _registerType(APIDocumentContext context, TypeMirror typeMirror) {

final classMirror = typeMirror;
if (!context.schema.hasRegisteredType(classMirror.reflectedType) &&
_shouldDocumentSerializable(classMirror.reflectedType)!) {
_shouldDocumentSerializable(classMirror.reflectedType)) {
final instance =
classMirror.newInstance(Symbol.empty, []).reflectee as Serializable;
context.schema.register(
Expand All @@ -256,13 +256,13 @@ void _registerType(APIDocumentContext context, TypeMirror typeMirror) {
}
}

bool? _shouldDocumentSerializable(Type type) {
bool _shouldDocumentSerializable(Type type) {
final hierarchy = classHierarchyForClass(reflectClass(type));
final definingType = hierarchy.firstWhereOrNull(
(cm) => cm.staticMembers.containsKey(#shouldAutomaticallyDocument),
);
if (definingType == null) {
return Serializable.shouldAutomaticallyDocument;
}
return definingType.getField(#shouldAutomaticallyDocument).reflectee as bool?;
return definingType.getField(#shouldAutomaticallyDocument).reflectee as bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class ResourceControllerRuntimeImpl extends ResourceControllerRuntime {
args.positionalArguments,
args.namedArguments.map((k, v) => MapEntry(Symbol(k), v)),
)
.reflectee as Future<Response?>;
.reflectee as Future<Response>;
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/http/body_encoder_streaming_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void main() {
final result = await resultFuture;
expect(result.statusCode, 500);
expect(result.bodyBytes, []);
} on http.ClientException catch (_) {}
} on http.ClientException {}
});
});

Expand Down Expand Up @@ -373,7 +373,7 @@ void main() {
try {
final response = await req.close();
expect(response.statusCode, 413);
} on SocketException catch (_) {
} on SocketException {
if (!Platform.isMacOS) {
rethrow;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/fs_test_agent/lib/dart_project_agent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'dart:io';

import 'package:fs_test_agent/working_directory_agent.dart';
import 'package:path/path.dart';
import 'package:pubspec/pubspec.dart';
import 'package:pubspec_parse/pubspec_parse.dart';

/// A [WorkingDirectoryAgent] with additional behavior for managing a 'Dart package' directory.
class DartProjectAgent extends WorkingDirectoryAgent {
Expand Down Expand Up @@ -51,8 +51,8 @@ class DartProjectAgent extends WorkingDirectoryAgent {
);
}

final pubspec = PubSpec.fromYamlString(pubspecFile.readAsStringSync());
name = pubspec.name!;
final pubspec = Pubspec.parse(pubspecFile.readAsStringSync());
name = pubspec.name;
}

/// Temporary directory where projects are stored ('/tmp/conduit')
Expand Down
2 changes: 1 addition & 1 deletion packages/fs_test_agent/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:

dependencies:
path: ^1.9.0
pubspec: ^2.3.0
pubspec_parse: ^1.2.3

dev_dependencies:
lints: ^3.0.0
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/lib/runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'package:conduit_runtime/src/mirror_context.dart';
/// a generated runtime to the replica's pubspec.
class RuntimePackageCompiler extends Compiler {
@override
Map<String, dynamic> compile(MirrorContext context) => {};
Map<String, Object> compile(MirrorContext context) => {};

@override
void deflectPackage(Directory destinationDirectory) {
Expand Down
4 changes: 1 addition & 3 deletions packages/runtime/lib/slow_coerce.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ T cast<T>(dynamic input) {
return List<bool?>.from(input) as T;
} else if (typeString.startsWith("List<Map<String, dynamic>>")) {
return List<Map<String, dynamic>>.from(input) as T;
} else if (typeString.startsWith("List<Map<String, dynamic>?>")) {
return List<Map<String, dynamic>?>.from(input) as T;
}
} else if (typeString.startsWith(_mapPrefix)) {
if (input is! Map) {
Expand Down Expand Up @@ -73,7 +71,7 @@ T cast<T>(dynamic input) {
}

return input as T;
} on TypeError catch (_) {
} on TypeError {
throw TypeCoercionException(T, input.runtimeType);
}
}
2 changes: 1 addition & 1 deletion packages/runtime/lib/src/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Build {
print("Generated runtime at '${context.buildRuntimeDirectory.uri}'.");

final nameOfPackageBeingCompiled = context.sourceApplicationPubspec.name;
final pubspecMap = <String, dynamic>{
final pubspecMap = <String, Object>{
'name': 'runtime_target',
'version': '1.0.0',
'environment': {'sdk': '>=3.3.0 <4.0.0'},
Expand Down
Loading

0 comments on commit d6e6063

Please sign in to comment.