The Moderne CLI is a command line tool that compliments the Moderne Platform and Moderne DX, enabling you to build Lossless Semantic Tree (LST) artifacts across many repositories and run recipes against all of them from your local machine. It also provides substantial benefits for creating and testing your own recipes.
To ensure you can use the Moderne CLI successfully, in this guide, we will walk you through everything you need to get started – from installation, to configuration, to examples demonstrating how to use it.
Assumptions
You can access app.moderne.io or a private Moderne tenant
Go to the Moderne Platform (or your private tenant) and sign in.
Click on Help in the bottom left-hand corner and select the version of the CLI you want to download (Stable or Staging).
Either press the download button for your appropriate OS, or select the installation method in the provided table. We recommend using HomeBrew or Chocolatey if you have access to either.
If you chose to install the CLI without a package manager, you'll need to save it somewhere that your terminal can access. This could involve updating your PATH to point to a specific location – or this could involve putting it in a directory that's already on your PATH (such as a /user/bin directory).
Remember to refresh any open terminals if you modify the PATH.
If everything was configured correctly, you should be able to type mod into your terminal and see a list of commands:
mod command results
➜modModerneCLI3.20.10Usage:mod [-h] [--version] [COMMAND]Description:Automatedcoderemediation.Options:-h,--helpDisplaythishelpmessage.--versionDisplayversioninfo.Commands:afterburner (INCUBATING) Indexes built LSTs to accelerate recipeexecution.audit (INCUBATING) Perform an audit of recent activity.buildGeneratesLSTartifactsforoneormorerepositories.cleanCleanbuildandrunartifactsproducedbytheCLI.configGlobalconfigurationoptionsthatarerequiredbysomeCLIcommands.devcenterDevCenteroperations.execExecuteanarbitraryshellcommandrecursivelyonselectedrepositoryroots.gitMulti-repositorygitoperations.logManagesalogaggregate.listListstherepositoriesthatcanbebuiltandpublished.monitor (INCUBATING) Launches an HTTP server used to monitor theCLI.publishPublishestheLSTartifactsforoneormoreprojects.runRunsanOpenRewriterecipelocallyonpre-builtLSTS.run-historyGetinformationaboutthemostrecentreciperuns.Thiswillbetransitioningtomodauditrunslisteventually.Adeprecationnoticewillbeaddedherewhenwesuggestadoptingthealternative.studyProducesstudiesfromOpenRewriterecipedatatableslocally.generate-completionGeneratebash/zshcompletionscriptformod.MODSUCCEEDEDin (0.01s)
Step 2: (Optional) Set up auto-completion in your terminal (Unix terminals only)
The Moderne CLI offers a command which generates a completion script that can be used to set up auto-completion in your terminal. After initializing this script, you can type mod config and press tab and then your terminal will offer suggestions for the sub-commands or parameters:
To configure this for the terminal you're using please enter the following command in your terminal:
source<(modgenerate-completion)
Or, if you want to configure auto-completion so that it works for every terminal instance you make, please update your ~/.zshrc or ~/.bashrc file and add this command to the bottom of it:
# The next line enables shell command completion for modsource<(modgenerate-completion)
Step 3: Connect the CLI to Moderne
Connecting the CLI to Moderne is necessary to:
Quickly sync the recipe catalog from Moderne to your local machine
Download pre-built LSTs from Moderne so you can quickly run recipes locally
Receive organizational information, so you can clone/build/run groups of repositories more easily
To set up this connection, you'll first need to create an access token for the CLI to use. Follow the below instructions to obtain a token and provide it to the CLI:
If everything worked, you should see a MOD SUCCEEDED message
Step 4: Install recipes
With the Moderne connection established, you can download recipes to your local machine by running the following command:
modconfigrecipesmodernesync
This will grab all of the recipes from the tenant you specified in mod config – so please expect this command to take a few minutes to download the recipes.
Using the CLI
With installation and configuration done, you're now ready to use the CLI. Let's walk through some things you might do with it. We recommend you follow along on your own machine to get a feel for how to use the CLI.
Run recipes against many repositories at once
In this example, we will use the Moderne CLI to run the DependencyVulnerabilityCheck recipe against a group of open-source repositories.
From your terminal, create a directory to work in and cd into it:
mkdir-p $HOME/workshopcd $HOME/workshop
For this exercise, we've prepared a list of open-source repositories for you to use. These repositories have been added to the Moderne Platform and put inside the Default organization. Clone these repositories by running the following command from inside your workshop directory.
Now that you have the repositories on your local machine, you'll need to build the Lossless Semantic Trees (LSTs) for them so that you can run recipes against them. Fortunately, since most of these repositories have their LSTs published to the Moderne Platform, the build operation will download the LSTs without you having to build them locally. This will save you a ton of time!
By default, the CLI is able to build LSTs for well-formed projects (i.e. projects that build well with a plain mvn verify or gradle build). At times, however, you may encounter a project that fails to build. This could be because of a hidden dependency on certain tooling, like NPM, or because specific dependencies or repositories are not available without additional configuration.
Through mod config build and other configuration options, you're typically able to get these LSTs built and ingested fairly quickly. For the purposes of this tutorial, however, let's ignore any projects that don't build and focus on running recipes against the ones that do.
modbuild.--download-only
You should see output similar to the following.
ModerneCLI3.20.10> Selecting repositories> apache/maven-doxia@master> aws/amazon-documentdb-jdbc-driver@develop> awslabs/aws-saas-boost@main> finos/messageml-utils@main> finos/spring-bot@spring-bot-master> finos/symphony-bdk-java@main> finos/symphony-wdk@master> Netflix/ndbench@master> Netflix/photon@master> Netflix/ribbon@master> openrewrite/rewrite-recipe-bom@main> openrewrite/rewrite-sql@main> spring-projects/spring-data-commons@main> spring-projects/spring-petclinic@mainSelected14repositories (1s)> Building LST(s)> apache/maven-doxia@master Build output will be written to /Users/mikesol/workshop/apache/maven-doxia/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/apache/maven-doxia/.moderne/build/20240904083148-s7SDp/maven-doxia-20240904124207407-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> aws/amazon-documentdb-jdbc-driver@develop Build output will be written to /Users/mikesol/workshop/aws/amazon-documentdb-jdbc-driver/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne!FailedtodownloadtheLSTfromModerne.ProceedingtobuildtheLSTlocally!Skippingbuildbecause--download-onlywasspecified+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> awslabs/aws-saas-boost@main Build output will be written to /Users/mikesol/workshop/awslabs/aws-saas-boost/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/awslabs/aws-saas-boost/.moderne/build/20240904083148-s7SDp/aws-saas-boost-20240904124344180-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> finos/messageml-utils@main Build output will be written to /Users/mikesol/workshop/finos/messageml-utils/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/finos/messageml-utils/.moderne/build/20240904083148-s7SDp/messageml-utils-20240904124418454-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> finos/spring-bot@spring-bot-master Build output will be written to /Users/mikesol/workshop/finos/spring-bot/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/finos/spring-bot/.moderne/build/20240904083148-s7SDp/spring-bot-20240904124515391-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> finos/symphony-bdk-java@main Build output will be written to /Users/mikesol/workshop/finos/symphony-bdk-java/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/finos/symphony-bdk-java/.moderne/build/20240904083148-s7SDp/symphony-bdk-java-20240904125118774-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> finos/symphony-wdk@master Build output will be written to /Users/mikesol/workshop/finos/symphony-wdk/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/finos/symphony-wdk/.moderne/build/20240904083148-s7SDp/symphony-wdk-20240904125339731-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> Netflix/ndbench@master Build output will be written to /Users/mikesol/workshop/Netflix/ndbench/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne!FailedtodownloadtheLSTfromModerne.ProceedingtobuildtheLSTlocally!Skippingbuildbecause--download-onlywasspecified+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> Netflix/photon@master Build output will be written to /Users/mikesol/workshop/Netflix/photon/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/Netflix/photon/.moderne/build/20240904083148-s7SDp/photon-20240904134649877-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> Netflix/ribbon@master Build output will be written to /Users/mikesol/workshop/Netflix/ribbon/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/Netflix/ribbon/.moderne/build/20240904083148-s7SDp/ribbon-20240904134938748-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> openrewrite/rewrite-recipe-bom@main Build output will be written to /Users/mikesol/workshop/openrewrite/rewrite-recipe-bom/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/openrewrite/rewrite-recipe-bom/.moderne/build/20240904083148-s7SDp/rewrite-recipe-bom-20240904140002559-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> openrewrite/rewrite-sql@main Build output will be written to /Users/mikesol/workshop/openrewrite/rewrite-sql/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/openrewrite/rewrite-sql/.moderne/build/20240904083148-s7SDp/rewrite-sql-20240904140118570-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> spring-projects/spring-data-commons@main Build output will be written to /Users/mikesol/workshop/spring-projects/spring-data-commons/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne!FailedtodownloadtheLSTfromModerne.ProceedingtobuildtheLSTlocally!Skippingbuildbecause--download-onlywasspecified+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.> spring-projects/spring-petclinic@main Build output will be written to /Users/mikesol/workshop/spring-projects/spring-petclinic/.moderne/build/20240904083148-s7SDp/build.log
>DownloadfromModerne + Downloaded LST /Users/mikesol/workshop/spring-projects/spring-petclinic/.moderne/build/20240904083148-s7SDp/spring-petclinic-20240904141033601-ast.jar
+ReportedbuildmetricstoModerne+Cleaned0olderbuilds.BuiltLSTsfor0repositories,downloaded11LSTs (11s)19m57ssavedbyusingpreviouslybuiltLSTs* What to donext>Runmodrun.--recipe=<RecipeName>>Runmoddevcenterrun.>Runmodlogbuildsadd.logs.zip--last-buildtoaggregatebuildlogsMODSUCCEEDEDin (12s)
With the LSTs downloaded to your machine, you can now run recipes against them. Let's run the DependencyVulnerabilityCheck recipe to find and fix vulnerable dependencies. Unlike many other tools, this recipe can find and fix dependencies that are many levels deep. For instance, if you depend on a library which depends on a library which depends on a library which contains a vulnerable dependency, this recipe can find that and offer suggestions on how to fix it.
modrun.--recipeDependencyVulnerabilityCheck# Select the recipe that matches org.openrewrite.java.dependencies.DependencyVulnerabilityCheck
You should see output similar to the following.
ModerneCLI3.20.10> Selecting repositories> apache/maven-doxia@master> aws/amazon-documentdb-jdbc-driver@develop> awslabs/aws-saas-boost@main> finos/messageml-utils@main> finos/spring-bot@spring-bot-master> finos/symphony-bdk-java@main> finos/symphony-wdk@master> Netflix/ndbench@master> Netflix/photon@master> Netflix/ribbon@master> openrewrite/rewrite-recipe-bom@main> openrewrite/rewrite-sql@main> spring-projects/spring-data-commons@main> spring-projects/spring-petclinic@mainSelected14repositories (0.33s)[1] Find and fix vulnerable Nuget dependencies (org.openrewrite.csharp.dependencies.DependencyVulnerabilityCheck)[2] Find and fix vulnerable dependencies (org.openrewrite.java.dependencies.DependencyVulnerabilityCheck)[3] Find and fix vulnerable npm dependencies (org.openrewrite.nodejs.DependencyVulnerabilityCheck)Selectarecipe [1-3]: 2> Running recipe org.openrewrite.java.dependencies.DependencyVulnerabilityCheck> apache/maven-doxia@masterNochanges> aws/amazon-documentdb-jdbc-driver@develop!SkippingreciperunbecausenoLSTwasfound> awslabs/aws-saas-boost@main+Fixresultsat/Users/mikesol/workshop/awslabs/aws-saas-boost/.moderne/run/20240904083238-wRnHo/fix.patch> finos/messageml-utils@mainNochanges> finos/spring-bot@spring-bot-masterNochanges> finos/symphony-bdk-java@mainNochanges> finos/symphony-wdk@masterNochanges> Netflix/ndbench@master!SkippingreciperunbecausenoLSTwasfound> Netflix/photon@masterNochanges> Netflix/ribbon@master+Fixresultsat/Users/mikesol/workshop/Netflix/ribbon/.moderne/run/20240904083238-wRnHo/fix.patch> openrewrite/rewrite-recipe-bom@mainNochanges> openrewrite/rewrite-sql@mainNochanges> spring-projects/spring-data-commons@main!SkippingreciperunbecausenoLSTwasfound> spring-projects/spring-petclinic@mainNochangesFound change results on 2 repositories; data tables available for 11 repositories; skipped 3 repositories with no LST (1m 19s)
19m57ssavedbyusingpreviouslybuiltLSTs* What to donext>!UpdateoutofdateLSTswithmodbuild.>Clickononeofthepatchlinksabovetoviewthechangesonaparticularrepository > Run mod study . --last-recipe-run --data-table <DATA-TABLE> to examine the following data tables produced by this recipe:
org.openrewrite.java.dependencies.table.VulnerabilityReportorg.openrewrite.table.RecipeRunStatsorg.openrewrite.table.SourcesFileResults>Runnpminstall-gdiff2html-clitoproducepatchfilesonsubsequentrunsthatareeasiertoview>Runmodgitcheckout.-bhotfix--last-recipe-runtoprepareahotfixbranchforapplyingthechanges>Runmodgitapply.--last-recipe-runtoapplythechanges>Runmodgitapply.--recipe-run20240904083238-wRnHotoapplythechanges>Runmodlogrunsadd.logs.zip--last-runtoaggregaterunlogsMODSUCCEEDEDin (2m 1s)
To learn more about what changed, you can command/ctrl click on the fix.patch files generated in the above command. If you open one of these patch files up, you'll see that various dependencies in pom.xml or build.gradle files have been updated. While these updates to the dependencies are useful, they are only a minor part of what this recipe does. In the next section we'll take a look at the real power of this recipe – the data table that is produced.
Study the results of a recipe
If you've been following along, you'll know that we just ran the DependencyVulnerabilityCheck recipe. Let's take another look at the What to do next section produced at the end of the recipe run:
* What to donext>!UpdateoutofdateLSTswithmodbuild.>Clickononeofthepatchlinksabovetoviewthechangesonaparticularrepository > Run mod study . --last-recipe-run --data-table <DATA-TABLE> to examine the following data tables produced by this recipe:
org.openrewrite.java.dependencies.table.VulnerabilityReportorg.openrewrite.table.RecipeRunStatsorg.openrewrite.table.SourcesFileResults>Runnpminstall-gdiff2html-clitoproducepatchfilesonsubsequentrunsthatareeasiertoview>Runmodgitcheckout.-bhotfix--last-recipe-runtoprepareahotfixbranchforapplyingthechanges>Runmodgitapply.--last-recipe-runtoapplythechanges>Runmodgitapply.--recipe-run20240904083238-wRnHotoapplythechanges>Runmodlogrunsadd.logs.zip--last-runtoaggregaterunlogs
You may notice that one of the suggestions on what to do next is the mod study command. This command allows you to examine the data tables produced by the recipe run. Data tables are columnar data in a schema defined by the recipe.
In the above example, you'll see there are three data tables produced by this recipe:
The VulnerabilityReport contains detailed information about the vulnerabilities that exist in the repositories. For instance, it will tell you what CVE a particular repository is affected by, what the current version is, what the minimum fixed version is, a clear summary of what is wrong, and how many levels deep the dependency is.
Let's generate this data table by running the following command:
ModerneCLI3.20.10Foundreciperun20240904083238-wRnHo> Selecting repositories> apache/maven-doxia@master> aws/amazon-documentdb-jdbc-driver@develop> awslabs/aws-saas-boost@main> finos/messageml-utils@main> finos/spring-bot@spring-bot-master> finos/symphony-bdk-java@main> finos/symphony-wdk@master> Netflix/ndbench@master> Netflix/photon@master> Netflix/ribbon@master> openrewrite/rewrite-recipe-bom@main> openrewrite/rewrite-sql@main> spring-projects/spring-data-commons@main> spring-projects/spring-petclinic@mainSelected14repositories (0.16s)> Building a combined data table from results on every repository> apache/maven-doxia@master+Didnotproduceanyrowsforthisdatatable> aws/amazon-documentdb-jdbc-driver@develop!Nomatchingreciperunwasfoundinthisrepository,skipping> awslabs/aws-saas-boost@main+Added57rows> finos/messageml-utils@main+Didnotproduceanyrowsforthisdatatable> finos/spring-bot@spring-bot-master+Added60rows> finos/symphony-bdk-java@main+Added139rows> finos/symphony-wdk@master+Added15rows> Netflix/ndbench@master!Nomatchingreciperunwasfoundinthisrepository,skipping> Netflix/photon@master+Added5rows> Netflix/ribbon@master+Added687rows> openrewrite/rewrite-recipe-bom@main+Didnotproduceanyrowsforthisdatatable> openrewrite/rewrite-sql@main+Didnotproduceanyrowsforthisdatatable> spring-projects/spring-data-commons@main!Nomatchingreciperunwasfoundinthisrepository,skipping> spring-projects/spring-petclinic@main+Added8rowsStudied14repositories (13s)* What to donext>Open/Users/mikesol/workshop/VulnerabilityReport.xlsxMODSUCCEEDEDin (13s)
We used the short name for the data table (VulnerabilityReport) rather than the fully-qualified name. As long as the short name is distinct, you can do this to save some typing.
Open up the Excel file that is produced. You will see that the recipe found almost 1,000 vulnerabilities. You can sort them by severity to see what the most important ones to start with are – or you could find the ones that can be fixed with a version update only to quickly address some of the problems. Having a table like this can help you and your organization track and prioritize security issues.
Adjust the format of data tables
Maybe you don't really want an Excel spreadsheet as the output, though. Fortunately, the Moderne CLI lets you customize what you get out of data tables with templates. Let's run a new recipe to demonstrate this. Let's run a recipe to find all locations where the java.util.List add(..) method is used (For more information on how to select a particular method, check out our method patterns documentation).
modrun.--recipeFindMethods-PmethodPattern="java.util.List add(..)"# Select the following recipe: # * Find method usages (org.openrewrite.java.search.FindMethods)
Once that's done running, we could run a similar study command as before to get an Excel file that contains detailed information about all of the places this specific method was found. Let's say, however, that you don't care about all of the columns and that you'd like a markdown file to be produced instead of an Excel spreadsheet.
We can filter the data table to only a couple columns we are interested in and then use a GoTemplate to produce a markdown file containing code samples for all of the matching methods we found:
mod study . --last-recipe-run --data-table MethodCalls --json sourceFile,method --template '{{"# Search results\n\n"}}{{range .}}{{"* "}}{{.sourceFile}}{{"\n```\n"}}{{.method}}{{"\n```\n"}}{{end}}' > methods.md
As you can see, the output is extremely flexible to meet whatever needs you have.
Commit changes and/or create PRs
So far, everything we've done has remained local to your machine. In a real-world situation, though, you'd definitely want to commit the results, test the changes, and open a PR in each repository. Let's walk through how to do this.
To begin, make sure you're still in the $HOME/workshop directory with the Default organization cloned. Then, run the following recipe to resolve common static analysis issues in all of the repositories:
modrun.--recipeCommonStaticAnalysis
You should see output similar to the following.
ModerneCLI3.20.10> Selecting repositories> apache/maven-doxia@master> aws/amazon-documentdb-jdbc-driver@develop> awslabs/aws-saas-boost@main> finos/messageml-utils@main> finos/spring-bot@spring-bot-master> finos/symphony-bdk-java@main> finos/symphony-wdk@master> Netflix/ndbench@master> Netflix/photon@master> Netflix/ribbon@master> openrewrite/rewrite-recipe-bom@main> openrewrite/rewrite-sql@main> spring-projects/spring-data-commons@main> spring-projects/spring-petclinic@mainSelected14repositories (0.32s)> Running recipe org.openrewrite.staticanalysis.CommonStaticAnalysis> apache/maven-doxia@master+Fixresultsat/Users/mikesol/workshop/apache/maven-doxia/.moderne/run/20240904084031-xdbaB/fix.patch> aws/amazon-documentdb-jdbc-driver@develop!SkippingreciperunbecausenoLSTwasfound> awslabs/aws-saas-boost@main+Fixresultsat/Users/mikesol/workshop/awslabs/aws-saas-boost/.moderne/run/20240904084031-xdbaB/fix.patch> finos/messageml-utils@main+Fixresultsat/Users/mikesol/workshop/finos/messageml-utils/.moderne/run/20240904084031-xdbaB/fix.patch> finos/spring-bot@spring-bot-master+Fixresultsat/Users/mikesol/workshop/finos/spring-bot/.moderne/run/20240904084031-xdbaB/fix.patch> finos/symphony-bdk-java@main+Fixresultsat/Users/mikesol/workshop/finos/symphony-bdk-java/.moderne/run/20240904084031-xdbaB/fix.patch> finos/symphony-wdk@master+Fixresultsat/Users/mikesol/workshop/finos/symphony-wdk/.moderne/run/20240904084031-xdbaB/fix.patch> Netflix/ndbench@master!SkippingreciperunbecausenoLSTwasfound> Netflix/photon@master+Fixresultsat/Users/mikesol/workshop/Netflix/photon/.moderne/run/20240904084031-xdbaB/fix.patch> Netflix/ribbon@master+Fixresultsat/Users/mikesol/workshop/Netflix/ribbon/.moderne/run/20240904084031-xdbaB/fix.patch> openrewrite/rewrite-recipe-bom@mainNochanges> openrewrite/rewrite-sql@mainNochanges> spring-projects/spring-data-commons@main!SkippingreciperunbecausenoLSTwasfound> spring-projects/spring-petclinic@main + Fix results at /Users/mikesol/workshop/spring-projects/spring-petclinic/.moderne/run/20240904084031-xdbaB/fix.patch
Found change results on 9 repositories; data tables available for 11 repositories; skipped 3 repositories with no LST (1m 37s)
19m57ssavedbyusingpreviouslybuiltLSTs* What to donext>!UpdateoutofdateLSTswithmodbuild.>Clickononeofthepatchlinksabovetoviewthechangesonaparticularrepository > Run mod study . --last-recipe-run --data-table <DATA-TABLE> to examine the following data tables produced by this recipe:
org.openrewrite.table.RecipeRunStatsorg.openrewrite.table.SourcesFileResults>Runnpminstall-gdiff2html-clitoproducepatchfilesonsubsequentrunsthatareeasiertoview>Runmodgitcheckout.-bhotfix--last-recipe-runtoprepareahotfixbranchforapplyingthechanges>Runmodgitapply.--last-recipe-runtoapplythechanges>Runmodgitapply.--recipe-run20240904084031-xdbaBtoapplythechanges>Runmodlogrunsadd.logs.zip--last-runtoaggregaterunlogsMODSUCCEEDEDin (1m 37s)
Right now, if you cd to any of the repositories in the workshop directory, you won't see any of these changes. While you could apply these changes to the branches you have checked out, it's generally preferable to make changes inside of a branch and then submit a PR for said branch.
To begin, let's create a branch in each repository that has changes by running the following command:
Next, let's apply the changes from the recipe to these branches:
modgitapply.--last-recipe-run
If you cd into the project directories and run git status, you will see that you have a bunch of uncommitted and unstaged changes. Normally this would be where you would run tests and confirm that everything still works. For the purposes of the workshop, though, let's just pretend everything worked perfectly and move to the next step of staging the files and committing the changes.
To add the files to the list that should be committed, run the following command:
modgitadd.--last-recipe-run
Then, to commit these changes, run the following command:
modgitcommit.-m"Test common static analysis changes"--last-recipe-run
Right now, GPG signing is not supported by the mod git commit command. If you use GPG signing, you'll either need to disable that temporarily or manually commit the changes in each repository without using the CLI.
Normally, the next step you would do would be to push the commit to a branch and open a PR for it. However, as we don't own these repositories and as we don't want to clutter them, please refrain from running the following commands against the repositories above.
There are a variety of ways to create PRs based on your goals. We'll provide a few of the most common examples below.
You could push commits to the repositories via:
modgitpush.--last-recipe-run
Or you could create a PR directly with the GitHub command line:
modexec.--last-recipe-run--ghprcreate--title"refactor: Apply AssertJ best practices"
Differences between the Moderne CLI and the OpenRewrite build plugins
The OpenRewrite build plugins are designed to run a single recipe on a single repository at a time. When you run a recipe using these plugins, a new LST is produced regardless of whether or not the code for that repository has changed. This LST is temporarily stored in memory and used by the recipe before being discarded at the end of the recipe run. For large projects, this can be problematic as the entire LST must fit in memory for the recipe to work.
In contrast, the Moderne CLI is designed for scale. You can run recipes against multiple repositories at once and the LST does not need to fit into memory. This is because the Moderne CLI uses proprietary code to build the LST up in parts and then serializes/writes it to the disk (as part of the mod build command). Likewise, the mod run command will read this LST from the disk in pieces as it runs recipes rather than building the LST every time.
When running the Moderne CLI commands for the first time, you might notice that running a single recipe on a single repository is slower than the OpenRewrite build plugins. This is due to the fact that the OpenRewrite build plugins do not serialize the LST and write it to disk.
However, if you wanted to run more recipes against the same LST, you would see that the Moderne CLI drastically increases in speed compared to the OpenRewrite build plugins as the Moderne CLI can read the pre-built LST and execute recipes against it rather than having to build it again each time. Furthermore, if you wanted to, you could use the Moderne CLI to run a recipe against many repositories at once – which the OpenRewrite build plugins can't do.