-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
an implementation of the init command #293
Conversation
Added the init command, a test for it, and updated the README. |
mono_repo/lib/src/commands/init.dart
Outdated
final repoCfgPath = p.join(rootDir, _repoCfgFileName); | ||
if (!File(repoCfgPath).existsSync()) { | ||
File(repoCfgPath).writeAsStringSync(_commentText); | ||
print('Added $_repoCfgFileName to $rootDir'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to bold these? We use the package:io/ansi.dart
library for this, so for example this would become:
print(styleBold.wrap('Added $_repoCfgFileName to $rootDir'))
mono_repo/lib/src/commands/init.dart
Outdated
File(repoCfgPath).writeAsStringSync(_commentText); | ||
print('Added $_repoCfgFileName to $rootDir'); | ||
} else { | ||
print('$_repoCfgFileName already present in $rootDir. Exiting...'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly this should likely be red, or maybe yellow
mono_repo/lib/src/commands/init.dart
Outdated
final pubspecPath = p.join(currentDir, _pubspecFileName); | ||
|
||
if (!File(pubspecPath).existsSync()) { | ||
final pubspecContents = 'name: ${p.basename(currentDir)}\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am not completely opposed to this part, but I wasn't originally assuming this would create any packages for you (it would assume the packages exist and just create mono repo files).
I can see value in both options though, and this does allow for the bootstrapping existing packages case still so 🤷
String get description => 'Scaffold a new mono repo.'; | ||
|
||
@override | ||
void run() => scaffold(p.current, globalResults[_recursiveScanFlag] as bool); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command should use its own arg parser and then use argResults
here - see the generate
command for an example. Then we can set the default as well (it should be false
, imo).
mono_repo/lib/src/commands/init.dart
Outdated
} | ||
|
||
if (!File(pkgCfgPath).existsSync()) { | ||
File(pkgCfgPath).writeAsStringSync(_commentText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the package config, it would be good to initialize this with some default settings.
For instance running dartanalyzer, dartfmt and pub run test, something like this:
dart:
- dev
- stable
os:
- linux
stages:
- analyze_and_format:
- dartanalyzer: --fatal-infos --fatal-warnings .
- dartfmt: sdk
- unit_test:
- test:
mono_repo/lib/src/commands/init.dart
Outdated
if (currentDir == rootDir) { | ||
final repoCfgPath = p.join(rootDir, _repoCfgFileName); | ||
if (!File(repoCfgPath).existsSync()) { | ||
File(repoCfgPath).writeAsStringSync(_commentText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for this one we should default to enabling github actions.
It might also be nice to plop in some other common settings such as a cron job and webhook notifications for failed jobs on master?
|
||
final subdirs = | ||
Directory(currentDir).listSync().whereType<Directory>().toList(); | ||
for (var subdir in subdirs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit on the fence about this behavior - especially in the case of pre-existing packages we wouldn't want to go creating a whole bunch of pubspecs in all nested packages.
I am somewhat inclined to just not support this for the init
command at all - or we could remove the behavior that creates a new package in all directories where a pubspec did not exist before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add the mono_pkg.yaml only to directories that already have a pubspec.yaml, we're assuming the user is never starting from scratch.
And I was initially adding the mono_pkg.yaml file only to the immediate subdirectories of root. But directory structures such as root/pkgs/package1,package2 are common too, so doing it recursively seemed to make more sense. But this would add the files in the pkgs directory too, which would be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be safest to add the mono_pkg.yaml only to directories that have a pubspec.yaml.
Now that I'm only adding mono_pkg.yaml to directories that have a pubspec.yaml, do I still need to use the arg parser? Wouldn't the default recursive setting be acceptable now? |
Missed your updates here somehow sorry - taking a look |
The usage of the global config and not arg parser is weird, but it looks like the base I think you do need to add a default in when reading it though (or add |
if: (github.event_name == 'push' || github.event_name == 'schedule') && failure() | ||
steps: | ||
- run: > | ||
curl -H "Content-Type: application/json" -X POST -d \ | ||
"{'text':'Build failed! ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}'}" \ | ||
"${CHAT_WEBHOOK_URL}" | ||
env: | ||
CHAT_WEBHOOK_URL: ${{ secrets.BUILD_AND_TEST_TEAM_CHAT_WEBHOOK_URL }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section should be commented out, as it won't work without some repo level configuration and it is also specific to the expected payload for google chat webhooks and won't work for slack, etc.
if: (github.event_name == 'push' || github.event_name == 'schedule') && failure() | |
steps: | |
- run: > | |
curl -H "Content-Type: application/json" -X POST -d \ | |
"{'text':'Build failed! ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}'}" \ | |
"${CHAT_WEBHOOK_URL}" | |
env: | |
CHAT_WEBHOOK_URL: ${{ secrets.BUILD_AND_TEST_TEAM_CHAT_WEBHOOK_URL }} | |
# if: (github.event_name == 'push' || github.event_name == 'schedule') && failure() | |
# steps: | |
# - run: > | |
# curl -H "Content-Type: application/json" -X POST -d \ | |
# # Note that this is specific to google chat webhook format - other services expect | |
# # a different looking JSON payload. | |
# "{'text':'Build failed! ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}'}" \ | |
# "${CHAT_WEBHOOK_URL}" | |
# env: | |
# CHAT_WEBHOOK_URL: ${{ secrets.<your-github-secret-id> }} |
env: | ||
CHAT_WEBHOOK_URL: ${{ secrets.BUILD_AND_TEST_TEAM_CHAT_WEBHOOK_URL }} | ||
|
||
merge_stages: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge_stages: | |
# Merges all tasks from this stage across all packages into a single job, where possible. | |
# This speeds up CI runs when you have lots of very small tasks. | |
merge_stages: |
@kevmoo did you have thoughts here? |
...if you're happy... 😄 |
Fixes #193