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

FI-2266: inferno new generator #408

Merged
merged 61 commits into from
Jan 17, 2024
Merged

FI-2266: inferno new generator #408

merged 61 commits into from
Jan 17, 2024

Conversation

Shaumik-Ashraf
Copy link
Contributor

@Shaumik-Ashraf Shaumik-Ashraf commented Nov 22, 2023

Summary

Implemented working inferno new command with the following:

Usage was updated in comments below

Usage:
  inferno new TEST_KIT_NAME [-i IG_URL]

Options:
  -i, [--implementation-guide=IG_URL]  # URL to an implementation guide or absolute path to a package.tgz
  -a, [--author=AUTHOR]                # Author names for gemspec file; you may use '-a' multiple times

Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

Generate a new Inferno test kit for FHIR software testing

Examples:

  `inferno new test_fhir_app`
    => generates an Inferno app

  `inferno new test_us_core -i https://build.fhir.org/ig/HL7/US-Core/`
    => generates Inferno app and loads US Core implementation guide

  `inferno new test_my_ig -i /absolute/path/to/ig/package.tgz -a Name`
    => generates Inferno app, loads a local implementation guide, and specifies Name as author

https://inferno-framework.github.io/index.html

Some key things to note in the implementation:

  • Made rails-like generator heavily leveraging Thor::Actions
  • /lib/inferno/apps/cli/new/templates dictates the contents of a new Inferno project
  • Added dry/inflector for good naming, but doesn't support acronyms like 'FHIR' well. No acronym support in this PR.
  • I tried to do rspec testing on it
  • There is a library called aruba that can integrate with RSpec and test CLIs better, but I opted not to use it for now

Testing Guidance

Both rake spec and rubocop should pass. The main testing file is spec/inferno/apps/cli/new_spec.rb which only focuses on testing naming and IG loading. Features from Thor::Actions like --pretend or say aren't tested via RSpec.

For manual testing I did:

  1. mkdir tmp
  2. cd tmp
  3. bundle init
  4. add to Gemfile:
gem "inferno_core", path: "your/path/to/inferno_core/dev/with/fi-2266-inferno-new/branch"
  1. bundle install --binstubs
  2. bin/inferno new --help and other new commands

Copy link

codecov bot commented Nov 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bd57638) 77.02% compared to head (11da63d) 77.06%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #408      +/-   ##
==========================================
+ Coverage   77.02%   77.06%   +0.03%     
==========================================
  Files         218      219       +1     
  Lines       10914    10931      +17     
  Branches     1026     1026              
==========================================
+ Hits         8407     8424      +17     
  Misses       1928     1928              
  Partials      579      579              
Flag Coverage Δ
backend 93.92% <100.00%> (+0.03%) ⬆️
frontend 69.59% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@Jammjammjamm Jammjammjamm left a comment

Choose a reason for hiding this comment

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

I like the inclusion of the put_ig_package_dot_tgz_here file just to make things even more obvious.

I feel like we should probably include Gemfile.lock, although that seems like it could be tricky. Any ideas on a good way to do that?

lib/inferno/apps/cli/new.rb Outdated Show resolved Hide resolved
lib/inferno/apps/cli/templates/%library_name%.gemspec.tt Outdated Show resolved Hide resolved
lib/inferno/apps/cli/templates/README.md.tt Show resolved Hide resolved
lib/inferno/apps/cli/new.rb Show resolved Hide resolved
@Shaumik-Ashraf
Copy link
Contributor Author

Shaumik-Ashraf commented Dec 22, 2023

@Jammjammjamm ready for re-review.

For Gemfile.lock, I put in an Gemfile.lock.tt template that works in the current PR, but this solution feels flimsy. If inferno_core adds new dependencies bundle install will break on new templates, unless the team remembers to update the Gemfile.lock.tt template each time. There aren't any integration tests to catch this either.

Edit: rails new just runs bundle install after the new generator. Should I implement this instead?

Also bundler.io recommends rebuilding Gemfile.lock with CI.

@Jammjammjamm
Copy link
Collaborator

rails new just runs bundle install after the new generator. Should I implement this instead?

I think that makes sense. The user will have to run it anyway, so we may as well cut out that step.

@Shaumik-Ashraf
Copy link
Contributor Author

I replaced Gemfile.lock.tt template with running bundle install.

I also added a publish_template.sh script that puts up a new branch at inferno-template with the latest inferno new inferno-template run. Merging it shouldn't delete NOTICE.md from inferno-framework/inferno-template#22 (data rights legend PR) but does add copyright 2024 TODO back in the README.md. Is this okay?

Ready for review @Jammjammjamm, @arscan

Copy link
Collaborator

@Jammjammjamm Jammjammjamm left a comment

Choose a reason for hiding this comment

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

Could you just remove the publish script? This is so close to being done I don't think we should be adding anything new.

When I run bin/inferno new inferno_template I get:

inferno/lib/inferno/apps/cli/templates/%library_name%.gemspec.tt:11:in `template': uninitialized constant Inferno::VERSION (NameError)

@Shaumik-Ashraf
Copy link
Contributor Author

Removed publish_template.sh and fixed bugs. Ready for review @Jammjammjamm

@Jammjammjamm
Copy link
Collaborator

After bundle install, this should run the migrations too. Otherwise I think this is good to go.

@Shaumik-Ashraf
Copy link
Contributor Author

Added inferno migrate

lib/inferno/apps/cli/new.rb Outdated Show resolved Hide resolved
@Shaumik-Ashraf Shaumik-Ashraf merged commit b7ecc81 into main Jan 17, 2024
10 checks passed
@Shaumik-Ashraf Shaumik-Ashraf deleted the fi-2266-inferno-new branch January 23, 2024 17:37
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.

3 participants