Skip to content

Commit

Permalink
set up mono_repo configs (#12)
Browse files Browse the repository at this point in the history
Closes #2

I also added tool/dart_model_generator to the workspace config.
  • Loading branch information
jakemac53 authored Jun 21, 2024
1 parent 1abc0e6 commit 98ae98b
Show file tree
Hide file tree
Showing 9 changed files with 554 additions and 11 deletions.
396 changes: 396 additions & 0 deletions .github/workflows/dart.yml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions mono_repo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See https://github.com/google/mono_repo.dart for details on this file

# The stage to put the "mono_repo validate" check in.
self_validate: analyze_and_format

# These stages are fast, and we don't need parallelism of jobs, so we run them
# all in the same job.
merge_stages:
- analyze_and_format
15 changes: 15 additions & 0 deletions pkgs/dart_model/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sdk:
- pubspec
- dev

stages:
- analyze_and_format:
- analyze: --fatal-infos .
- format:
sdk:
- dev
- unit_test:
- test: --test-randomize-ordering-seed=random
os:
- linux
- windows
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dev_dependencies:
publish_to: none
workspace:
- pkgs/dart_model
- tool/dart_model_generator
111 changes: 111 additions & 0 deletions tool/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash
# Created with package:mono_repo v6.6.1

# Support built in commands on windows out of the box.

# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")
# then "flutter pub" is called instead of "dart pub".
# This assumes that the Flutter SDK has been installed in a previous step.
function pub() {
if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then
command flutter pub "$@"
else
command dart pub "$@"
fi
}

function format() {
command dart format "$@"
}

# When it is a flutter repo (check the pubspec.yaml for "sdk: flutter")
# then "flutter analyze" is called instead of "dart analyze".
# This assumes that the Flutter SDK has been installed in a previous step.
function analyze() {
if grep -Fq "sdk: flutter" "${PWD}/pubspec.yaml"; then
command flutter analyze "$@"
else
command dart analyze "$@"
fi
}

if [[ -z ${PKGS} ]]; then
echo -e '\033[31mPKGS environment variable must be set! - TERMINATING JOB\033[0m'
exit 64
fi

if [[ "$#" == "0" ]]; then
echo -e '\033[31mAt least one task argument must be provided! - TERMINATING JOB\033[0m'
exit 64
fi

SUCCESS_COUNT=0
declare -a FAILURES

for PKG in ${PKGS}; do
echo -e "\033[1mPKG: ${PKG}\033[22m"
EXIT_CODE=0
pushd "${PKG}" >/dev/null || EXIT_CODE=$?

if [[ ${EXIT_CODE} -ne 0 ]]; then
echo -e "\033[31mPKG: '${PKG}' does not exist - TERMINATING JOB\033[0m"
exit 64
fi

dart pub upgrade || EXIT_CODE=$?

if [[ ${EXIT_CODE} -ne 0 ]]; then
echo -e "\033[31mPKG: ${PKG}; 'dart pub upgrade' - FAILED (${EXIT_CODE})\033[0m"
FAILURES+=("${PKG}; 'dart pub upgrade'")
else
for TASK in "$@"; do
EXIT_CODE=0
echo
echo -e "\033[1mPKG: ${PKG}; TASK: ${TASK}\033[22m"
case ${TASK} in
analyze)
echo 'dart analyze --fatal-infos .'
dart analyze --fatal-infos . || EXIT_CODE=$?
;;
format)
echo 'dart format --output=none --set-exit-if-changed .'
dart format --output=none --set-exit-if-changed . || EXIT_CODE=$?
;;
test)
echo 'dart test --test-randomize-ordering-seed=random'
dart test --test-randomize-ordering-seed=random || EXIT_CODE=$?
;;
*)
echo -e "\033[31mUnknown TASK '${TASK}' - TERMINATING JOB\033[0m"
exit 64
;;
esac

if [[ ${EXIT_CODE} -ne 0 ]]; then
echo -e "\033[31mPKG: ${PKG}; TASK: ${TASK} - FAILED (${EXIT_CODE})\033[0m"
FAILURES+=("${PKG}; TASK: ${TASK}")
else
echo -e "\033[32mPKG: ${PKG}; TASK: ${TASK} - SUCCEEDED\033[0m"
SUCCESS_COUNT=$((SUCCESS_COUNT + 1))
fi

done
fi

echo
echo -e "\033[32mSUCCESS COUNT: ${SUCCESS_COUNT}\033[0m"

if [ ${#FAILURES[@]} -ne 0 ]; then
echo -e "\033[31mFAILURES: ${#FAILURES[@]}\033[0m"
for i in "${FAILURES[@]}"; do
echo -e "\033[31m $i\033[0m"
done
fi

popd >/dev/null || exit 70
echo
done

if [ ${#FAILURES[@]} -ne 0 ]; then
exit 1
fi
3 changes: 2 additions & 1 deletion tool/dart_model_generator/lib/generate_dart_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ String _generateExtensionType(String name, JsonSchema definition) {
// extension types or casts collections as needed. The getters assume the
// data is present and will throw if it's not.
for (final property in propertyMetadatas) {
if (property.description != null)
if (property.description != null) {
result.writeln('/// ${property.description}');
}
result.writeln(switch (property.type) {
PropertyType.object =>
// TODO(davidmorgan): use the extension type constructor instead of
Expand Down
15 changes: 15 additions & 0 deletions tool/dart_model_generator/mono_pkg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
sdk:
- pubspec
- dev

stages:
- analyze_and_format:
- analyze: --fatal-infos .
- format:
sdk:
- dev
- unit_test:
- test: --test-randomize-ordering-seed=random
os:
- linux
- windows
9 changes: 2 additions & 7 deletions tool/dart_model_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: generate_dart_model
publish-to: none

resolution: workspace
environment:
sdk: ^3.4.0
sdk: ^3.5.0-259.0.dev

dependencies:
dart_model: any
Expand All @@ -12,8 +12,3 @@ dependencies:
dev_dependencies:
dart_flutter_team_lints: ^3.0.0
test: ^1.25.7

dependency_overrides:
dart_model:
path:
../../pkgs/dart_model
6 changes: 3 additions & 3 deletions tool/dart_model_generator/test/generated_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ void main() {
File('../../schemas/dart_model.schema.json').readAsStringSync());
final actual = File('../../pkgs/dart_model/lib/src/dart_model.g.dart')
.readAsStringSync();
if (actual != expected) {
fail('''
// TODO: On windows we get carraige returns, which makes this fail
// without ignoring white space. In theory this shouldn't happen.
expect(actual, equalsIgnoringWhitespace(expected), reason: '''
Output is not up to date. Please run
dart tool/dart_model_generator/bin/main.dart
in repo root.
''');
}
});
}

0 comments on commit 98ae98b

Please sign in to comment.