Skip to content
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

Closed
wants to merge 6 commits into from
Closed

an implementation of the init command #293

wants to merge 6 commits into from

Conversation

hathibelagal-dev
Copy link

Fixes #193

@hathibelagal-dev
Copy link
Author

Added the init command, a test for it, and updated the README.

final repoCfgPath = p.join(rootDir, _repoCfgFileName);
if (!File(repoCfgPath).existsSync()) {
File(repoCfgPath).writeAsStringSync(_commentText);
print('Added $_repoCfgFileName to $rootDir');
Copy link
Collaborator

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'))

File(repoCfgPath).writeAsStringSync(_commentText);
print('Added $_repoCfgFileName to $rootDir');
} else {
print('$_repoCfgFileName already present in $rootDir. Exiting...');
Copy link
Collaborator

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

final pubspecPath = p.join(currentDir, _pubspecFileName);

if (!File(pubspecPath).existsSync()) {
final pubspecContents = 'name: ${p.basename(currentDir)}\n';
Copy link
Collaborator

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);
Copy link
Collaborator

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 generatecommand for an example. Then we can set the default as well (it should be false, imo).

}

if (!File(pkgCfgPath).existsSync()) {
File(pkgCfgPath).writeAsStringSync(_commentText);
Copy link
Collaborator

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:

if (currentDir == rootDir) {
final repoCfgPath = p.join(rootDir, _repoCfgFileName);
if (!File(repoCfgPath).existsSync()) {
File(repoCfgPath).writeAsStringSync(_commentText);
Copy link
Collaborator

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) {
Copy link
Collaborator

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.

Copy link
Author

@hathibelagal-dev hathibelagal-dev Dec 11, 2020

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.

Copy link
Author

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.

@hathibelagal-dev
Copy link
Author

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?

@jakemac53
Copy link
Collaborator

Missed your updates here somehow sorry - taking a look

@jakemac53
Copy link
Collaborator

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?

The usage of the global config and not arg parser is weird, but it looks like the base MonoRepo class is doing this already so what you have is probably fine (its at least consistent, maybe we should clean it all up later).

I think you do need to add a default in when reading it though (or add recursive ??= false to the top of the configureDirectory method).

Comment on lines +27 to +34
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 }}
Copy link
Collaborator

@jakemac53 jakemac53 Dec 17, 2020

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.

Suggested change
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:

@jakemac53
Copy link
Collaborator

@kevmoo did you have thoughts here?

@kevmoo
Copy link
Collaborator

kevmoo commented Dec 17, 2020

@kevmoo did you have thoughts here?

...if you're happy... 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add command to scaffold a new mono_repo
3 participants