-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: tool for comparing different ignite versions (#3718)
* Add gen-migdoc script * Fix gen-migdoc script * Add gen-mig-docs tool * Add exceptions and more test cases to migdoc * Add diff subtraction and cleanup * Minor improvements * Remove gen-migdoc bash script * Move exception files to different file * Change the diff subtraction algorithm * Clean up error handling * Add diff package * Add Subtract to diff package * Cleanup gen-mig-diffs * Fix bugs * Fix bugs * Add more test to subtract test cases * Update the subtract lines algorithm * go mod tidy * Add changelog * Fix lint errors * Fix bugs * Fix lint * make format * Fix cleanup * Update ignite/internal/tools/gen-mig-diffs/migdiff/gen.go Co-authored-by: Danilo Pantani <[email protected]> * Update ignite/internal/tools/gen-mig-diffs/migdiff/gen.go Co-authored-by: Danilo Pantani <[email protected]> * Fix lint * Use cliui instead of log package * add gen options * code clean * improve error log * reset and clean the repo before the checkout to avoid conflicts * use https for repo url * draft refactor * improve the logs * remove useless code * add pkg options * pass the context to the commands * add cache file * create Scaffold struct * fix wrong output * add the scaffold cache * fix folder search for diffs * improve the logs and comments * remove unused temp folder creation * fix binaries path * generate migration docs inside a doc template * format the markdown file * unhandled error * fix changelog * markdown breakline * add CI to generate migration docs for each release * skip diff if is empty * use script to gen mig file * fix link for the genesis file --------- Co-authored-by: Danilo Pantani <[email protected]> Co-authored-by: Danny <[email protected]> Co-authored-by: Pantani <Pantani>
- Loading branch information
1 parent
794b448
commit 0fea7ef
Showing
26 changed files
with
2,247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Generate Migration Docs | ||
on: | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
cli: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: 'stable' | ||
|
||
- name: Generate Scaffold Migration Docs | ||
run: ./scripts/gen-mig-diffs | ||
|
||
- name: Create Pull Request | ||
id: cpr | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
title: "docs(migration): update generated docs" | ||
commit-message: "docs(migration): update generated docs" | ||
body: "" | ||
branch: feat/gen-migration-docs | ||
add-paths: | | ||
docs/ | ||
- name: Check outputs | ||
run: | | ||
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" | ||
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ignite/cli/v29/ignite/pkg/cliui" | ||
"github.com/ignite/cli/v29/ignite/pkg/errors" | ||
"github.com/ignite/cli/v29/ignite/pkg/xgenny" | ||
|
||
"github.com/ignite/cli/ignite/internal/tools/gen-mig-diffs/pkg/diff" | ||
"github.com/ignite/cli/ignite/internal/tools/gen-mig-diffs/pkg/repo" | ||
"github.com/ignite/cli/ignite/internal/tools/gen-mig-diffs/pkg/scaffold" | ||
"github.com/ignite/cli/ignite/internal/tools/gen-mig-diffs/templates/doc" | ||
) | ||
|
||
const ( | ||
flagFrom = "from" | ||
flagTo = "to" | ||
flagOutput = "output" | ||
flagSource = "repo-source" | ||
flagRepoURL = "repo-url" | ||
flagRepoOutput = "repo-output" | ||
flagScaffoldOutput = "scaffold-output" | ||
flagScaffoldCache = "scaffold-cache" | ||
|
||
defaultDocPath = "docs/docs/06-migration" | ||
) | ||
|
||
// NewRootCmd creates a new root command. | ||
func NewRootCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "gen-mig-diffs", | ||
Short: "GenerateBinaries migration diffs", | ||
Long: "This tool is used to generate migration diff files for each of ignites scaffold commands", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
session := cliui.New() | ||
defer session.End() | ||
|
||
var ( | ||
from, _ = cmd.Flags().GetString(flagFrom) | ||
to, _ = cmd.Flags().GetString(flagTo) | ||
repoSource, _ = cmd.Flags().GetString(flagSource) | ||
output, _ = cmd.Flags().GetString(flagOutput) | ||
repoURL, _ = cmd.Flags().GetString(flagRepoURL) | ||
repoOutput, _ = cmd.Flags().GetString(flagRepoOutput) | ||
scaffoldOutput, _ = cmd.Flags().GetString(flagScaffoldOutput) | ||
scaffoldCache, _ = cmd.Flags().GetString(flagScaffoldCache) | ||
) | ||
fromVer, err := semver.NewVersion(from) | ||
if err != nil && from != "" { | ||
return errors.Wrapf(err, "failed to parse from version %s", from) | ||
} | ||
toVer, err := semver.NewVersion(to) | ||
if err != nil && to != "" { | ||
return errors.Wrapf(err, "failed to parse to version %s", to) | ||
} | ||
|
||
// Check or download the source and generate the binaries for each version. | ||
repoOptions := make([]repo.Options, 0) | ||
if repoSource != "" { | ||
repoOptions = append(repoOptions, repo.WithSource(repoSource)) | ||
} | ||
if repoURL != "" { | ||
repoOptions = append(repoOptions, repo.WithRepoURL(repoURL)) | ||
} | ||
if repoOutput != "" { | ||
repoOptions = append(repoOptions, repo.WithRepoOutput(repoOutput)) | ||
} | ||
|
||
igniteRepo, err := repo.New(fromVer, toVer, session, repoOptions...) | ||
if err != nil { | ||
return err | ||
} | ||
defer igniteRepo.Cleanup() | ||
|
||
releaseDescription, err := igniteRepo.ReleaseDescription() | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to fetch the release tag %s description", igniteRepo.To.Original()) | ||
} | ||
|
||
fromBin, toBin, err := igniteRepo.GenerateBinaries(cmd.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Scaffold the default commands for each version. | ||
scaffoldOptions := make([]scaffold.Options, 0) | ||
if scaffoldOutput != "" { | ||
scaffoldOptions = append(scaffoldOptions, scaffold.WithOutput(scaffoldOutput)) | ||
} | ||
if scaffoldCache != "" { | ||
scaffoldOptions = append(scaffoldOptions, scaffold.WithCachePath(scaffoldCache)) | ||
} | ||
|
||
session.StartSpinner(fmt.Sprintf("Running scaffold commands for %s...", igniteRepo.From.Original())) | ||
sFrom, err := scaffold.New(fromBin, igniteRepo.From, scaffoldOptions...) | ||
if err != nil { | ||
return err | ||
} | ||
defer sFrom.Cleanup() | ||
|
||
if err := sFrom.Run(cmd.Context()); err != nil { | ||
return err | ||
} | ||
session.StopSpinner() | ||
session.EventBus().SendInfo(fmt.Sprintf("Scaffolded code for %s at %s", igniteRepo.From.Original(), sFrom.Output)) | ||
|
||
session.StartSpinner(fmt.Sprintf("Running scaffold commands for %s...", igniteRepo.To.Original())) | ||
sTo, err := scaffold.New(toBin, igniteRepo.To, scaffoldOptions...) | ||
if err != nil { | ||
return err | ||
} | ||
defer sTo.Cleanup() | ||
|
||
if err := sTo.Run(cmd.Context()); err != nil { | ||
return err | ||
} | ||
session.StopSpinner() | ||
session.EventBus().SendInfo(fmt.Sprintf("Scaffolded code for %s at %s", igniteRepo.To.Original(), sTo.Output)) | ||
|
||
// Calculate and save the diffs from the scaffolded code. | ||
session.StartSpinner("Calculating diff...") | ||
diffs, err := diff.CalculateDiffs(sFrom.Output, sTo.Output) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to calculate diff") | ||
} | ||
|
||
formatedDiffs, err := diff.FormatDiffs(diffs) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to save diff map") | ||
} | ||
session.StopSpinner() | ||
session.EventBus().SendInfo("Diff calculated successfully") | ||
|
||
output, err = filepath.Abs(output) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to find the abs path") | ||
} | ||
|
||
// Generate the docs file. | ||
g, err := doc.NewGenerator(doc.Options{ | ||
Path: output, | ||
FromVersion: igniteRepo.From, | ||
ToVersion: igniteRepo.To, | ||
Diffs: string(formatedDiffs), | ||
Description: releaseDescription, | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to create the doc generator object") | ||
} | ||
|
||
sm, err := xgenny.NewRunner(cmd.Context(), output).RunAndApply(g) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
files := append(sm.CreatedFiles(), sm.ModifiedFiles()...) | ||
if len(files) == 0 { | ||
return errors.Errorf("migration doc not created at %s", output) | ||
} | ||
session.EventBus().SendInfo( | ||
fmt.Sprintf("Migration doc generated successfully at %s", files[0]), | ||
) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringP(flagFrom, "f", "", "Version of Ignite or path to Ignite source code to generate the diff from") | ||
cmd.Flags().StringP(flagTo, "t", "", "Version of Ignite or path to Ignite source code to generate the diff to") | ||
cmd.Flags().StringP(flagOutput, "o", defaultDocPath, "Output directory to save the migration document") | ||
cmd.Flags().StringP(flagSource, "s", "", "Path to Ignite source code repository. Set the source automatically set the cleanup to false") | ||
cmd.Flags().String(flagRepoURL, repo.DefaultRepoURL, "Git URL for the Ignite repository") | ||
cmd.Flags().String(flagRepoOutput, "", "Output path to clone the Ignite repository") | ||
cmd.Flags().String(flagScaffoldOutput, "", "Output path to clone the Ignite repository") | ||
cmd.Flags().String(flagScaffoldCache, "", "Path to cache directory") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
module github.com/ignite/cli/ignite/internal/tools/gen-mig-diffs | ||
|
||
go 1.22.2 | ||
|
||
replace github.com/ignite/cli/v29 => ../../../../ | ||
|
||
require ( | ||
github.com/Masterminds/semver/v3 v3.2.1 | ||
github.com/go-git/go-git/v5 v5.12.0 | ||
github.com/gobuffalo/genny/v2 v2.1.0 | ||
github.com/gobuffalo/plush/v4 v4.1.19 | ||
github.com/gobwas/glob v0.2.3 | ||
github.com/hexops/gotextdiff v1.0.3 | ||
github.com/ignite/cli/v29 v29.0.0-00010101000000-000000000000 | ||
github.com/spf13/cobra v1.8.0 | ||
github.com/stretchr/testify v1.9.0 | ||
) | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/AlecAivazis/survey/v2 v2.3.7 // indirect | ||
github.com/Microsoft/go-winio v0.6.1 // indirect | ||
github.com/ProtonMail/go-crypto v1.0.0 // indirect | ||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | ||
github.com/aymerick/douceur v0.2.0 // indirect | ||
github.com/briandowns/spinner v1.23.0 // indirect | ||
github.com/charmbracelet/lipgloss v0.10.0 // indirect | ||
github.com/chzyer/readline v1.5.1 // indirect | ||
github.com/cloudflare/circl v1.3.7 // indirect | ||
github.com/cockroachdb/errors v1.11.1 // indirect | ||
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect | ||
github.com/cockroachdb/redact v1.1.5 // indirect | ||
github.com/cyphar/filepath-securejoin v0.2.4 // indirect | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
github.com/emicklei/proto v1.13.2 // indirect | ||
github.com/emicklei/proto-contrib v0.16.0 // indirect | ||
github.com/emirpasic/gods v1.18.1 // indirect | ||
github.com/fatih/color v1.16.0 // indirect | ||
github.com/fatih/structs v1.1.0 // indirect | ||
github.com/getsentry/sentry-go v0.27.0 // indirect | ||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect | ||
github.com/go-git/go-billy/v5 v5.5.0 // indirect | ||
github.com/gobuffalo/flect v1.0.2 // indirect | ||
github.com/gobuffalo/github_flavored_markdown v1.1.4 // indirect | ||
github.com/gobuffalo/helpers v0.6.7 // indirect | ||
github.com/gobuffalo/logger v1.0.7 // indirect | ||
github.com/gobuffalo/packd v1.0.2 // indirect | ||
github.com/gobuffalo/tags/v3 v3.1.4 // indirect | ||
github.com/gobuffalo/validate/v3 v3.3.3 // indirect | ||
github.com/gofrs/uuid v4.4.0+incompatible // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
github.com/gorilla/css v1.0.1 // indirect | ||
github.com/iancoleman/strcase v0.3.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect | ||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect | ||
github.com/kevinburke/ssh_config v1.2.0 // indirect | ||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||
github.com/manifoldco/promptui v0.9.0 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/mattn/go-runewidth v0.0.15 // indirect | ||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect | ||
github.com/microcosm-cc/bluemonday v1.0.26 // indirect | ||
github.com/muesli/reflow v0.3.0 // indirect | ||
github.com/muesli/termenv v0.15.2 // indirect | ||
github.com/pjbgf/sha1cd v0.3.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect | ||
github.com/rivo/uniseg v0.4.7 // indirect | ||
github.com/rogpeppe/go-internal v1.12.0 // indirect | ||
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
github.com/skeema/knownhosts v1.2.2 // indirect | ||
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect | ||
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/xanzy/ssh-agent v0.3.3 // indirect | ||
golang.org/x/crypto v0.22.0 // indirect | ||
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect | ||
golang.org/x/mod v0.17.0 // indirect | ||
golang.org/x/net v0.24.0 // indirect | ||
golang.org/x/sync v0.7.0 // indirect | ||
golang.org/x/sys v0.19.0 // indirect | ||
golang.org/x/term v0.19.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/tools v0.20.0 // indirect | ||
gopkg.in/warnings.v0 v0.1.2 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.