From b61933e81c7faa3f6047889c27e457140b614202 Mon Sep 17 00:00:00 2001 From: hthieu1110 Date: Sat, 21 Sep 2024 07:14:07 +0700 Subject: [PATCH 01/35] feat: pre-register test1 user to make interaction with boards easier --- .../gno.land/r/demo/users/preregister.gno | 3 +++ .../gno.land/r/demo/users/z_13_filetest.gno | 23 +++++++++++++++++++ .../gno.land/r/demo/users/z_5_filetest.gno | 1 + 3 files changed, 27 insertions(+) create mode 100644 examples/gno.land/r/demo/users/z_13_filetest.gno diff --git a/examples/gno.land/r/demo/users/preregister.gno b/examples/gno.land/r/demo/users/preregister.gno index a6377c54938..e87bb478d4e 100644 --- a/examples/gno.land/r/demo/users/preregister.gno +++ b/examples/gno.land/r/demo/users/preregister.gno @@ -26,6 +26,9 @@ var preRegisteredUsers = []struct { {"nt", "g15ge0ae9077eh40erwrn2eq0xw6wupwqthpv34l"}, // -> @r_nt {"sys", "g1r929wt2qplfawe4lvqv9zuwfdcz4vxdun7qh8l"}, // -> @r_sys {"x", "g164sdpew3c2t3rvxj3kmfv7c7ujlvcw2punzzuz"}, // -> @r_x + + // test1 user + {"test1", "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"}, // -> @test1 } func init() { diff --git a/examples/gno.land/r/demo/users/z_13_filetest.gno b/examples/gno.land/r/demo/users/z_13_filetest.gno new file mode 100644 index 00000000000..b7f5caeffea --- /dev/null +++ b/examples/gno.land/r/demo/users/z_13_filetest.gno @@ -0,0 +1,23 @@ +package main + +// SEND: 200000000ugnot + +import ( + "strconv" + + "gno.land/r/demo/users" +) + +func main() { + { + // Verify pre-registered test1 user + names := users.ListUsersByPrefix("test1", 1) + println("# names: " + strconv.Itoa(len(names))) + println("name: " + names[0]) + } +} + +// Output: +// # names: 1 +// name: test1 + diff --git a/examples/gno.land/r/demo/users/z_5_filetest.gno b/examples/gno.land/r/demo/users/z_5_filetest.gno index 4ab68ec0e0b..31e482b7388 100644 --- a/examples/gno.land/r/demo/users/z_5_filetest.gno +++ b/examples/gno.land/r/demo/users/z_5_filetest.gno @@ -46,6 +46,7 @@ func main() { // * [nt](/r/demo/users:nt) // * [satoshi](/r/demo/users:satoshi) // * [sys](/r/demo/users:sys) +// * [test1](/r/demo/users:test1) // * [x](/r/demo/users:x) // // ======================================== From 50fa8d0db33c8a7763b00a764721ead649020b3b Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Thu, 7 Dec 2023 17:46:48 +0100 Subject: [PATCH 02/35] Add Myers algorithm implementation and Algorithm interface --- misc/stdlib_diff/algorithm.go | 20 +++++ misc/stdlib_diff/myers.go | 159 ++++++++++++++++++++++++++++++++++ misc/stdlib_diff/operation.go | 28 ++++++ 3 files changed, 207 insertions(+) create mode 100644 misc/stdlib_diff/algorithm.go create mode 100644 misc/stdlib_diff/myers.go create mode 100644 misc/stdlib_diff/operation.go diff --git a/misc/stdlib_diff/algorithm.go b/misc/stdlib_diff/algorithm.go new file mode 100644 index 00000000000..259af7187dd --- /dev/null +++ b/misc/stdlib_diff/algorithm.go @@ -0,0 +1,20 @@ +package main + +import "errors" + +const ( + MYERS = "myers" +) + +type Algorithm interface { + Do() (srcDiff []LineDifferrence, dstDiff []LineDifferrence) +} + +func AlgorithmFactory(src, dst []string, algoType string) (Algorithm, error) { + switch algoType { + case MYERS: + return NewMyers(src, dst), nil + default: + return nil, errors.New("unknown algorithm type") + } +} diff --git a/misc/stdlib_diff/myers.go b/misc/stdlib_diff/myers.go new file mode 100644 index 00000000000..126484c8365 --- /dev/null +++ b/misc/stdlib_diff/myers.go @@ -0,0 +1,159 @@ +package main + +import ( + "slices" +) + +var _ Algorithm = (*Myers)(nil) + +// Myers is a struct representing the Myers algorithm for line-based difference. +type Myers struct { + src []string // Lines of the source file. + dst []string // Lines of the destination file. +} + +// NewMyers creates a new Myers instance with the specified source and destination lines. +func NewMyers(src, dst []string) *Myers { + return &Myers{ + src: src, + dst: dst, + } +} + +// Do performs the Myers algorithm to find the differences between source and destination files. +// It returns the differences as two slices of LineDifferrence representing source and destination changes. +func (m *Myers) Do() ([]LineDifferrence, []LineDifferrence) { + operations := m.doMyers() + + srcIndex, dstIndex := 0, 0 + dstDiff := make([]LineDifferrence, 0) + srcDiff := make([]LineDifferrence, 0) + insertCount := 0 + for _, op := range operations { + switch op { + case INSERT: + dstDiff = append(dstDiff, LineDifferrence{Line: "+" + m.dst[dstIndex], Operation: op.String()}) + srcDiff = append(srcDiff, LineDifferrence{Line: "", Operation: MOVE.String()}) + dstIndex += 1 + insertCount++ + continue + + case MOVE: + dstDiff = append(dstDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op.String()}) + srcDiff = append(srcDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op.String()}) + srcIndex += 1 + dstIndex += 1 + continue + + case DELETE: + dstDiff = append(dstDiff, LineDifferrence{Line: "", Operation: MOVE.String()}) + srcDiff = append(srcDiff, LineDifferrence{Line: "-" + m.src[srcIndex], Operation: op.String()}) + srcIndex += 1 + continue + } + } + + // Means that src file is empty. + if insertCount == len(srcDiff) { + srcDiff = make([]LineDifferrence, 0) + } + return srcDiff, dstDiff +} + +// doMyers performs the Myers algorithm and returns the list of operations. +func (m *Myers) doMyers() []operation { + var tree []map[int]int + var x, y int + + srcLen := len(m.src) + dstLen := len(m.dst) + max := srcLen + dstLen + + for pathLen := 0; pathLen <= max; pathLen++ { + optimalCoordinates := make(map[int]int, pathLen+2) + tree = append(tree, optimalCoordinates) + + if pathLen == 0 { + commonPrefixLen := 0 + for srcLen > commonPrefixLen && dstLen > commonPrefixLen && m.src[commonPrefixLen] == m.dst[commonPrefixLen] { + commonPrefixLen++ + } + optimalCoordinates[0] = commonPrefixLen + + if commonPrefixLen == srcLen && commonPrefixLen == dstLen { + return m.getAllOperations(tree) + } + continue + } + + lastV := tree[pathLen-1] + + for k := -pathLen; k <= pathLen; k += 2 { + if k == -pathLen || (k != pathLen && lastV[k-1] < lastV[k+1]) { + x = lastV[k+1] + } else { + x = lastV[k-1] + 1 + } + + y = x - k + + for x < srcLen && y < dstLen && m.src[x] == m.dst[y] { + x, y = x+1, y+1 + } + + optimalCoordinates[k] = x + + if x == srcLen && y == dstLen { + return m.getAllOperations(tree) + } + } + } + + return m.getAllOperations(tree) +} + +// getAllOperations retrieves the list of operations from the calculated tree. +func (m *Myers) getAllOperations(tree []map[int]int) []operation { + var operations []operation + var k, prevK, prevX, prevY int + + x := len(m.src) + y := len(m.dst) + + for pathLen := len(tree) - 1; pathLen > 0; pathLen-- { + k = x - y + lastV := tree[pathLen-1] + + if k == -pathLen || (k != pathLen && lastV[k-1] < lastV[k+1]) { + prevK = k + 1 + } else { + prevK = k - 1 + } + + prevX = lastV[prevK] + prevY = prevX - prevK + + for x > prevX && y > prevY { + operations = append(operations, MOVE) + x -= 1 + y -= 1 + } + + if x == prevX { + operations = append(operations, INSERT) + } else { + operations = append(operations, DELETE) + } + + x, y = prevX, prevY + } + + if tree[0][0] != 0 { + for i := 0; i < tree[0][0]; i++ { + operations = append(operations, MOVE) + } + } + + slices.Reverse(operations) + return operations +} diff --git a/misc/stdlib_diff/operation.go b/misc/stdlib_diff/operation.go new file mode 100644 index 00000000000..926e64b1a39 --- /dev/null +++ b/misc/stdlib_diff/operation.go @@ -0,0 +1,28 @@ +package main + +// operation is an enumeration type representing different types of operations. Used in diff algorithm +// to indicates differences between files. +type operation uint + +const ( + // INSERT represents an insertion operation. + INSERT operation = 1 + // DELETE represents a deletion operation. + DELETE operation = 2 + // MOVE represents a move operation. + MOVE operation = 3 +) + +// String returns a string representation of the operation. +func (op operation) String() string { + switch op { + case INSERT: + return "INS" + case DELETE: + return "DEL" + case MOVE: + return "MOV" + default: + return "UNKNOWN" + } +} From aa3b468c6fa9c6c3dc3bc904694e5c99730caea9 Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Thu, 7 Dec 2023 17:48:32 +0100 Subject: [PATCH 03/35] Add objects to handle packages comparison --- misc/stdlib_diff/diffstatus.go | 25 +++++ misc/stdlib_diff/filediff.go | 67 +++++++++++++ misc/stdlib_diff/packagediff.go | 164 ++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 misc/stdlib_diff/diffstatus.go create mode 100644 misc/stdlib_diff/filediff.go create mode 100644 misc/stdlib_diff/packagediff.go diff --git a/misc/stdlib_diff/diffstatus.go b/misc/stdlib_diff/diffstatus.go new file mode 100644 index 00000000000..df39016891f --- /dev/null +++ b/misc/stdlib_diff/diffstatus.go @@ -0,0 +1,25 @@ +package main + +type diffStatus uint + +const ( + MISSING_IN_SRC diffStatus = 1 + MISSING_IN_DST diffStatus = 2 + HAS_DIFF diffStatus = 3 + NO_DIFF diffStatus = 4 +) + +func (status diffStatus) String() string { + switch status { + case MISSING_IN_SRC: + return "missing in src" + case MISSING_IN_DST: + return "missing in dst" + case HAS_DIFF: + return "files differ" + case NO_DIFF: + return "files are equal" + default: + return "Unknown" + } +} diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go new file mode 100644 index 00000000000..d2330e042f4 --- /dev/null +++ b/misc/stdlib_diff/filediff.go @@ -0,0 +1,67 @@ +package main + +import ( + "bufio" + "os" +) + +// FileDiff is a struct for comparing differences between two files. +type FileDiff struct { + Src []string // Lines of the source file. + Dst []string // Lines of the destination file. + DiffAlgorithm Algorithm // Algorithm used for comparison. +} + +// LineDifferrence represents a difference in a line during file comparison. +type LineDifferrence struct { + Line string // The line content. + Operation string // The operation performed on the line (e.g., "add", "delete", "equal"). +} + +// NewFileDiff creates a new FileDiff instance for comparing differences between +// the specified source and destination files. It initializes the source and +// destination file lines and the specified diff algorithm. +func NewFileDiff(srcPath, dstPath, algoType string) (*FileDiff, error) { + src := getFileLines(srcPath) + dst := getFileLines(dstPath) + + diffAlgorithm, err := AlgorithmFactory(src, dst, algoType) + if err != nil { + return nil, err + } + + return &FileDiff{ + Src: src, + Dst: dst, + DiffAlgorithm: diffAlgorithm, + }, nil +} + +// Differences returns the differences in lines between the source and +// destination files using the configured diff algorithm. +func (f *FileDiff) Differences() ([]LineDifferrence, []LineDifferrence) { + srcDiff, dstDiff := f.DiffAlgorithm.Do() + return srcDiff, dstDiff +} + +// getFileLines reads and returns the lines of a file given its path. +func getFileLines(p string) []string { + lines := make([]string, 0) + + f, err := os.Open(p) + if err != nil { + return lines + } + defer f.Close() + + scanner := bufio.NewScanner(f) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + + if err := scanner.Err(); err != nil { + return lines + } + + return lines +} diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go new file mode 100644 index 00000000000..d97a1f4b9a3 --- /dev/null +++ b/misc/stdlib_diff/packagediff.go @@ -0,0 +1,164 @@ +package main + +import ( + "fmt" + "os" + "slices" + "strings" +) + +// PackageDiffChecker is a struct for comparing and identifying differences +// between files in two directories. +type PackageDiffChecker struct { + SrcFiles []string // List of source files. + SrcPath string // Source directory path. + DstFiles []string // List of destination files. + DstPath string // Destination directory path. +} + +// Differences represents the differences between source and destination packages. +type Differences struct { + SameNumberOfFiles bool // Indicates whether the source and destination have the same number of files. + FilesDifferences []FileDifference // Differences in individual files. +} + +// FileDifference represents the differences between source and destination files. +type FileDifference struct { + Status string // Diff status of the processed files. + SourceName string // Name of the source file. + DestinationName string // Name of the destination file. + SrcLineDiff []LineDifferrence // Differences in source file lines. + DstLineDiff []LineDifferrence // Differences in destination file lines. +} + +// NewPackageDiffChecker creates a new PackageDiffChecker instance with the specified +// source and destination paths. It initializes the SrcFiles and DstFiles fields by +// listing files in the corresponding directories. +func NewPackageDiffChecker(srcPath, dstPath string) (*PackageDiffChecker, error) { + srcFiles, err := listDirFiles(srcPath) + if err != nil { + return nil, err + } + + dstFiles, err := listDirFiles(dstPath) + if err != nil { + return nil, err + } + + return &PackageDiffChecker{ + SrcFiles: srcFiles, + SrcPath: srcPath, + DstFiles: dstFiles, + DstPath: dstPath, + }, nil +} + +// Differences calculates and returns the differences between source and destination +// packages. It compares files line by line using the Myers algorithm. +func (p *PackageDiffChecker) Differences() (*Differences, error) { + d := &Differences{ + SameNumberOfFiles: p.hasSameNumberOfFiles(), + FilesDifferences: make([]FileDifference, 0), + } + + allFiles := p.listAllPossibleFiles() + + for _, trimmedFileName := range allFiles { + srcFilePath := p.SrcPath + "/" + trimmedFileName + ".gno" + dstFilePath := p.DstPath + "/" + trimmedFileName + ".go" + + fileDiff, err := NewFileDiff(srcFilePath, dstFilePath, "myers") + if err != nil { + return nil, err + } + + srcDiff, dstDiff := fileDiff.Differences() + + d.FilesDifferences = append(d.FilesDifferences, FileDifference{ + Status: p.getStatus(srcDiff, dstDiff).String(), + SourceName: trimmedFileName + ".gno", + DestinationName: trimmedFileName + ".go", + SrcLineDiff: srcDiff, + DstLineDiff: dstDiff, + }) + } + + return d, nil +} + +// listAllPossibleFiles returns a list of unique file names without extensions +// from both source and destination directories. +func (p *PackageDiffChecker) listAllPossibleFiles() []string { + files := p.SrcFiles + files = append(files, p.DstFiles...) + + for i := 0; i < len(files); i++ { + files[i] = strings.TrimSuffix(files[i], ".go") + files[i] = strings.TrimSuffix(files[i], ".gno") + } + + unique := make(map[string]bool, len(files)) + uniqueFiles := make([]string, len(unique)) + for _, file := range files { + if len(file) != 0 { + if !unique[file] { + uniqueFiles = append(uniqueFiles, file) + unique[file] = true + } + } + } + + return uniqueFiles +} + +func (p *PackageDiffChecker) getStatus(srcDiff, dstDiff []LineDifferrence) diffStatus { + slicesAreEquals := slices.Equal(srcDiff, dstDiff) + if slicesAreEquals { + return NO_DIFF + } + + if len(srcDiff) == 0 { + return MISSING_IN_SRC + } + + if len(dstDiff) == 0 { + return MISSING_IN_DST + } + + if !slicesAreEquals { + return HAS_DIFF + } + + return 0 +} + +// listDirFiles returns a list of file names in the specified directory. +func listDirFiles(dirPath string) ([]string, error) { + f, err := os.Open(dirPath) + if err != nil { + return []string{}, nil + } + + defer func() { + if err := f.Close(); err != nil { + fmt.Fprintln(os.Stderr, "can't close "+dirPath) + } + }() + + filesInfo, err := f.Readdir(0) + if err != nil { + return nil, fmt.Errorf("can't list file in directory :%w", err) + } + + fileNames := make([]string, 0) + for _, info := range filesInfo { + fileNames = append(fileNames, info.Name()) + } + + return fileNames, nil +} + +// hasSameNumberOfFiles checks if the source and destination have the same number of files. +func (p *PackageDiffChecker) hasSameNumberOfFiles() bool { + return len(p.SrcFiles) == len(p.DstFiles) +} From df26bbf1edafadc0463f31cfb05c9a43f34736ac Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Thu, 7 Dec 2023 17:49:10 +0100 Subject: [PATCH 04/35] Add report generation --- misc/stdlib_diff/main.go | 28 +++ misc/stdlib_diff/report.go | 165 ++++++++++++++++++ .../stdlib_diff/templates/index_template.html | 53 ++++++ .../templates/package_diff_template.html | 98 +++++++++++ 4 files changed, 344 insertions(+) create mode 100644 misc/stdlib_diff/main.go create mode 100644 misc/stdlib_diff/report.go create mode 100644 misc/stdlib_diff/templates/index_template.html create mode 100644 misc/stdlib_diff/templates/package_diff_template.html diff --git a/misc/stdlib_diff/main.go b/misc/stdlib_diff/main.go new file mode 100644 index 00000000000..5f06577eaff --- /dev/null +++ b/misc/stdlib_diff/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "flag" + "log" +) + +func main() { + var srcPath string + var dstPath string + var outDirectory string + + flag.StringVar(&srcPath, "src", "", "Path to Gnoland standard libraries directory") + flag.StringVar(&dstPath, "dst", "", "Path to Goland standard libraries directory") + flag.StringVar(&outDirectory, "out", "", "Path to the directory where the report will be generated") + flag.Parse() + + reportBuilder, err := NewReportBuilder(srcPath, dstPath, outDirectory) + if err != nil { + log.Fatal("can't build report builder: ", err.Error()) + } + + log.Println("Building report...") + if err := reportBuilder.Build(); err != nil { + log.Fatalln("can't build report: ", err.Error()) + } + log.Println("Report generation done!") +} diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go new file mode 100644 index 00000000000..5b7328c2b5c --- /dev/null +++ b/misc/stdlib_diff/report.go @@ -0,0 +1,165 @@ +package main + +import ( + "bytes" + "fmt" + "html/template" + "os" +) + +// ReportBuilder is a struct for building reports based on the differences +// between source and destination directories. +type ReportBuilder struct { + SrcPath string // Source directory path. + DstPath string // Destination directory path. + OutDir string // Output directory path for the reports. + packageTemplate *template.Template // Template for generating reports. + indexTemplate *template.Template // Template for generating index file of the reports. +} + +// PackageDiffTemplateData represents the template data structure for a package's +// differences between source and destination directories. +type PackageDiffTemplateData struct { + PackageName string // Package name. + GnoFileCount int // Number of Gno files in the package. + GnoPackageLocation string // Location of Gno files in the source directory. + GoFileCount int // Number of Go files in the package. + GoPackageLocation string // Location of Go files in the destination directory. + FilesDifferences []FileDifference // Differences in individual files. +} + +type IndexTemplate struct { + Reports []LinkToReport +} + +type LinkToReport struct { + PathToReport string + PackageName string +} + +// NewReportBuilder creates a new ReportBuilder instance with the specified +// source path, destination path, and output directory. It also initializes +// the packageTemplate using the provided HTML template file. +func NewReportBuilder(srcPath, dstPath, outDir string) (*ReportBuilder, error) { + packageTemplate, err := template.ParseFiles("templates/package_diff_template.html") + if err != nil { + return nil, err + } + + indexTemplate, err := template.ParseFiles("templates/index_template.html") + if err != nil { + return nil, err + } + + return &ReportBuilder{ + SrcPath: srcPath, + DstPath: dstPath, + OutDir: outDir, + packageTemplate: packageTemplate, + indexTemplate: indexTemplate, + }, nil +} + +// Build generates reports for differences between packages in the source and +// destination directories. It iterates through each directory, calculates +// differences using PackageDiffChecker, and generates reports using the +// packageTemplate. +func (builder *ReportBuilder) Build() error { + directories, err := builder.listSrcDirectories() + if err != nil { + return err + } + + indexTemplateData := &IndexTemplate{ + Reports: make([]LinkToReport, 0), + } + + for _, directory := range directories { + srcPackagePath := builder.SrcPath + "/" + directory + dstPackagePath := builder.DstPath + "/" + directory + + packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath) + if err != nil { + return fmt.Errorf("can't create new PackageDiffChecker: %w", err) + } + + differences, err := packageChecker.Differences() + if err != nil { + return fmt.Errorf("can't compute differences: %w", err) + } + + data := &PackageDiffTemplateData{ + PackageName: directory, + GnoFileCount: len(packageChecker.SrcFiles), + GnoPackageLocation: srcPackagePath, + GoFileCount: len(packageChecker.DstFiles), + GoPackageLocation: dstPackagePath, + FilesDifferences: differences.FilesDifferences, + } + + if err := builder.writePackageTemplate(data, directory); err != nil { + return err + } + + indexTemplateData.Reports = append(indexTemplateData.Reports, LinkToReport{ + PathToReport: "./" + directory + "/report.html", + PackageName: directory, + }) + } + + if err := builder.writeIndexTemplate(indexTemplateData); err != nil { + return err + } + + return nil +} + +// listSrcDirectories retrieves a list of directories in the source path. +func (builder *ReportBuilder) listSrcDirectories() ([]string, error) { + dirEntries, err := os.ReadDir(builder.SrcPath) + if err != nil { + return nil, err + } + + directories := make([]string, 0) + for _, dirEntry := range dirEntries { + if dirEntry.IsDir() { + directories = append(directories, dirEntry.Name()) + } + } + + return directories, nil +} + +// writeIndexTemplate generates and writes the index template with the given output paths. +func (builder *ReportBuilder) writeIndexTemplate(data *IndexTemplate) error { + resolvedTemplate := new(bytes.Buffer) + if err := builder.indexTemplate.Execute(resolvedTemplate, data); err != nil { + return err + } + + if err := os.WriteFile(builder.OutDir+"/index.html", resolvedTemplate.Bytes(), 0644); err != nil { + return err + } + + return nil +} + +// writePackageTemplate executes the template with the provided data and +// writes the generated report to the output directory. +func (builder *ReportBuilder) writePackageTemplate(templateData any, packageName string) error { + resolvedTemplate := new(bytes.Buffer) + if err := builder.packageTemplate.Execute(resolvedTemplate, templateData); err != nil { + return err + } + + if err := os.MkdirAll(builder.OutDir+"/"+packageName, 0777); err != nil { + return err + } + + if err := os.WriteFile(builder.OutDir+"/"+packageName+"/report.html", resolvedTemplate.Bytes(), 0644); err != nil { + return err + } + + return nil +} diff --git a/misc/stdlib_diff/templates/index_template.html b/misc/stdlib_diff/templates/index_template.html new file mode 100644 index 00000000000..5ad98f29d3b --- /dev/null +++ b/misc/stdlib_diff/templates/index_template.html @@ -0,0 +1,53 @@ + + + + + + Index + + + +

List of packages processed

+ + + \ No newline at end of file diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html new file mode 100644 index 00000000000..45c966fbb86 --- /dev/null +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -0,0 +1,98 @@ +{{define "file-viewer" }} +
+ {{- range .}} + {{- if eq .Operation "INS"}} +

{{.Line}}

+ {{- else if eq .Operation "DEL"}} +

{{.Line}}

+ {{- else}} + {{- if eq .Line ""}} +
+ {{- else}} +

{{.Line}}

+ {{- end}} + {{- end}} + {{- end}} +
+{{end}} + + + + + + + {{ .PackageName }} + + + + +

{{ .PackageName }} package differences

+ +

Package information

+ +

Sources location

+
    +
  • SRC: {{.GnoPackageLocation}}
  • +
  • DST: {{.GoPackageLocation}}
  • +
+ +

Number of files

+
    +
  • SRC: {{.GnoFileCount}}
  • +
  • DST: {{.GoFileCount}}
  • +
+ + {{- range .FilesDifferences}} +
+ {{.SourceName}} ({{.Status}}) +
+
+

{{.SourceName}}

+ {{template "file-viewer" .SrcLineDiff}} +
+ +
+

{{.DestinationName}}

+ {{template "file-viewer" .DstLineDiff}} +
+
+
+ {{- end}} + + \ No newline at end of file From dadbdf4ce7bc54b16cfd854b8a8252d9b1fa0d3a Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Thu, 7 Dec 2023 17:49:20 +0100 Subject: [PATCH 05/35] Add README.md --- misc/stdlib_diff/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 misc/stdlib_diff/README.md diff --git a/misc/stdlib_diff/README.md b/misc/stdlib_diff/README.md new file mode 100644 index 00000000000..2b41afff9eb --- /dev/null +++ b/misc/stdlib_diff/README.md @@ -0,0 +1,10 @@ +# Stdlibs_diff + +Stdlibs_diff is a tool that generates an html report indicating differences between gno standard libraries and go standrad libraries + +## Usage + +```shell +./stdlibs_diff --src --dst --out +``` + From 0d7850e59774475383a68d7b6b3935b3a79f6417 Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 8 Dec 2023 10:01:38 +0100 Subject: [PATCH 06/35] Indentation is now preserved in file preview --- misc/stdlib_diff/templates/package_diff_template.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index 45c966fbb86..d64c47fdce9 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -36,9 +36,11 @@ letter-spacing: .08rem } p { + white-space-collapse: preserve; margin: 0; font-size: 1rem; font-weight: 400; + tab-size: 4; } .file-container { From adb947840e11aa244f4d1e944d5ba5232c8d1d5c Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 8 Dec 2023 10:20:23 +0100 Subject: [PATCH 07/35] Reorganize functions order --- misc/stdlib_diff/packagediff.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index d97a1f4b9a3..d9242074b83 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -132,6 +132,11 @@ func (p *PackageDiffChecker) getStatus(srcDiff, dstDiff []LineDifferrence) diffS return 0 } +// hasSameNumberOfFiles checks if the source and destination have the same number of files. +func (p *PackageDiffChecker) hasSameNumberOfFiles() bool { + return len(p.SrcFiles) == len(p.DstFiles) +} + // listDirFiles returns a list of file names in the specified directory. func listDirFiles(dirPath string) ([]string, error) { f, err := os.Open(dirPath) @@ -157,8 +162,3 @@ func listDirFiles(dirPath string) ([]string, error) { return fileNames, nil } - -// hasSameNumberOfFiles checks if the source and destination have the same number of files. -func (p *PackageDiffChecker) hasSameNumberOfFiles() bool { - return len(p.SrcFiles) == len(p.DstFiles) -} From eb55d62fe7b8b18bb2da56abc89cec2603da659b Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 8 Dec 2023 11:00:15 +0100 Subject: [PATCH 08/35] Add missing check on delete count --- misc/stdlib_diff/myers.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/misc/stdlib_diff/myers.go b/misc/stdlib_diff/myers.go index 126484c8365..56464c228a2 100644 --- a/misc/stdlib_diff/myers.go +++ b/misc/stdlib_diff/myers.go @@ -25,10 +25,9 @@ func NewMyers(src, dst []string) *Myers { func (m *Myers) Do() ([]LineDifferrence, []LineDifferrence) { operations := m.doMyers() - srcIndex, dstIndex := 0, 0 + srcIndex, dstIndex, insertCount, deleteCount := 0, 0, 0, 0 dstDiff := make([]LineDifferrence, 0) srcDiff := make([]LineDifferrence, 0) - insertCount := 0 for _, op := range operations { switch op { case INSERT: @@ -49,6 +48,7 @@ func (m *Myers) Do() ([]LineDifferrence, []LineDifferrence) { dstDiff = append(dstDiff, LineDifferrence{Line: "", Operation: MOVE.String()}) srcDiff = append(srcDiff, LineDifferrence{Line: "-" + m.src[srcIndex], Operation: op.String()}) srcIndex += 1 + deleteCount++ continue } } @@ -57,6 +57,10 @@ func (m *Myers) Do() ([]LineDifferrence, []LineDifferrence) { if insertCount == len(srcDiff) { srcDiff = make([]LineDifferrence, 0) } + // Means that dst file is empty. + if deleteCount == len(dstDiff) { + dstDiff = make([]LineDifferrence, 0) + } return srcDiff, dstDiff } From 89dc533871bf4916224cffd3c5c0ac1b3c03aa96 Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 8 Dec 2023 11:01:32 +0100 Subject: [PATCH 09/35] Add --src_is_gno flag to indicates which one of the source or destination is the standard gno library --- misc/stdlib_diff/main.go | 4 +++- misc/stdlib_diff/packagediff.go | 23 ++++++++++++++++++----- misc/stdlib_diff/report.go | 6 ++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/misc/stdlib_diff/main.go b/misc/stdlib_diff/main.go index 5f06577eaff..3b4300aa474 100644 --- a/misc/stdlib_diff/main.go +++ b/misc/stdlib_diff/main.go @@ -9,13 +9,15 @@ func main() { var srcPath string var dstPath string var outDirectory string + var srcIsGno bool flag.StringVar(&srcPath, "src", "", "Path to Gnoland standard libraries directory") flag.StringVar(&dstPath, "dst", "", "Path to Goland standard libraries directory") flag.StringVar(&outDirectory, "out", "", "Path to the directory where the report will be generated") + flag.BoolVar(&srcIsGno, "src_is_gno", false, "If true, indicates that the src parameter correponds to the gno standard libraries") flag.Parse() - reportBuilder, err := NewReportBuilder(srcPath, dstPath, outDirectory) + reportBuilder, err := NewReportBuilder(srcPath, dstPath, outDirectory, srcIsGno) if err != nil { log.Fatal("can't build report builder: ", err.Error()) } diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index d9242074b83..2d326a44a84 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -14,6 +14,7 @@ type PackageDiffChecker struct { SrcPath string // Source directory path. DstFiles []string // List of destination files. DstPath string // Destination directory path. + SrcIsGno bool // Indicates if the SrcFiles are gno files. } // Differences represents the differences between source and destination packages. @@ -34,7 +35,7 @@ type FileDifference struct { // NewPackageDiffChecker creates a new PackageDiffChecker instance with the specified // source and destination paths. It initializes the SrcFiles and DstFiles fields by // listing files in the corresponding directories. -func NewPackageDiffChecker(srcPath, dstPath string) (*PackageDiffChecker, error) { +func NewPackageDiffChecker(srcPath, dstPath string, srcIsGno bool) (*PackageDiffChecker, error) { srcFiles, err := listDirFiles(srcPath) if err != nil { return nil, err @@ -50,6 +51,7 @@ func NewPackageDiffChecker(srcPath, dstPath string) (*PackageDiffChecker, error) SrcPath: srcPath, DstFiles: dstFiles, DstPath: dstPath, + SrcIsGno: srcIsGno, }, nil } @@ -61,11 +63,14 @@ func (p *PackageDiffChecker) Differences() (*Differences, error) { FilesDifferences: make([]FileDifference, 0), } + srcFilesExt, dstFileExt := p.inferFileExtensions() allFiles := p.listAllPossibleFiles() for _, trimmedFileName := range allFiles { - srcFilePath := p.SrcPath + "/" + trimmedFileName + ".gno" - dstFilePath := p.DstPath + "/" + trimmedFileName + ".go" + srcFileName := trimmedFileName + srcFilesExt + srcFilePath := p.SrcPath + "/" + srcFileName + dstFileName := trimmedFileName + dstFileExt + dstFilePath := p.DstPath + "/" + dstFileName fileDiff, err := NewFileDiff(srcFilePath, dstFilePath, "myers") if err != nil { @@ -76,8 +81,8 @@ func (p *PackageDiffChecker) Differences() (*Differences, error) { d.FilesDifferences = append(d.FilesDifferences, FileDifference{ Status: p.getStatus(srcDiff, dstDiff).String(), - SourceName: trimmedFileName + ".gno", - DestinationName: trimmedFileName + ".go", + SourceName: srcFileName, + DestinationName: dstFileName, SrcLineDiff: srcDiff, DstLineDiff: dstDiff, }) @@ -111,6 +116,14 @@ func (p *PackageDiffChecker) listAllPossibleFiles() []string { return uniqueFiles } +func (p *PackageDiffChecker) inferFileExtensions() (string, string) { + if p.SrcIsGno { + return ".gno", ".go" + } + + return ".go", ".gno" +} + func (p *PackageDiffChecker) getStatus(srcDiff, dstDiff []LineDifferrence) diffStatus { slicesAreEquals := slices.Equal(srcDiff, dstDiff) if slicesAreEquals { diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index 5b7328c2b5c..ea29299c628 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -13,6 +13,7 @@ type ReportBuilder struct { SrcPath string // Source directory path. DstPath string // Destination directory path. OutDir string // Output directory path for the reports. + SrcIsGno bool // Indicates if the Src files are gno files. packageTemplate *template.Template // Template for generating reports. indexTemplate *template.Template // Template for generating index file of the reports. } @@ -40,7 +41,7 @@ type LinkToReport struct { // NewReportBuilder creates a new ReportBuilder instance with the specified // source path, destination path, and output directory. It also initializes // the packageTemplate using the provided HTML template file. -func NewReportBuilder(srcPath, dstPath, outDir string) (*ReportBuilder, error) { +func NewReportBuilder(srcPath, dstPath, outDir string, srcIsGno bool) (*ReportBuilder, error) { packageTemplate, err := template.ParseFiles("templates/package_diff_template.html") if err != nil { return nil, err @@ -55,6 +56,7 @@ func NewReportBuilder(srcPath, dstPath, outDir string) (*ReportBuilder, error) { SrcPath: srcPath, DstPath: dstPath, OutDir: outDir, + SrcIsGno: srcIsGno, packageTemplate: packageTemplate, indexTemplate: indexTemplate, }, nil @@ -78,7 +80,7 @@ func (builder *ReportBuilder) Build() error { srcPackagePath := builder.SrcPath + "/" + directory dstPackagePath := builder.DstPath + "/" + directory - packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath) + packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath, builder.SrcIsGno) if err != nil { return fmt.Errorf("can't create new PackageDiffChecker: %w", err) } From a4ec9ca8b04ca527e9a2638294c1c6a43ac67b4a Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 8 Dec 2023 11:06:07 +0100 Subject: [PATCH 10/35] Rename template variables --- misc/stdlib_diff/report.go | 16 ++++++++-------- .../templates/package_diff_template.html | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index ea29299c628..76384237ce2 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -22,10 +22,10 @@ type ReportBuilder struct { // differences between source and destination directories. type PackageDiffTemplateData struct { PackageName string // Package name. - GnoFileCount int // Number of Gno files in the package. - GnoPackageLocation string // Location of Gno files in the source directory. - GoFileCount int // Number of Go files in the package. - GoPackageLocation string // Location of Go files in the destination directory. + SrcFilesCount int // Number of files in the source package. + SrcPackageLocation string // Location of source files in the source directory. + DstFileCount int // Number of destination files in the package. + DstPackageLocation string // Location of destination files in the destination directory. FilesDifferences []FileDifference // Differences in individual files. } @@ -92,10 +92,10 @@ func (builder *ReportBuilder) Build() error { data := &PackageDiffTemplateData{ PackageName: directory, - GnoFileCount: len(packageChecker.SrcFiles), - GnoPackageLocation: srcPackagePath, - GoFileCount: len(packageChecker.DstFiles), - GoPackageLocation: dstPackagePath, + SrcFilesCount: len(packageChecker.SrcFiles), + SrcPackageLocation: srcPackagePath, + DstFileCount: len(packageChecker.DstFiles), + DstPackageLocation: dstPackagePath, FilesDifferences: differences.FilesDifferences, } diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index d64c47fdce9..83174a60a69 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -70,14 +70,14 @@

Package information

Sources location

    -
  • SRC: {{.GnoPackageLocation}}
  • -
  • DST: {{.GoPackageLocation}}
  • +
  • SRC: {{.SrcPackageLocation}}
  • +
  • DST: {{.DstPackageLocation}}

Number of files

    -
  • SRC: {{.GnoFileCount}}
  • -
  • DST: {{.GoFileCount}}
  • +
  • SRC: {{.SrcFilesCount}}
  • +
  • DST: {{.DstFileCount}}
{{- range .FilesDifferences}} From f56696b34c13695e9c4eb36d96f8fee2e54b213e Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 8 Dec 2023 11:08:57 +0100 Subject: [PATCH 11/35] Add code comment --- misc/stdlib_diff/packagediff.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index 2d326a44a84..37f1a690bd8 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -116,6 +116,7 @@ func (p *PackageDiffChecker) listAllPossibleFiles() []string { return uniqueFiles } +// inferFileExtensions by returning the src and dst files extensions. func (p *PackageDiffChecker) inferFileExtensions() (string, string) { if p.SrcIsGno { return ".gno", ".go" @@ -124,6 +125,8 @@ func (p *PackageDiffChecker) inferFileExtensions() (string, string) { return ".go", ".gno" } +// getStatus determines the diff status based on the differences in source and destination. +// It returns a diffStatus indicating whether there is no difference, missing in source, missing in destination, or differences exist. func (p *PackageDiffChecker) getStatus(srcDiff, dstDiff []LineDifferrence) diffStatus { slicesAreEquals := slices.Equal(srcDiff, dstDiff) if slicesAreEquals { From 193e2dfe85eafbddde52345bc5ff6d8b107eedad Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 8 Dec 2023 11:17:51 +0100 Subject: [PATCH 12/35] Update README.md --- misc/stdlib_diff/README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/misc/stdlib_diff/README.md b/misc/stdlib_diff/README.md index 2b41afff9eb..3ed9c70bfcb 100644 --- a/misc/stdlib_diff/README.md +++ b/misc/stdlib_diff/README.md @@ -4,7 +4,28 @@ Stdlibs_diff is a tool that generates an html report indicating differences betw ## Usage +Compare the `go` standard libraries the `gno` standard libraries + +```shell +./stdlibs_diff --src --dst --out +``` + +Compare the `gno` standard libraries the `go` standard libraries + ```shell -./stdlibs_diff --src --dst --out +./stdlibs_diff --src --dst --out --src_is_gno ``` + +## Parameters + +| Flag | Description | Default value | +| ---------- | ------------------------------------------------------------------ | ------------- | +| src | Directory containing packages that will be compared to destination | None | +| dst | Directory containing packages; used to compare src packages | None | +| out | Directory where the report will be created | None | +| src_is_gno | Indicates if the src parameters is the gno standard library | false | + +## Tips + +An index.html is generated at the root of the report location. Utilize it to navigate easily through the report. \ No newline at end of file From 16e54a3852c78d0cce73a63c0d993e57fe7c69fc Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 8 Dec 2023 11:18:53 +0100 Subject: [PATCH 13/35] Update flag usage --- misc/stdlib_diff/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/misc/stdlib_diff/main.go b/misc/stdlib_diff/main.go index 3b4300aa474..fd95ecd5a17 100644 --- a/misc/stdlib_diff/main.go +++ b/misc/stdlib_diff/main.go @@ -11,10 +11,10 @@ func main() { var outDirectory string var srcIsGno bool - flag.StringVar(&srcPath, "src", "", "Path to Gnoland standard libraries directory") - flag.StringVar(&dstPath, "dst", "", "Path to Goland standard libraries directory") - flag.StringVar(&outDirectory, "out", "", "Path to the directory where the report will be generated") - flag.BoolVar(&srcIsGno, "src_is_gno", false, "If true, indicates that the src parameter correponds to the gno standard libraries") + flag.StringVar(&srcPath, "src", "", "Directory containing packages that will be compared to destination") + flag.StringVar(&dstPath, "dst", "", "Directory containing packages; used to compare src packages") + flag.StringVar(&outDirectory, "out", "", "Directory where the report will be created") + flag.BoolVar(&srcIsGno, "src_is_gno", false, "If true, indicates that the src parameter corresponds to the gno standard libraries") flag.Parse() reportBuilder, err := NewReportBuilder(srcPath, dstPath, outDirectory, srcIsGno) From 8e5bc5e2779dd25fc55e677eb205cb28ad2c99ef Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 10:58:29 +0100 Subject: [PATCH 14/35] Fix diffstatus const case. Use iota for enum --- misc/stdlib_diff/diffstatus.go | 16 ++++++++-------- misc/stdlib_diff/packagediff.go | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/misc/stdlib_diff/diffstatus.go b/misc/stdlib_diff/diffstatus.go index df39016891f..23829619f64 100644 --- a/misc/stdlib_diff/diffstatus.go +++ b/misc/stdlib_diff/diffstatus.go @@ -3,21 +3,21 @@ package main type diffStatus uint const ( - MISSING_IN_SRC diffStatus = 1 - MISSING_IN_DST diffStatus = 2 - HAS_DIFF diffStatus = 3 - NO_DIFF diffStatus = 4 + missingInSrc diffStatus = iota + missingInDst + hasDiff + noDiff ) func (status diffStatus) String() string { switch status { - case MISSING_IN_SRC: + case missingInSrc: return "missing in src" - case MISSING_IN_DST: + case missingInDst: return "missing in dst" - case HAS_DIFF: + case hasDiff: return "files differ" - case NO_DIFF: + case noDiff: return "files are equal" default: return "Unknown" diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index 37f1a690bd8..43aba4fd8c6 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -130,19 +130,19 @@ func (p *PackageDiffChecker) inferFileExtensions() (string, string) { func (p *PackageDiffChecker) getStatus(srcDiff, dstDiff []LineDifferrence) diffStatus { slicesAreEquals := slices.Equal(srcDiff, dstDiff) if slicesAreEquals { - return NO_DIFF + return noDiff } if len(srcDiff) == 0 { - return MISSING_IN_SRC + return missingInSrc } if len(dstDiff) == 0 { - return MISSING_IN_DST + return missingInDst } if !slicesAreEquals { - return HAS_DIFF + return hasDiff } return 0 From 8a6ab0be383507e470944d395a628f0c1597a6b9 Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 11:27:48 +0100 Subject: [PATCH 15/35] add go:embed to load templates --- misc/stdlib_diff/report.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index 76384237ce2..44ba8feb49e 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -2,11 +2,19 @@ package main import ( "bytes" + _ "embed" "fmt" "html/template" "os" ) +var ( + //go:embed templates/package_diff_template.html + packageDiffTemplate string + //go:embed templates/index_template.html + indexTemplate string +) + // ReportBuilder is a struct for building reports based on the differences // between source and destination directories. type ReportBuilder struct { @@ -42,12 +50,12 @@ type LinkToReport struct { // source path, destination path, and output directory. It also initializes // the packageTemplate using the provided HTML template file. func NewReportBuilder(srcPath, dstPath, outDir string, srcIsGno bool) (*ReportBuilder, error) { - packageTemplate, err := template.ParseFiles("templates/package_diff_template.html") + packageTemplate, err := template.New("").Parse(packageDiffTemplate) if err != nil { return nil, err } - indexTemplate, err := template.ParseFiles("templates/index_template.html") + indexTemplate, err := template.New("").Parse(indexTemplate) if err != nil { return nil, err } From 485461456f96a0a09e1f82c97872f1392117716e Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 11:34:11 +0100 Subject: [PATCH 16/35] Cleaning FileDiff.Differences() --- misc/stdlib_diff/filediff.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go index d2330e042f4..cfc2c768c52 100644 --- a/misc/stdlib_diff/filediff.go +++ b/misc/stdlib_diff/filediff.go @@ -40,8 +40,7 @@ func NewFileDiff(srcPath, dstPath, algoType string) (*FileDiff, error) { // Differences returns the differences in lines between the source and // destination files using the configured diff algorithm. func (f *FileDiff) Differences() ([]LineDifferrence, []LineDifferrence) { - srcDiff, dstDiff := f.DiffAlgorithm.Do() - return srcDiff, dstDiff + return f.DiffAlgorithm.Do() } // getFileLines reads and returns the lines of a file given its path. From 9efc2efe27e9439a51527617b9505568b62a589d Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 11:42:32 +0100 Subject: [PATCH 17/35] Add named return values --- misc/stdlib_diff/filediff.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go index cfc2c768c52..0faea3aecd0 100644 --- a/misc/stdlib_diff/filediff.go +++ b/misc/stdlib_diff/filediff.go @@ -39,7 +39,7 @@ func NewFileDiff(srcPath, dstPath, algoType string) (*FileDiff, error) { // Differences returns the differences in lines between the source and // destination files using the configured diff algorithm. -func (f *FileDiff) Differences() ([]LineDifferrence, []LineDifferrence) { +func (f *FileDiff) Differences() (src, dst []LineDifferrence) { return f.DiffAlgorithm.Do() } From 5edfd6c3fdbfcab040e277c8fe8f88a157048083 Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 14:25:20 +0100 Subject: [PATCH 18/35] Improving myers algorithm --- misc/stdlib_diff/algorithm.go | 17 +---------------- misc/stdlib_diff/filediff.go | 23 +++++++++-------------- misc/stdlib_diff/myers.go | 19 +++++++++++-------- misc/stdlib_diff/packagediff.go | 2 +- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/misc/stdlib_diff/algorithm.go b/misc/stdlib_diff/algorithm.go index 259af7187dd..7f832d9fe2c 100644 --- a/misc/stdlib_diff/algorithm.go +++ b/misc/stdlib_diff/algorithm.go @@ -1,20 +1,5 @@ package main -import "errors" - -const ( - MYERS = "myers" -) - type Algorithm interface { - Do() (srcDiff []LineDifferrence, dstDiff []LineDifferrence) -} - -func AlgorithmFactory(src, dst []string, algoType string) (Algorithm, error) { - switch algoType { - case MYERS: - return NewMyers(src, dst), nil - default: - return nil, errors.New("unknown algorithm type") - } + Diff() (srcDiff []LineDifferrence, dstDiff []LineDifferrence) } diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go index 0faea3aecd0..57a590211e1 100644 --- a/misc/stdlib_diff/filediff.go +++ b/misc/stdlib_diff/filediff.go @@ -7,9 +7,9 @@ import ( // FileDiff is a struct for comparing differences between two files. type FileDiff struct { - Src []string // Lines of the source file. - Dst []string // Lines of the destination file. - DiffAlgorithm Algorithm // Algorithm used for comparison. + Src []string // Lines of the source file. + Dst []string // Lines of the destination file. + Algorithm // Algorithm used for comparison. } // LineDifferrence represents a difference in a line during file comparison. @@ -20,27 +20,22 @@ type LineDifferrence struct { // NewFileDiff creates a new FileDiff instance for comparing differences between // the specified source and destination files. It initializes the source and -// destination file lines and the specified diff algorithm. -func NewFileDiff(srcPath, dstPath, algoType string) (*FileDiff, error) { +// destination file lines . +func NewFileDiff(srcPath, dstPath string) (*FileDiff, error) { src := getFileLines(srcPath) dst := getFileLines(dstPath) - diffAlgorithm, err := AlgorithmFactory(src, dst, algoType) - if err != nil { - return nil, err - } - return &FileDiff{ - Src: src, - Dst: dst, - DiffAlgorithm: diffAlgorithm, + Src: src, + Dst: dst, + Algorithm: NewMyers(src, dst), }, nil } // Differences returns the differences in lines between the source and // destination files using the configured diff algorithm. func (f *FileDiff) Differences() (src, dst []LineDifferrence) { - return f.DiffAlgorithm.Do() + return f.Diff() } // getFileLines reads and returns the lines of a file given its path. diff --git a/misc/stdlib_diff/myers.go b/misc/stdlib_diff/myers.go index 56464c228a2..bfb623416bd 100644 --- a/misc/stdlib_diff/myers.go +++ b/misc/stdlib_diff/myers.go @@ -22,32 +22,35 @@ func NewMyers(src, dst []string) *Myers { // Do performs the Myers algorithm to find the differences between source and destination files. // It returns the differences as two slices of LineDifferrence representing source and destination changes. -func (m *Myers) Do() ([]LineDifferrence, []LineDifferrence) { +func (m *Myers) Diff() ([]LineDifferrence, []LineDifferrence) { + var ( + srcIndex, dstIndex int + insertCount, deleteCount int + dstDiff, srcDiff []LineDifferrence + ) + operations := m.doMyers() - srcIndex, dstIndex, insertCount, deleteCount := 0, 0, 0, 0 - dstDiff := make([]LineDifferrence, 0) - srcDiff := make([]LineDifferrence, 0) for _, op := range operations { switch op { case INSERT: dstDiff = append(dstDiff, LineDifferrence{Line: "+" + m.dst[dstIndex], Operation: op.String()}) srcDiff = append(srcDiff, LineDifferrence{Line: "", Operation: MOVE.String()}) - dstIndex += 1 + dstIndex++ insertCount++ continue case MOVE: dstDiff = append(dstDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op.String()}) srcDiff = append(srcDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op.String()}) - srcIndex += 1 - dstIndex += 1 + srcIndex++ + dstIndex++ continue case DELETE: dstDiff = append(dstDiff, LineDifferrence{Line: "", Operation: MOVE.String()}) srcDiff = append(srcDiff, LineDifferrence{Line: "-" + m.src[srcIndex], Operation: op.String()}) - srcIndex += 1 + srcIndex++ deleteCount++ continue } diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index 43aba4fd8c6..247e49a9a27 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -72,7 +72,7 @@ func (p *PackageDiffChecker) Differences() (*Differences, error) { dstFileName := trimmedFileName + dstFileExt dstFilePath := p.DstPath + "/" + dstFileName - fileDiff, err := NewFileDiff(srcFilePath, dstFilePath, "myers") + fileDiff, err := NewFileDiff(srcFilePath, dstFilePath) if err != nil { return nil, err } From 79f825e0e4ce453b4fe4071504918c352ccd13db Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 14:42:40 +0100 Subject: [PATCH 19/35] Making LineDifference Operation field an actual operation. Cleaning operation.go --- misc/stdlib_diff/filediff.go | 4 +-- misc/stdlib_diff/myers.go | 26 +++++++++---------- misc/stdlib_diff/operation.go | 20 +++++++------- .../templates/package_diff_template.html | 4 +-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go index 57a590211e1..7ce6975e2ac 100644 --- a/misc/stdlib_diff/filediff.go +++ b/misc/stdlib_diff/filediff.go @@ -14,8 +14,8 @@ type FileDiff struct { // LineDifferrence represents a difference in a line during file comparison. type LineDifferrence struct { - Line string // The line content. - Operation string // The operation performed on the line (e.g., "add", "delete", "equal"). + Line string // The line content. + Operation operation // The operation performed on the line (e.g., "add", "delete", "equal"). } // NewFileDiff creates a new FileDiff instance for comparing differences between diff --git a/misc/stdlib_diff/myers.go b/misc/stdlib_diff/myers.go index bfb623416bd..1e5f4ea6784 100644 --- a/misc/stdlib_diff/myers.go +++ b/misc/stdlib_diff/myers.go @@ -33,23 +33,23 @@ func (m *Myers) Diff() ([]LineDifferrence, []LineDifferrence) { for _, op := range operations { switch op { - case INSERT: - dstDiff = append(dstDiff, LineDifferrence{Line: "+" + m.dst[dstIndex], Operation: op.String()}) - srcDiff = append(srcDiff, LineDifferrence{Line: "", Operation: MOVE.String()}) + case insert: + dstDiff = append(dstDiff, LineDifferrence{Line: "+" + m.dst[dstIndex], Operation: op}) + srcDiff = append(srcDiff, LineDifferrence{Line: "", Operation: equal}) dstIndex++ insertCount++ continue - case MOVE: - dstDiff = append(dstDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op.String()}) - srcDiff = append(srcDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op.String()}) + case equal: + dstDiff = append(dstDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op}) + srcDiff = append(srcDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op}) srcIndex++ dstIndex++ continue - case DELETE: - dstDiff = append(dstDiff, LineDifferrence{Line: "", Operation: MOVE.String()}) - srcDiff = append(srcDiff, LineDifferrence{Line: "-" + m.src[srcIndex], Operation: op.String()}) + case delete: + dstDiff = append(dstDiff, LineDifferrence{Line: "", Operation: equal}) + srcDiff = append(srcDiff, LineDifferrence{Line: "-" + m.src[srcIndex], Operation: op}) srcIndex++ deleteCount++ continue @@ -141,15 +141,15 @@ func (m *Myers) getAllOperations(tree []map[int]int) []operation { prevY = prevX - prevK for x > prevX && y > prevY { - operations = append(operations, MOVE) + operations = append(operations, equal) x -= 1 y -= 1 } if x == prevX { - operations = append(operations, INSERT) + operations = append(operations, insert) } else { - operations = append(operations, DELETE) + operations = append(operations, delete) } x, y = prevX, prevY @@ -157,7 +157,7 @@ func (m *Myers) getAllOperations(tree []map[int]int) []operation { if tree[0][0] != 0 { for i := 0; i < tree[0][0]; i++ { - operations = append(operations, MOVE) + operations = append(operations, equal) } } diff --git a/misc/stdlib_diff/operation.go b/misc/stdlib_diff/operation.go index 926e64b1a39..5ebc632a90e 100644 --- a/misc/stdlib_diff/operation.go +++ b/misc/stdlib_diff/operation.go @@ -5,23 +5,23 @@ package main type operation uint const ( - // INSERT represents an insertion operation. - INSERT operation = 1 - // DELETE represents a deletion operation. - DELETE operation = 2 - // MOVE represents a move operation. - MOVE operation = 3 + // insert represents an insertion operation. + insert operation = iota + 1 + // delete represents a deletion operation. + delete + // equal represents an equal operation. + equal ) // String returns a string representation of the operation. func (op operation) String() string { switch op { - case INSERT: + case insert: return "INS" - case DELETE: + case delete: return "DEL" - case MOVE: - return "MOV" + case equal: + return "EQ" default: return "UNKNOWN" } diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index 83174a60a69..be0ceb77ac6 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -1,9 +1,9 @@ {{define "file-viewer" }}
{{- range .}} - {{- if eq .Operation "INS"}} + {{- if eq .Operation 1}}

{{.Line}}

- {{- else if eq .Operation "DEL"}} + {{- else if eq .Operation 2}}

{{.Line}}

{{- else}} {{- if eq .Line ""}} From 803333034a309bfff223b10912af5661504241d7 Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 14:57:54 +0100 Subject: [PATCH 20/35] getFileLines now returns error --- misc/stdlib_diff/filediff.go | 39 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go index 7ce6975e2ac..746c2a689b2 100644 --- a/misc/stdlib_diff/filediff.go +++ b/misc/stdlib_diff/filediff.go @@ -1,8 +1,9 @@ package main import ( - "bufio" + "fmt" "os" + "strings" ) // FileDiff is a struct for comparing differences between two files. @@ -22,8 +23,15 @@ type LineDifferrence struct { // the specified source and destination files. It initializes the source and // destination file lines . func NewFileDiff(srcPath, dstPath string) (*FileDiff, error) { - src := getFileLines(srcPath) - dst := getFileLines(dstPath) + src, err := getFileLines(srcPath) + if err != nil { + return nil, fmt.Errorf("can't read src file: %w", err) + } + + dst, err := getFileLines(dstPath) + if err != nil { + return nil, fmt.Errorf("can't read dst file: %w", err) + } return &FileDiff{ Src: src, @@ -39,23 +47,14 @@ func (f *FileDiff) Differences() (src, dst []LineDifferrence) { } // getFileLines reads and returns the lines of a file given its path. -func getFileLines(p string) []string { - lines := make([]string, 0) - - f, err := os.Open(p) +func getFileLines(p string) ([]string, error) { + data, err := os.ReadFile(p) if err != nil { - return lines + if os.IsNotExist(err) { + return nil, nil + } + return nil, err } - defer f.Close() - - scanner := bufio.NewScanner(f) - for scanner.Scan() { - lines = append(lines, scanner.Text()) - } - - if err := scanner.Err(); err != nil { - return lines - } - - return lines + lines := strings.Split(strings.ReplaceAll(string(data), "\r\n", "\n"), "\n") + return lines, nil } From 175c32db632130f006bc1282b4ed0f48f69ee4e5 Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 15:07:07 +0100 Subject: [PATCH 21/35] Equal values on compared files are greyed --- misc/stdlib_diff/templates/package_diff_template.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index be0ceb77ac6..47740f6267b 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -9,7 +9,7 @@ {{- if eq .Line ""}}
{{- else}} -

{{.Line}}

+

{{.Line}}

{{- end}} {{- end}} {{- end}} From 219de7366d73b554a8670190cc4c20a503fd00b8 Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 15:39:29 +0100 Subject: [PATCH 22/35] Operation symbols (+/-) are handled by the template, and they are not selectable --- misc/stdlib_diff/myers.go | 4 ++-- misc/stdlib_diff/templates/package_diff_template.html | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/misc/stdlib_diff/myers.go b/misc/stdlib_diff/myers.go index 1e5f4ea6784..c967dd639da 100644 --- a/misc/stdlib_diff/myers.go +++ b/misc/stdlib_diff/myers.go @@ -34,7 +34,7 @@ func (m *Myers) Diff() ([]LineDifferrence, []LineDifferrence) { for _, op := range operations { switch op { case insert: - dstDiff = append(dstDiff, LineDifferrence{Line: "+" + m.dst[dstIndex], Operation: op}) + dstDiff = append(dstDiff, LineDifferrence{Line: m.dst[dstIndex], Operation: op}) srcDiff = append(srcDiff, LineDifferrence{Line: "", Operation: equal}) dstIndex++ insertCount++ @@ -49,7 +49,7 @@ func (m *Myers) Diff() ([]LineDifferrence, []LineDifferrence) { case delete: dstDiff = append(dstDiff, LineDifferrence{Line: "", Operation: equal}) - srcDiff = append(srcDiff, LineDifferrence{Line: "-" + m.src[srcIndex], Operation: op}) + srcDiff = append(srcDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op}) srcIndex++ deleteCount++ continue diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index 47740f6267b..55c67c4c280 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -2,11 +2,14 @@
{{- range .}} {{- if eq .Operation 1}} -

{{.Line}}

+
+ -

{{.Line}}

+
{{- else if eq .Operation 2}} -

{{.Line}}

- {{- else}} - {{- if eq .Line ""}} +
+ +

{{.Line}}

+
+ {{- else if eq .Line ""}}
{{- else}}

{{.Line}}

From cfb11ac3c53dc60bda7e02995c59e168341efffc Mon Sep 17 00:00:00 2001 From: Florian Richard Date: Fri, 15 Dec 2023 15:56:00 +0100 Subject: [PATCH 23/35] Fix templates --- misc/stdlib_diff/templates/package_diff_template.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index 55c67c4c280..684e6d7bd1f 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -2,7 +2,7 @@
{{- range .}} {{- if eq .Operation 1}} -
+
-

{{.Line}}

{{- else if eq .Operation 2}} @@ -15,7 +15,6 @@

{{.Line}}

{{- end}} {{- end}} - {{- end}}
{{end}} From ef3bb3a3445d2fbbfe332c9d26fa51389b76631f Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sun, 29 Sep 2024 12:46:42 +0200 Subject: [PATCH 24/35] Solve comments on PR --- misc/stdlib_diff/README.md | 4 +- misc/stdlib_diff/go.mod | 3 ++ misc/stdlib_diff/packagediff.go | 40 ++++++++++--------- misc/stdlib_diff/report.go | 3 +- .../templates/package_diff_template.html | 2 +- 5 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 misc/stdlib_diff/go.mod diff --git a/misc/stdlib_diff/README.md b/misc/stdlib_diff/README.md index 3ed9c70bfcb..9b05deaed03 100644 --- a/misc/stdlib_diff/README.md +++ b/misc/stdlib_diff/README.md @@ -7,13 +7,13 @@ Stdlibs_diff is a tool that generates an html report indicating differences betw Compare the `go` standard libraries the `gno` standard libraries ```shell -./stdlibs_diff --src --dst --out +./stdlibs_diff -src -dst -out ``` Compare the `gno` standard libraries the `go` standard libraries ```shell -./stdlibs_diff --src --dst --out --src_is_gno +./stdlibs_diff -src -dst -out -src_is_gno ``` diff --git a/misc/stdlib_diff/go.mod b/misc/stdlib_diff/go.mod new file mode 100644 index 00000000000..b533ae398f0 --- /dev/null +++ b/misc/stdlib_diff/go.mod @@ -0,0 +1,3 @@ +module github.com/gnolang/gno/misc/stdlib_diff + +go 1.21.0 diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index 247e49a9a27..5564e080c7c 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -1,8 +1,10 @@ package main import ( - "fmt" + "errors" + "io/fs" "os" + "path/filepath" "slices" "strings" ) @@ -155,26 +157,28 @@ func (p *PackageDiffChecker) hasSameNumberOfFiles() bool { // listDirFiles returns a list of file names in the specified directory. func listDirFiles(dirPath string) ([]string, error) { - f, err := os.Open(dirPath) - if err != nil { - return []string{}, nil - } + fileNames := make([]string, 0) + err := filepath.WalkDir(dirPath, func(path string, dirEntry fs.DirEntry, err error) error { + if err != nil { + // Avoid returning an error if the file does not exists on source or destination. + if errors.Is(err, os.ErrNotExist) { + return nil + } + return err + } - defer func() { - if err := f.Close(); err != nil { - fmt.Fprintln(os.Stderr, "can't close "+dirPath) + // Only list .go and .gno files + if !strings.Contains(path, ".go") && !strings.Contains(path, ".gno") { + return nil } - }() - filesInfo, err := f.Readdir(0) - if err != nil { - return nil, fmt.Errorf("can't list file in directory :%w", err) - } + if dirEntry != nil && !dirEntry.IsDir() { + filenameWithSubfolder := strings.TrimPrefix(path, dirPath+"/") + fileNames = append(fileNames, filenameWithSubfolder) + } - fileNames := make([]string, 0) - for _, info := range filesInfo { - fileNames = append(fileNames, info.Name()) - } + return nil + }) - return fileNames, nil + return fileNames, err } diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index 44ba8feb49e..72403ea434a 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -6,6 +6,7 @@ import ( "fmt" "html/template" "os" + "slices" ) var ( @@ -133,7 +134,7 @@ func (builder *ReportBuilder) listSrcDirectories() ([]string, error) { directories := make([]string, 0) for _, dirEntry := range dirEntries { - if dirEntry.IsDir() { + if dirEntry.IsDir() && !slices.Contains([]string{"cmd", "vendor"}, dirEntry.Name()) { directories = append(directories, dirEntry.Name()) } } diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index 684e6d7bd1f..9b2158fc73b 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -12,7 +12,7 @@ {{- else if eq .Line ""}}
{{- else}} -

{{.Line}}

+

{{.Line}}

{{- end}} {{- end}}
From 777a759ac144f0c428585c3404fb9dfb465eaca5 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sat, 5 Oct 2024 11:35:55 +0200 Subject: [PATCH 25/35] use gotextdiff --- misc/stdlib_diff/filediff.go | 116 ++++++++++-- misc/stdlib_diff/go.mod | 2 + misc/stdlib_diff/go.sum | 2 + misc/stdlib_diff/myers.go | 166 ------------------ .../templates/package_diff_template.html | 14 +- 5 files changed, 114 insertions(+), 186 deletions(-) create mode 100644 misc/stdlib_diff/go.sum delete mode 100644 misc/stdlib_diff/myers.go diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go index 746c2a689b2..278ba67e02a 100644 --- a/misc/stdlib_diff/filediff.go +++ b/misc/stdlib_diff/filediff.go @@ -4,57 +4,143 @@ import ( "fmt" "os" "strings" + + "github.com/hexops/gotextdiff" + "github.com/hexops/gotextdiff/myers" + "github.com/hexops/gotextdiff/span" ) // FileDiff is a struct for comparing differences between two files. type FileDiff struct { - Src []string // Lines of the source file. - Dst []string // Lines of the destination file. - Algorithm // Algorithm used for comparison. + Src string // Name of the source file. + Dst string // Name of the destination file. + srcContent string // Content of the source file. + dstContent string // Content of the destination file. + srcLines []string // Lines of the source file. + dstLines []string // Lines of the destination file. + } // LineDifferrence represents a difference in a line during file comparison. type LineDifferrence struct { Line string // The line content. Operation operation // The operation performed on the line (e.g., "add", "delete", "equal"). + Number int } // NewFileDiff creates a new FileDiff instance for comparing differences between // the specified source and destination files. It initializes the source and // destination file lines . func NewFileDiff(srcPath, dstPath string) (*FileDiff, error) { - src, err := getFileLines(srcPath) + src, err := getFileContent(srcPath) if err != nil { return nil, fmt.Errorf("can't read src file: %w", err) } - dst, err := getFileLines(dstPath) + dst, err := getFileContent(dstPath) if err != nil { return nil, fmt.Errorf("can't read dst file: %w", err) } return &FileDiff{ - Src: src, - Dst: dst, - Algorithm: NewMyers(src, dst), + srcContent: src, + dstContent: dst, + srcLines: strings.Split(src, "\n"), + dstLines: strings.Split(dst, "\n"), + Src: srcPath, + Dst: dstPath, }, nil } // Differences returns the differences in lines between the source and // destination files using the configured diff algorithm. func (f *FileDiff) Differences() (src, dst []LineDifferrence) { - return f.Diff() + var ( + srcIndex, dstIndex int + insertCount, deleteCount int + dstDiff, srcDiff []LineDifferrence + ) + + if len(f.dstContent) == 0 { + return f.destEmpty() + } + + if len(f.srcContent) == 0 { + return f.srcEmpty() + } + + /* printUntil prints all the lines thar are equal + because they do not appear on the computed edits from gotextdiff + so we need to add them manually looping always from the current value of + srcIndex until the line before the start of the hunk computed diff, hunk.FromLine-1 + + We need to print all the lines before each hunk and then ensure the end of the file is printed too + */ + printUntil := func(until int) { + for i := srcIndex; i < until; i++ { + dstDiff = append(dstDiff, LineDifferrence{Line: f.srcLines[srcIndex], Operation: equal, Number: dstIndex + 1}) + srcDiff = append(srcDiff, LineDifferrence{Line: f.srcLines[srcIndex], Operation: equal, Number: srcIndex + 1}) + srcIndex++ + dstIndex++ + } + } + + edits := myers.ComputeEdits(span.URIFromPath(f.Src), f.srcContent, f.dstContent) + unified := gotextdiff.ToUnified(f.Src, f.Dst, f.srcContent, edits) + for _, hunk := range unified.Hunks { + printUntil(hunk.FromLine - 1) + + for _, line := range hunk.Lines { + switch line.Kind { + case gotextdiff.Insert: + insertCount++ + dstIndex++ + dstDiff = append(dstDiff, LineDifferrence{Line: line.Content, Operation: insert, Number: dstIndex}) + + case gotextdiff.Equal: + srcIndex++ + dstIndex++ + dstDiff = append(dstDiff, LineDifferrence{Line: line.Content, Operation: equal, Number: dstIndex}) + srcDiff = append(srcDiff, LineDifferrence{Line: line.Content, Operation: equal, Number: srcIndex}) + + case gotextdiff.Delete: + srcIndex++ + deleteCount++ + srcDiff = append(srcDiff, LineDifferrence{Line: line.Content, Operation: delete, Number: srcIndex}) + } + } + } + + printUntil(len(f.srcLines)) + return srcDiff, dstDiff +} + +func (f *FileDiff) destEmpty() ([]LineDifferrence, []LineDifferrence) { + srcDiff := []LineDifferrence{} + for index, line := range f.srcLines { + srcDiff = append(srcDiff, LineDifferrence{Line: line, Operation: delete, Number: index + 1}) + } + + return srcDiff, make([]LineDifferrence, 0) +} + +func (f *FileDiff) srcEmpty() ([]LineDifferrence, []LineDifferrence) { + destDiff := []LineDifferrence{} + for index, line := range f.dstLines { + destDiff = append(destDiff, LineDifferrence{Line: line, Operation: insert, Number: index + 1}) + } + + return make([]LineDifferrence, 0), destDiff } -// getFileLines reads and returns the lines of a file given its path. -func getFileLines(p string) ([]string, error) { +// getFileContent reads and returns the lines of a file given its path. +func getFileContent(p string) (string, error) { data, err := os.ReadFile(p) if err != nil { if os.IsNotExist(err) { - return nil, nil + return "", nil } - return nil, err + return "", err } - lines := strings.Split(strings.ReplaceAll(string(data), "\r\n", "\n"), "\n") - return lines, nil + return strings.ReplaceAll(string(data), "\t", " "), nil } diff --git a/misc/stdlib_diff/go.mod b/misc/stdlib_diff/go.mod index b533ae398f0..4e200f56ebb 100644 --- a/misc/stdlib_diff/go.mod +++ b/misc/stdlib_diff/go.mod @@ -1,3 +1,5 @@ module github.com/gnolang/gno/misc/stdlib_diff go 1.21.0 + +require github.com/hexops/gotextdiff v1.0.3 diff --git a/misc/stdlib_diff/go.sum b/misc/stdlib_diff/go.sum new file mode 100644 index 00000000000..e71200ae5ce --- /dev/null +++ b/misc/stdlib_diff/go.sum @@ -0,0 +1,2 @@ +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= diff --git a/misc/stdlib_diff/myers.go b/misc/stdlib_diff/myers.go deleted file mode 100644 index c967dd639da..00000000000 --- a/misc/stdlib_diff/myers.go +++ /dev/null @@ -1,166 +0,0 @@ -package main - -import ( - "slices" -) - -var _ Algorithm = (*Myers)(nil) - -// Myers is a struct representing the Myers algorithm for line-based difference. -type Myers struct { - src []string // Lines of the source file. - dst []string // Lines of the destination file. -} - -// NewMyers creates a new Myers instance with the specified source and destination lines. -func NewMyers(src, dst []string) *Myers { - return &Myers{ - src: src, - dst: dst, - } -} - -// Do performs the Myers algorithm to find the differences between source and destination files. -// It returns the differences as two slices of LineDifferrence representing source and destination changes. -func (m *Myers) Diff() ([]LineDifferrence, []LineDifferrence) { - var ( - srcIndex, dstIndex int - insertCount, deleteCount int - dstDiff, srcDiff []LineDifferrence - ) - - operations := m.doMyers() - - for _, op := range operations { - switch op { - case insert: - dstDiff = append(dstDiff, LineDifferrence{Line: m.dst[dstIndex], Operation: op}) - srcDiff = append(srcDiff, LineDifferrence{Line: "", Operation: equal}) - dstIndex++ - insertCount++ - continue - - case equal: - dstDiff = append(dstDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op}) - srcDiff = append(srcDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op}) - srcIndex++ - dstIndex++ - continue - - case delete: - dstDiff = append(dstDiff, LineDifferrence{Line: "", Operation: equal}) - srcDiff = append(srcDiff, LineDifferrence{Line: m.src[srcIndex], Operation: op}) - srcIndex++ - deleteCount++ - continue - } - } - - // Means that src file is empty. - if insertCount == len(srcDiff) { - srcDiff = make([]LineDifferrence, 0) - } - // Means that dst file is empty. - if deleteCount == len(dstDiff) { - dstDiff = make([]LineDifferrence, 0) - } - return srcDiff, dstDiff -} - -// doMyers performs the Myers algorithm and returns the list of operations. -func (m *Myers) doMyers() []operation { - var tree []map[int]int - var x, y int - - srcLen := len(m.src) - dstLen := len(m.dst) - max := srcLen + dstLen - - for pathLen := 0; pathLen <= max; pathLen++ { - optimalCoordinates := make(map[int]int, pathLen+2) - tree = append(tree, optimalCoordinates) - - if pathLen == 0 { - commonPrefixLen := 0 - for srcLen > commonPrefixLen && dstLen > commonPrefixLen && m.src[commonPrefixLen] == m.dst[commonPrefixLen] { - commonPrefixLen++ - } - optimalCoordinates[0] = commonPrefixLen - - if commonPrefixLen == srcLen && commonPrefixLen == dstLen { - return m.getAllOperations(tree) - } - continue - } - - lastV := tree[pathLen-1] - - for k := -pathLen; k <= pathLen; k += 2 { - if k == -pathLen || (k != pathLen && lastV[k-1] < lastV[k+1]) { - x = lastV[k+1] - } else { - x = lastV[k-1] + 1 - } - - y = x - k - - for x < srcLen && y < dstLen && m.src[x] == m.dst[y] { - x, y = x+1, y+1 - } - - optimalCoordinates[k] = x - - if x == srcLen && y == dstLen { - return m.getAllOperations(tree) - } - } - } - - return m.getAllOperations(tree) -} - -// getAllOperations retrieves the list of operations from the calculated tree. -func (m *Myers) getAllOperations(tree []map[int]int) []operation { - var operations []operation - var k, prevK, prevX, prevY int - - x := len(m.src) - y := len(m.dst) - - for pathLen := len(tree) - 1; pathLen > 0; pathLen-- { - k = x - y - lastV := tree[pathLen-1] - - if k == -pathLen || (k != pathLen && lastV[k-1] < lastV[k+1]) { - prevK = k + 1 - } else { - prevK = k - 1 - } - - prevX = lastV[prevK] - prevY = prevX - prevK - - for x > prevX && y > prevY { - operations = append(operations, equal) - x -= 1 - y -= 1 - } - - if x == prevX { - operations = append(operations, insert) - } else { - operations = append(operations, delete) - } - - x, y = prevX, prevY - } - - if tree[0][0] != 0 { - for i := 0; i < tree[0][0]; i++ { - operations = append(operations, equal) - } - } - - slices.Reverse(operations) - return operations -} diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index 9b2158fc73b..6a41cf38db3 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -3,16 +3,20 @@ {{- range .}} {{- if eq .Operation 1}}
- -

{{.Line}}

+ {{.Number}}

{{.Line}}

{{- else if eq .Operation 2}}
- +

{{.Line}}

+ {{.Number}}

{{.Line}}

+
+ + {{- else if eq .Operation 3}} +
+ {{.Number}} +

{{.Line}}

- {{- else if eq .Line ""}} -
{{- else}} -

{{.Line}}

+

{{.Line}}

{{- end}} {{- end}} From 0d563bc914d39a01b8724e88b8f9efdb70fd43bc Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sat, 5 Oct 2024 12:32:18 +0200 Subject: [PATCH 26/35] mark directories as not found on index --- misc/stdlib_diff/algorithm.go | 5 -- misc/stdlib_diff/filediff.go | 4 +- misc/stdlib_diff/report.go | 88 ++++++++++++------- .../stdlib_diff/templates/index_template.html | 6 +- 4 files changed, 64 insertions(+), 39 deletions(-) delete mode 100644 misc/stdlib_diff/algorithm.go diff --git a/misc/stdlib_diff/algorithm.go b/misc/stdlib_diff/algorithm.go deleted file mode 100644 index 7f832d9fe2c..00000000000 --- a/misc/stdlib_diff/algorithm.go +++ /dev/null @@ -1,5 +0,0 @@ -package main - -type Algorithm interface { - Diff() (srcDiff []LineDifferrence, dstDiff []LineDifferrence) -} diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go index 278ba67e02a..6e5f10baf6e 100644 --- a/misc/stdlib_diff/filediff.go +++ b/misc/stdlib_diff/filediff.go @@ -69,8 +69,7 @@ func (f *FileDiff) Differences() (src, dst []LineDifferrence) { return f.srcEmpty() } - /* printUntil prints all the lines thar are equal - because they do not appear on the computed edits from gotextdiff + /* printUntil prints all the lines than do not appear on the computed edits from gotextdiff so we need to add them manually looping always from the current value of srcIndex until the line before the start of the hunk computed diff, hunk.FromLine-1 @@ -112,6 +111,7 @@ func (f *FileDiff) Differences() (src, dst []LineDifferrence) { } printUntil(len(f.srcLines)) + return srcDiff, dstDiff } diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index 72403ea434a..681b5c18404 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -6,7 +6,6 @@ import ( "fmt" "html/template" "os" - "slices" ) var ( @@ -45,6 +44,7 @@ type IndexTemplate struct { type LinkToReport struct { PathToReport string PackageName string + WasFound bool } // NewReportBuilder creates a new ReportBuilder instance with the specified @@ -86,35 +86,37 @@ func (builder *ReportBuilder) Build() error { } for _, directory := range directories { - srcPackagePath := builder.SrcPath + "/" + directory - dstPackagePath := builder.DstPath + "/" + directory - - packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath, builder.SrcIsGno) - if err != nil { - return fmt.Errorf("can't create new PackageDiffChecker: %w", err) - } - - differences, err := packageChecker.Differences() - if err != nil { - return fmt.Errorf("can't compute differences: %w", err) - } - - data := &PackageDiffTemplateData{ - PackageName: directory, - SrcFilesCount: len(packageChecker.SrcFiles), - SrcPackageLocation: srcPackagePath, - DstFileCount: len(packageChecker.DstFiles), - DstPackageLocation: dstPackagePath, - FilesDifferences: differences.FilesDifferences, - } - - if err := builder.writePackageTemplate(data, directory); err != nil { - return err + if directory.FoundInDest { + srcPackagePath := builder.SrcPath + "/" + directory.Path + dstPackagePath := builder.DstPath + "/" + directory.Path + packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath, builder.SrcIsGno) + if err != nil { + return fmt.Errorf("can't create new PackageDiffChecker: %w", err) + } + + differences, err := packageChecker.Differences() + if err != nil { + return fmt.Errorf("can't compute differences: %w", err) + } + + data := &PackageDiffTemplateData{ + PackageName: directory.Path, + SrcFilesCount: len(packageChecker.SrcFiles), + SrcPackageLocation: srcPackagePath, + DstFileCount: len(packageChecker.DstFiles), + DstPackageLocation: dstPackagePath, + FilesDifferences: differences.FilesDifferences, + } + + if err := builder.writePackageTemplate(data, directory.Path); err != nil { + return err + } } indexTemplateData.Reports = append(indexTemplateData.Reports, LinkToReport{ - PathToReport: "./" + directory + "/report.html", - PackageName: directory, + PathToReport: "./" + directory.Path + "/report.html", + PackageName: directory.Path, + WasFound: directory.FoundInDest, }) } @@ -125,20 +127,44 @@ func (builder *ReportBuilder) Build() error { return nil } +type Directory struct { + Path string + FoundInDest bool +} + // listSrcDirectories retrieves a list of directories in the source path. -func (builder *ReportBuilder) listSrcDirectories() ([]string, error) { +func (builder *ReportBuilder) listSrcDirectories() ([]Directory, error) { dirEntries, err := os.ReadDir(builder.SrcPath) if err != nil { return nil, err } - directories := make([]string, 0) + destDirectories, err := builder.getSrcDirectories() + if err != nil { + return nil, err + } + + directories := make([]Directory, 0) for _, dirEntry := range dirEntries { - if dirEntry.IsDir() && !slices.Contains([]string{"cmd", "vendor"}, dirEntry.Name()) { - directories = append(directories, dirEntry.Name()) + if dirEntry.IsDir() { + directories = append(directories, Directory{FoundInDest: destDirectories[dirEntry.Name()], Path: dirEntry.Name()}) } } + return directories, nil +} +func (builder *ReportBuilder) getSrcDirectories() (map[string]bool, error) { + dirEntries, err := os.ReadDir(builder.DstPath) + if err != nil { + return nil, err + } + + directories := make(map[string]bool) + for _, dirEntry := range dirEntries { + if dirEntry.IsDir() { + directories[dirEntry.Name()] = true + } + } return directories, nil } diff --git a/misc/stdlib_diff/templates/index_template.html b/misc/stdlib_diff/templates/index_template.html index 5ad98f29d3b..c868b8021aa 100644 --- a/misc/stdlib_diff/templates/index_template.html +++ b/misc/stdlib_diff/templates/index_template.html @@ -45,7 +45,11 @@

List of packages processed

From 88c73f01bd4b45d82784e5b80ad0994f08605072 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sat, 5 Oct 2024 23:14:27 +0200 Subject: [PATCH 27/35] list all subdirectories on index --- misc/stdlib_diff/packagediff.go | 30 +--- misc/stdlib_diff/report.go | 167 ++++++++++++------ .../stdlib_diff/templates/index_template.html | 23 ++- 3 files changed, 145 insertions(+), 75 deletions(-) diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index 5564e080c7c..f0aa88ad42b 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -1,10 +1,7 @@ package main import ( - "errors" - "io/fs" "os" - "path/filepath" "slices" "strings" ) @@ -158,27 +155,18 @@ func (p *PackageDiffChecker) hasSameNumberOfFiles() bool { // listDirFiles returns a list of file names in the specified directory. func listDirFiles(dirPath string) ([]string, error) { fileNames := make([]string, 0) - err := filepath.WalkDir(dirPath, func(path string, dirEntry fs.DirEntry, err error) error { - if err != nil { - // Avoid returning an error if the file does not exists on source or destination. - if errors.Is(err, os.ErrNotExist) { - return nil - } - return err - } + dirEntries, err := os.ReadDir(dirPath) + if err != nil { + return nil, err + } + for _, dirEntry := range dirEntries { // Only list .go and .gno files - if !strings.Contains(path, ".go") && !strings.Contains(path, ".gno") { - return nil - } - - if dirEntry != nil && !dirEntry.IsDir() { - filenameWithSubfolder := strings.TrimPrefix(path, dirPath+"/") - fileNames = append(fileNames, filenameWithSubfolder) + if !strings.Contains(dirEntry.Name(), ".go") && !strings.Contains(dirEntry.Name(), ".gno") { + continue } - - return nil - }) + fileNames = append(fileNames, dirEntry.Name()) + } return fileNames, err } diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index 681b5c18404..b193de11f35 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -5,7 +5,10 @@ import ( _ "embed" "fmt" "html/template" + "io/fs" "os" + "path/filepath" + "strings" ) var ( @@ -42,9 +45,10 @@ type IndexTemplate struct { } type LinkToReport struct { - PathToReport string - PackageName string - WasFound bool + PathToReport string + PackageName string + WasFound bool + Subdirectories []LinkToReport } // NewReportBuilder creates a new ReportBuilder instance with the specified @@ -86,38 +90,28 @@ func (builder *ReportBuilder) Build() error { } for _, directory := range directories { - if directory.FoundInDest { - srcPackagePath := builder.SrcPath + "/" + directory.Path - dstPackagePath := builder.DstPath + "/" + directory.Path - packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath, builder.SrcIsGno) - if err != nil { - return fmt.Errorf("can't create new PackageDiffChecker: %w", err) - } - - differences, err := packageChecker.Differences() - if err != nil { - return fmt.Errorf("can't compute differences: %w", err) - } - - data := &PackageDiffTemplateData{ - PackageName: directory.Path, - SrcFilesCount: len(packageChecker.SrcFiles), - SrcPackageLocation: srcPackagePath, - DstFileCount: len(packageChecker.DstFiles), - DstPackageLocation: dstPackagePath, - FilesDifferences: differences.FilesDifferences, - } - - if err := builder.writePackageTemplate(data, directory.Path); err != nil { + if err := builder.ExecuteDiffTemplate(directory); err != nil { + return err + } + report := LinkToReport{ + PathToReport: "./" + directory.Path + "/report.html", + PackageName: directory.Path, + WasFound: directory.FoundInDest, + Subdirectories: make([]LinkToReport, 0), + } + for _, subDirectory := range directory.Children { + if err := builder.ExecuteDiffTemplate(subDirectory); err != nil { return err } + report.Subdirectories = append(report.Subdirectories, LinkToReport{ + PathToReport: "./" + subDirectory.Path + "/report.html", + PackageName: subDirectory.Path, + WasFound: subDirectory.FoundInDest, + }) + } + indexTemplateData.Reports = append(indexTemplateData.Reports, report) - indexTemplateData.Reports = append(indexTemplateData.Reports, LinkToReport{ - PathToReport: "./" + directory.Path + "/report.html", - PackageName: directory.Path, - WasFound: directory.FoundInDest, - }) } if err := builder.writeIndexTemplate(indexTemplateData); err != nil { @@ -127,45 +121,112 @@ func (builder *ReportBuilder) Build() error { return nil } -type Directory struct { - Path string - FoundInDest bool -} +func (builder *ReportBuilder) ExecuteDiffTemplate(directory *Directory) error { + if !directory.FoundInDest { + return nil + } -// listSrcDirectories retrieves a list of directories in the source path. -func (builder *ReportBuilder) listSrcDirectories() ([]Directory, error) { - dirEntries, err := os.ReadDir(builder.SrcPath) + srcPackagePath := builder.SrcPath + "/" + directory.Path + dstPackagePath := builder.DstPath + "/" + directory.Path + packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath, builder.SrcIsGno) if err != nil { - return nil, err + return fmt.Errorf("can't create new PackageDiffChecker: %w", err) } - destDirectories, err := builder.getSrcDirectories() + differences, err := packageChecker.Differences() if err != nil { - return nil, err + return fmt.Errorf("can't compute differences: %w", err) } - directories := make([]Directory, 0) - for _, dirEntry := range dirEntries { - if dirEntry.IsDir() { - directories = append(directories, Directory{FoundInDest: destDirectories[dirEntry.Name()], Path: dirEntry.Name()}) - } + data := &PackageDiffTemplateData{ + PackageName: directory.Path, + SrcFilesCount: len(packageChecker.SrcFiles), + SrcPackageLocation: srcPackagePath, + DstFileCount: len(packageChecker.DstFiles), + DstPackageLocation: dstPackagePath, + FilesDifferences: differences.FilesDifferences, } - return directories, nil + + return builder.writePackageTemplate(data, directory.Path) +} + +type Directory struct { + Path string + FoundInDest bool + Children []*Directory } -func (builder *ReportBuilder) getSrcDirectories() (map[string]bool, error) { - dirEntries, err := os.ReadDir(builder.DstPath) +// listSrcDirectories retrieves a list of directories in the source path. +func (builder *ReportBuilder) listSrcDirectories() ([]*Directory, error) { + destDirectories, err := builder.getDstDirectories() if err != nil { return nil, err } + notfoundInDest := []string{} + directories := make(map[string]*Directory) + res := make([]*Directory, 0) + err = filepath.WalkDir(builder.SrcPath, func(path string, dirEntry fs.DirEntry, err error) error { + if path == builder.SrcPath { + return nil + } + + folderName := strings.TrimPrefix(path, builder.SrcPath+"/") + + // skip directories that are not found in the destination + for _, prefix := range notfoundInDest { + if strings.HasPrefix(folderName, prefix) { + return nil + } + } + + if err != nil { + return err + } + + if !dirEntry.IsDir() { + return nil + } + + newDir := &Directory{ + Path: folderName, + FoundInDest: destDirectories[folderName], + Children: make([]*Directory, 0), + } + + if isRootFolder(folderName) { + directories[folderName] = newDir + res = append(res, newDir) + } else { + directory := directories[getRootFolder(folderName)] + directory.Children = append(directory.Children, newDir) + directories[getRootFolder(folderName)] = directory + } + + if !destDirectories[dirEntry.Name()] { + notfoundInDest = append(notfoundInDest, folderName) + } + return nil + }) + + return res, err +} +func isRootFolder(path string) bool { + return !strings.Contains(path, "/") +} +func getRootFolder(path string) string { + return strings.Split(path, "/")[0] +} +func (builder *ReportBuilder) getDstDirectories() (map[string]bool, error) { directories := make(map[string]bool) - for _, dirEntry := range dirEntries { + err := filepath.WalkDir(builder.DstPath, func(path string, dirEntry fs.DirEntry, err error) error { if dirEntry.IsDir() { - directories[dirEntry.Name()] = true + folderName := strings.TrimPrefix(path, builder.DstPath+"/") + directories[folderName] = true } - } - return directories, nil + return nil + }) + return directories, err } // writeIndexTemplate generates and writes the index template with the given output paths. diff --git a/misc/stdlib_diff/templates/index_template.html b/misc/stdlib_diff/templates/index_template.html index c868b8021aa..bdddf3592db 100644 --- a/misc/stdlib_diff/templates/index_template.html +++ b/misc/stdlib_diff/templates/index_template.html @@ -46,7 +46,28 @@

List of packages processed

    {{- range .Reports}} {{- if .WasFound}} -
  • {{.PackageName}} + {{if .Subdirectories}} +
    + {{.PackageName}} + + {{- range .Subdirectories}} + {{- if .WasFound}} + + {{- else}} +
      +
    • {{.PackageName}}

      : missing in go
    • +
    + {{- end}} + {{- end}} +
    + {{- else}} + {{.PackageName}} + + {{- end}} {{- else}}
  • {{.PackageName}}

    : missing in gno {{- end}} From 44441cc11ef30ba2a072c73b7062cd21db9923af Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sun, 6 Oct 2024 00:12:24 +0200 Subject: [PATCH 28/35] Handle paths with and without trailing / --- misc/stdlib_diff/report.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index b193de11f35..9ae5a63be53 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -66,9 +66,10 @@ func NewReportBuilder(srcPath, dstPath, outDir string, srcIsGno bool) (*ReportBu } return &ReportBuilder{ - SrcPath: srcPath, - DstPath: dstPath, - OutDir: outDir, + // Trim suffix / in order to standardize paths accept path with or without `/` + SrcPath: strings.TrimSuffix(srcPath, `/`), + DstPath: strings.TrimSuffix(dstPath, `/`), + OutDir: strings.TrimSuffix(outDir, `/`), SrcIsGno: srcIsGno, packageTemplate: packageTemplate, indexTemplate: indexTemplate, From 3550f0b3993b5895376ecd86f59edbff538ad43c Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Wed, 9 Oct 2024 20:56:05 +0200 Subject: [PATCH 29/35] keep fixing some comments :) --- misc/stdlib_diff/filediff.go | 102 +++++++++++++----- misc/stdlib_diff/packagediff.go | 42 ++++---- misc/stdlib_diff/report.go | 39 ++++++- .../templates/package_diff_template.html | 77 ++++++++----- 4 files changed, 179 insertions(+), 81 deletions(-) diff --git a/misc/stdlib_diff/filediff.go b/misc/stdlib_diff/filediff.go index 6e5f10baf6e..a097c9afcc9 100644 --- a/misc/stdlib_diff/filediff.go +++ b/misc/stdlib_diff/filediff.go @@ -10,28 +10,35 @@ import ( "github.com/hexops/gotextdiff/span" ) -// FileDiff is a struct for comparing differences between two files. -type FileDiff struct { +// DiffChecker is a struct for comparing differences between two files. +type DiffChecker struct { Src string // Name of the source file. Dst string // Name of the destination file. srcContent string // Content of the source file. dstContent string // Content of the destination file. srcLines []string // Lines of the source file. dstLines []string // Lines of the destination file. - } // LineDifferrence represents a difference in a line during file comparison. type LineDifferrence struct { - Line string // The line content. - Operation operation // The operation performed on the line (e.g., "add", "delete", "equal"). - Number int + SrcLine string // The line on Src. + DestLine string // The line on Src. + SrcOperation operation // The operation performed on the line (e.g., "add", "delete", "equal"). + DestOperation operation + SrcNumber int + DestNumber int +} +type Diff struct { + Diffs []LineDifferrence + MissingSrc bool + MissingDst bool } -// NewFileDiff creates a new FileDiff instance for comparing differences between +// NewDiffChecker creates a new DiffChecker instance for comparing differences between // the specified source and destination files. It initializes the source and // destination file lines . -func NewFileDiff(srcPath, dstPath string) (*FileDiff, error) { +func NewDiffChecker(srcPath, dstPath string) (*DiffChecker, error) { src, err := getFileContent(srcPath) if err != nil { return nil, fmt.Errorf("can't read src file: %w", err) @@ -42,7 +49,7 @@ func NewFileDiff(srcPath, dstPath string) (*FileDiff, error) { return nil, fmt.Errorf("can't read dst file: %w", err) } - return &FileDiff{ + return &DiffChecker{ srcContent: src, dstContent: dst, srcLines: strings.Split(src, "\n"), @@ -54,11 +61,11 @@ func NewFileDiff(srcPath, dstPath string) (*FileDiff, error) { // Differences returns the differences in lines between the source and // destination files using the configured diff algorithm. -func (f *FileDiff) Differences() (src, dst []LineDifferrence) { +func (f *DiffChecker) Differences() *Diff { var ( srcIndex, dstIndex int insertCount, deleteCount int - dstDiff, srcDiff []LineDifferrence + diff []LineDifferrence ) if len(f.dstContent) == 0 { @@ -77,8 +84,15 @@ func (f *FileDiff) Differences() (src, dst []LineDifferrence) { */ printUntil := func(until int) { for i := srcIndex; i < until; i++ { - dstDiff = append(dstDiff, LineDifferrence{Line: f.srcLines[srcIndex], Operation: equal, Number: dstIndex + 1}) - srcDiff = append(srcDiff, LineDifferrence{Line: f.srcLines[srcIndex], Operation: equal, Number: srcIndex + 1}) + diff = append(diff, LineDifferrence{ + SrcLine: f.srcLines[srcIndex], + DestLine: f.srcLines[srcIndex], + DestOperation: equal, + SrcOperation: equal, + SrcNumber: srcIndex + 1, + DestNumber: dstIndex + 1, + }) + srcIndex++ dstIndex++ } @@ -89,48 +103,84 @@ func (f *FileDiff) Differences() (src, dst []LineDifferrence) { for _, hunk := range unified.Hunks { printUntil(hunk.FromLine - 1) + currentLine := LineDifferrence{} for _, line := range hunk.Lines { switch line.Kind { case gotextdiff.Insert: + if currentLine.DestLine != "" { + diff = append(diff, currentLine) + currentLine = LineDifferrence{} + } + insertCount++ dstIndex++ - dstDiff = append(dstDiff, LineDifferrence{Line: line.Content, Operation: insert, Number: dstIndex}) + + currentLine.DestLine = line.Content + currentLine.DestOperation = insert + currentLine.DestNumber = dstIndex case gotextdiff.Equal: + if currentLine.DestLine != "" || currentLine.SrcLine != "" { + diff = append(diff, currentLine) + currentLine = LineDifferrence{} + } + srcIndex++ dstIndex++ - dstDiff = append(dstDiff, LineDifferrence{Line: line.Content, Operation: equal, Number: dstIndex}) - srcDiff = append(srcDiff, LineDifferrence{Line: line.Content, Operation: equal, Number: srcIndex}) + + currentLine = LineDifferrence{ + SrcLine: line.Content, + DestLine: line.Content, + DestOperation: equal, + SrcOperation: equal, + SrcNumber: srcIndex, + DestNumber: dstIndex, + } case gotextdiff.Delete: + if currentLine.SrcLine != "" { + diff = append(diff, currentLine) + currentLine = LineDifferrence{} + } srcIndex++ deleteCount++ - srcDiff = append(srcDiff, LineDifferrence{Line: line.Content, Operation: delete, Number: srcIndex}) + currentLine.SrcLine = line.Content + currentLine.SrcOperation = delete + currentLine.SrcNumber = srcIndex } } + diff = append(diff, currentLine) } printUntil(len(f.srcLines)) - return srcDiff, dstDiff + return &Diff{ + Diffs: diff, + } } -func (f *FileDiff) destEmpty() ([]LineDifferrence, []LineDifferrence) { - srcDiff := []LineDifferrence{} +func (f *DiffChecker) destEmpty() *Diff { + diffs := []LineDifferrence{} for index, line := range f.srcLines { - srcDiff = append(srcDiff, LineDifferrence{Line: line, Operation: delete, Number: index + 1}) + diffs = append(diffs, LineDifferrence{SrcLine: line, SrcOperation: delete, SrcNumber: index + 1}) } - return srcDiff, make([]LineDifferrence, 0) + return &Diff{ + Diffs: diffs, + MissingDst: true, + } } -func (f *FileDiff) srcEmpty() ([]LineDifferrence, []LineDifferrence) { - destDiff := []LineDifferrence{} +func (f *DiffChecker) srcEmpty() *Diff { + diffs := []LineDifferrence{} for index, line := range f.dstLines { - destDiff = append(destDiff, LineDifferrence{Line: line, Operation: insert, Number: index + 1}) + diffs = append(diffs, LineDifferrence{DestLine: line, DestOperation: insert, DestNumber: index + 1}) } - return make([]LineDifferrence, 0), destDiff + return &Diff{ + Diffs: diffs, + MissingSrc: true, + } } // getFileContent reads and returns the lines of a file given its path. diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index f0aa88ad42b..9b1b4c5e51c 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -2,7 +2,6 @@ package main import ( "os" - "slices" "strings" ) @@ -24,11 +23,10 @@ type Differences struct { // FileDifference represents the differences between source and destination files. type FileDifference struct { - Status string // Diff status of the processed files. - SourceName string // Name of the source file. - DestinationName string // Name of the destination file. - SrcLineDiff []LineDifferrence // Differences in source file lines. - DstLineDiff []LineDifferrence // Differences in destination file lines. + Status string // Diff status of the processed files. + SourceName string // Name of the source file. + DestinationName string // Name of the destination file. + LineDiffferrences []LineDifferrence // Differences in source file lines. } // NewPackageDiffChecker creates a new PackageDiffChecker instance with the specified @@ -71,19 +69,18 @@ func (p *PackageDiffChecker) Differences() (*Differences, error) { dstFileName := trimmedFileName + dstFileExt dstFilePath := p.DstPath + "/" + dstFileName - fileDiff, err := NewFileDiff(srcFilePath, dstFilePath) + diffChecker, err := NewDiffChecker(srcFilePath, dstFilePath) if err != nil { return nil, err } - srcDiff, dstDiff := fileDiff.Differences() + diff := diffChecker.Differences() d.FilesDifferences = append(d.FilesDifferences, FileDifference{ - Status: p.getStatus(srcDiff, dstDiff).String(), - SourceName: srcFileName, - DestinationName: dstFileName, - SrcLineDiff: srcDiff, - DstLineDiff: dstDiff, + Status: p.getStatus(diff).String(), + SourceName: srcFileName, + DestinationName: dstFileName, + LineDiffferrences: diff.Diffs, }) } @@ -126,25 +123,22 @@ func (p *PackageDiffChecker) inferFileExtensions() (string, string) { // getStatus determines the diff status based on the differences in source and destination. // It returns a diffStatus indicating whether there is no difference, missing in source, missing in destination, or differences exist. -func (p *PackageDiffChecker) getStatus(srcDiff, dstDiff []LineDifferrence) diffStatus { - slicesAreEquals := slices.Equal(srcDiff, dstDiff) - if slicesAreEquals { - return noDiff - } - - if len(srcDiff) == 0 { +func (p *PackageDiffChecker) getStatus(diff *Diff) diffStatus { + if diff.MissingSrc { return missingInSrc } - if len(dstDiff) == 0 { + if diff.MissingDst { return missingInDst } - if !slicesAreEquals { - return hasDiff + for _, diff := range diff.Diffs { + if diff.SrcOperation == delete || diff.DestOperation == insert { + return hasDiff + } } - return 0 + return noDiff } // hasSameNumberOfFiles checks if the source and destination have the same number of files. diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index 9ae5a63be53..5579ead6252 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -65,11 +65,25 @@ func NewReportBuilder(srcPath, dstPath, outDir string, srcIsGno bool) (*ReportBu return nil, err } + realSrcPath, err := getRealPath(srcPath) + if err != nil { + return nil, err + } + + realDstPath, err := getRealPath(dstPath) + if err != nil { + return nil, err + } + + realOutPath, err := getRealPath(outDir) + if err != nil { + return nil, err + } return &ReportBuilder{ // Trim suffix / in order to standardize paths accept path with or without `/` - SrcPath: strings.TrimSuffix(srcPath, `/`), - DstPath: strings.TrimSuffix(dstPath, `/`), - OutDir: strings.TrimSuffix(outDir, `/`), + SrcPath: strings.TrimSuffix(realSrcPath, `/`), + DstPath: strings.TrimSuffix(realDstPath, `/`), + OutDir: strings.TrimSuffix(realOutPath, `/`), SrcIsGno: srcIsGno, packageTemplate: packageTemplate, indexTemplate: indexTemplate, @@ -262,3 +276,22 @@ func (builder *ReportBuilder) writePackageTemplate(templateData any, packageName return nil } + +// getRealPath will check if the directory is a symbolic link and resolve if path before returning it +func getRealPath(path string) (string, error) { + info, err := os.Lstat(path) + if err != nil { + return "", err + } + + if info.Mode()&fs.ModeSymlink != 0 { + // File is symbolic link, no need to resolve + link, err := os.Readlink(path) + if err != nil { + return "", fmt.Errorf("can't resolve symbolic link: %w", err) + } + return link, nil + } + + return path, nil +} diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index 6a41cf38db3..f63e7f4617c 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -1,24 +1,42 @@ {{define "file-viewer" }}
    - {{- range .}} - {{- if eq .Operation 1}} -
    - {{.Number}}

    {{.Line}}

    -
    - {{- else if eq .Operation 2}} -
    - {{.Number}}

    {{.Line}}

    +
    + {{- range .}} + {{- if eq .SrcOperation 2}} +
    + {{.SrcNumber}}

    {{.SrcLine}}

    +
    + + {{- else if eq .SrcOperation 3}} +
    + {{.SrcNumber}} +

    {{.SrcLine}}

    +
    + {{- else}} +
    +

    +
    + {{- end}} + {{- end}}
    - - {{- else if eq .Operation 3}} -
    - {{.Number}} -

    {{.Line}}

    +
    +
    +
    + {{- range .}} + {{- if eq .DestOperation 1}} +
    + {{.DestNumber}}

    {{.DestLine}}

    +
    + {{- else if eq .DestOperation 3}} +
    + {{.DestNumber}} +

    {{.DestLine}}

    +
    + {{- else}} +

    + {{- end}} + {{- end}}
    - {{- else}} -

    {{.Line}}

    - {{- end}} - {{- end}}
    {{end}} @@ -87,18 +105,21 @@

    Number of files

{{- range .FilesDifferences}} -
- {{.SourceName}} ({{.Status}}) + {{- if eq .Status "files differ"}} +
+ {{.SourceName}} ({{.Status}}) + {{- else if eq .Status "missing in dst"}} +
+ {{.SourceName}} ({{.Status}}) ➖ + {{- else if eq .Status "missing in src"}} +
+ {{.SourceName}} ({{.Status}}) ➕ + {{- else}} +
+ {{.SourceName}} ({{.Status}}) + {{- end}}
-
-

{{.SourceName}}

- {{template "file-viewer" .SrcLineDiff}} -
- -
-

{{.DestinationName}}

- {{template "file-viewer" .DstLineDiff}} -
+ {{template "file-viewer" .LineDiffferrences}}
{{- end}} From 400a2235ba51de7a829392c4d288f877e4301a3c Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sun, 27 Oct 2024 21:18:43 +0100 Subject: [PATCH 30/35] Add std dir --- misc/stdlib_diff/packagediff.go | 4 +- misc/stdlib_diff/report.go | 100 +++++++++++------- .../stdlib_diff/templates/index_template.html | 29 ++--- 3 files changed, 83 insertions(+), 50 deletions(-) diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index 9b1b4c5e51c..321e24a8f45 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -150,7 +150,7 @@ func (p *PackageDiffChecker) hasSameNumberOfFiles() bool { func listDirFiles(dirPath string) ([]string, error) { fileNames := make([]string, 0) dirEntries, err := os.ReadDir(dirPath) - if err != nil { + if err != nil && !os.IsNotExist(err) { return nil, err } @@ -162,5 +162,5 @@ func listDirFiles(dirPath string) ([]string, error) { fileNames = append(fileNames, dirEntry.Name()) } - return fileNames, err + return fileNames, nil } diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index 5579ead6252..69c3d26db36 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -8,6 +8,7 @@ import ( "io/fs" "os" "path/filepath" + "slices" "strings" ) @@ -47,7 +48,8 @@ type IndexTemplate struct { type LinkToReport struct { PathToReport string PackageName string - WasFound bool + MissingGo bool + MissingGno bool Subdirectories []LinkToReport } @@ -95,7 +97,7 @@ func NewReportBuilder(srcPath, dstPath, outDir string, srcIsGno bool) (*ReportBu // differences using PackageDiffChecker, and generates reports using the // packageTemplate. func (builder *ReportBuilder) Build() error { - directories, err := builder.listSrcDirectories() + directories, err := builder.listDirectories() if err != nil { return err } @@ -111,7 +113,8 @@ func (builder *ReportBuilder) Build() error { report := LinkToReport{ PathToReport: "./" + directory.Path + "/report.html", PackageName: directory.Path, - WasFound: directory.FoundInDest, + MissingGno: !directory.FoundInDest, + MissingGo: !directory.FoundInSrc, Subdirectories: make([]LinkToReport, 0), } for _, subDirectory := range directory.Children { @@ -121,7 +124,8 @@ func (builder *ReportBuilder) Build() error { report.Subdirectories = append(report.Subdirectories, LinkToReport{ PathToReport: "./" + subDirectory.Path + "/report.html", PackageName: subDirectory.Path, - WasFound: subDirectory.FoundInDest, + MissingGno: !subDirectory.FoundInDest, + MissingGo: !subDirectory.FoundInSrc, }) } @@ -168,44 +172,34 @@ func (builder *ReportBuilder) ExecuteDiffTemplate(directory *Directory) error { type Directory struct { Path string FoundInDest bool + FoundInSrc bool Children []*Directory } -// listSrcDirectories retrieves a list of directories in the source path. -func (builder *ReportBuilder) listSrcDirectories() ([]*Directory, error) { - destDirectories, err := builder.getDstDirectories() +// listDirectories retrieves a list of directories in the source path. +func (builder *ReportBuilder) listDirectories() ([]*Directory, error) { + allSubdirectories, srcDirectories, destDirectories, err := builder.findDirectories() + if err != nil { return nil, err } - notfoundInDest := []string{} + notfound := []string{} directories := make(map[string]*Directory) res := make([]*Directory, 0) - err = filepath.WalkDir(builder.SrcPath, func(path string, dirEntry fs.DirEntry, err error) error { - if path == builder.SrcPath { - return nil - } - - folderName := strings.TrimPrefix(path, builder.SrcPath+"/") - - // skip directories that are not found in the destination - for _, prefix := range notfoundInDest { - if strings.HasPrefix(folderName, prefix) { - return nil - } - } - - if err != nil { - return err - } - if !dirEntry.IsDir() { - return nil + for _, folderName := range allSubdirectories { + if slices.ContainsFunc(notfound, func(s string) bool { + return strings.HasPrefix(folderName, s) + }) { + // this directory is not found in either source or destination skipping subsdirectories + continue } newDir := &Directory{ Path: folderName, FoundInDest: destDirectories[folderName], + FoundInSrc: srcDirectories[folderName], Children: make([]*Directory, 0), } @@ -218,11 +212,10 @@ func (builder *ReportBuilder) listSrcDirectories() ([]*Directory, error) { directories[getRootFolder(folderName)] = directory } - if !destDirectories[dirEntry.Name()] { - notfoundInDest = append(notfoundInDest, folderName) + if !newDir.FoundInDest && !newDir.FoundInSrc { + notfound = append(notfound, folderName) } - return nil - }) + } return res, err } @@ -232,12 +225,16 @@ func isRootFolder(path string) bool { func getRootFolder(path string) string { return strings.Split(path, "/")[0] } -func (builder *ReportBuilder) getDstDirectories() (map[string]bool, error) { - directories := make(map[string]bool) - err := filepath.WalkDir(builder.DstPath, func(path string, dirEntry fs.DirEntry, err error) error { +func (builder *ReportBuilder) getAllSubdirectories(rootPath string) ([]string, error) { + directories := make([]string, 0) + err := filepath.WalkDir(rootPath, func(path string, dirEntry fs.DirEntry, err error) error { + if path == rootPath { + return nil + } + if dirEntry.IsDir() { - folderName := strings.TrimPrefix(path, builder.DstPath+"/") - directories[folderName] = true + folderName := strings.TrimPrefix(path, rootPath+"/") + directories = append(directories, folderName) } return nil }) @@ -295,3 +292,34 @@ func getRealPath(path string) (string, error) { return path, nil } + +func (builder *ReportBuilder) findDirectories() ([]string, map[string]bool, map[string]bool, error) { + destDirectories, err := builder.getAllSubdirectories(builder.DstPath) + if err != nil { + return nil, nil, nil, err + } + + srcDirectories, err := builder.getAllSubdirectories(builder.SrcPath) + if err != nil { + return nil, nil, nil, err + } + + res := make([]string, 0, len(srcDirectories)+len(destDirectories)) + srcMap := make(map[string]bool) + dstMap := make(map[string]bool) + for _, path := range srcDirectories { + res = append(res, path) + srcMap[path] = true + } + + for _, path := range destDirectories { + dstMap[path] = true + if !srcMap[path] { + res = append(res, path) + } + } + + slices.Sort(res) + + return res, srcMap, dstMap, nil +} diff --git a/misc/stdlib_diff/templates/index_template.html b/misc/stdlib_diff/templates/index_template.html index bdddf3592db..9d7d687b5ab 100644 --- a/misc/stdlib_diff/templates/index_template.html +++ b/misc/stdlib_diff/templates/index_template.html @@ -45,7 +45,11 @@

List of packages processed

    {{- range .Reports}} - {{- if .WasFound}} + {{- if .MissingGno}} +
  • {{.PackageName}}

    : missing in gno + {{- else if .MissingGo}} +
  • {{.PackageName}}

    : missing in go + {{- else}} {{if .Subdirectories}}
    {{.PackageName}} @@ -53,23 +57,24 @@

    List of packages processed

  • {{.PackageName}}
{{- range .Subdirectories}} - {{- if .WasFound}} - + {{- if .MissingGno}} +
    +
  • {{.PackageName}}

    : missing in gno
  • +
+ {{- else if .MissingGo}} +
    +
  • {{.PackageName}}

    : missing in go
  • +
{{- else}} -
    -
  • {{.PackageName}}

    : missing in go
  • -
+ {{- end}} {{- end}}
{{- else}} - {{.PackageName}} - + {{.PackageName}}
{{- end}} - {{- else}} -
  • {{.PackageName}}

    : missing in gno {{- end}}
  • {{- end}} From ece75f99dec392ae7d4ac405922938a8b9a776c6 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sun, 27 Oct 2024 21:43:56 +0100 Subject: [PATCH 31/35] Remove container when file is empty --- .../templates/package_diff_template.html | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index f63e7f4617c..b582253d412 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -1,43 +1,47 @@ {{define "file-viewer" }} -
    -
    - {{- range .}} - {{- if eq .SrcOperation 2}} -
    - {{.SrcNumber}}

    {{.SrcLine}}

    -
    - - {{- else if eq .SrcOperation 3}} -
    - {{.SrcNumber}} -

    {{.SrcLine}}

    -
    - {{- else}} -
    -

    -
    +{{if ne .Status "missing in src"}} +
    +
    + {{- range .LineDiffferrences}} + {{- if eq .SrcOperation 2}} +
    + {{.SrcNumber}}

    {{.SrcLine}}

    +
    + + {{- else if eq .SrcOperation 3}} +
    + {{.SrcNumber}} +

    {{.SrcLine}}

    +
    + {{- else}} +
    +

    +
    + {{- end}} {{- end}} - {{- end}} +
    -
    -
    -
    - {{- range .}} - {{- if eq .DestOperation 1}} -
    - {{.DestNumber}}

    {{.DestLine}}

    -
    - {{- else if eq .DestOperation 3}} -
    - {{.DestNumber}} -

    {{.DestLine}}

    +{{end}} + {{if ne .Status "missing in dst"}} +
    +
    + {{- range .LineDiffferrences}} + {{- if eq .DestOperation 1}} +
    + {{.DestNumber}}

    {{.DestLine}}

    +
    + {{- else if eq .DestOperation 3}} +
    + {{.DestNumber}} +

    {{.DestLine}}

    +
    + {{- else}} +

    + {{- end}} + {{- end}}
    - {{- else}} -

    - {{- end}} - {{- end}} -
    -
    +
    + {{end}} {{end}} @@ -119,7 +123,7 @@

    Number of files

    {{.SourceName}} ({{.Status}}) {{- end}}
    - {{template "file-viewer" .LineDiffferrences}} + {{template "file-viewer" .}}
    {{- end}} From 2ff4f9e995834174744026cc5dfa57aa4e3573e7 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sat, 14 Dec 2024 08:07:02 -0500 Subject: [PATCH 32/35] fix comments on review --- misc/stdlib_diff/README.md | 7 ++-- misc/stdlib_diff/main.go | 4 +-- misc/stdlib_diff/packagediff.go | 23 +++++++++---- misc/stdlib_diff/report.go | 32 ++++--------------- .../templates/package_diff_template.html | 3 +- 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/misc/stdlib_diff/README.md b/misc/stdlib_diff/README.md index 9b05deaed03..32c3cbcd93d 100644 --- a/misc/stdlib_diff/README.md +++ b/misc/stdlib_diff/README.md @@ -1,6 +1,6 @@ -# Stdlibs_diff +# stdlibs_diff -Stdlibs_diff is a tool that generates an html report indicating differences between gno standard libraries and go standrad libraries +stdlibs_diff is a tool that generates an html report indicating differences between gno standard libraries and go standrad libraries ## Usage @@ -13,7 +13,7 @@ Compare the `go` standard libraries the `gno` standard libraries Compare the `gno` standard libraries the `go` standard libraries ```shell -./stdlibs_diff -src -dst -out -src_is_gno +./stdlibs_diff -src -dst -out ``` @@ -24,7 +24,6 @@ Compare the `gno` standard libraries the `go` standard libraries | src | Directory containing packages that will be compared to destination | None | | dst | Directory containing packages; used to compare src packages | None | | out | Directory where the report will be created | None | -| src_is_gno | Indicates if the src parameters is the gno standard library | false | ## Tips diff --git a/misc/stdlib_diff/main.go b/misc/stdlib_diff/main.go index fd95ecd5a17..0b29abd18fd 100644 --- a/misc/stdlib_diff/main.go +++ b/misc/stdlib_diff/main.go @@ -9,15 +9,13 @@ func main() { var srcPath string var dstPath string var outDirectory string - var srcIsGno bool flag.StringVar(&srcPath, "src", "", "Directory containing packages that will be compared to destination") flag.StringVar(&dstPath, "dst", "", "Directory containing packages; used to compare src packages") flag.StringVar(&outDirectory, "out", "", "Directory where the report will be created") - flag.BoolVar(&srcIsGno, "src_is_gno", false, "If true, indicates that the src parameter corresponds to the gno standard libraries") flag.Parse() - reportBuilder, err := NewReportBuilder(srcPath, dstPath, outDirectory, srcIsGno) + reportBuilder, err := NewReportBuilder(srcPath, dstPath, outDirectory) if err != nil { log.Fatal("can't build report builder: ", err.Error()) } diff --git a/misc/stdlib_diff/packagediff.go b/misc/stdlib_diff/packagediff.go index 321e24a8f45..f99578874b5 100644 --- a/misc/stdlib_diff/packagediff.go +++ b/misc/stdlib_diff/packagediff.go @@ -2,6 +2,7 @@ package main import ( "os" + "path/filepath" "strings" ) @@ -12,7 +13,6 @@ type PackageDiffChecker struct { SrcPath string // Source directory path. DstFiles []string // List of destination files. DstPath string // Destination directory path. - SrcIsGno bool // Indicates if the SrcFiles are gno files. } // Differences represents the differences between source and destination packages. @@ -32,7 +32,7 @@ type FileDifference struct { // NewPackageDiffChecker creates a new PackageDiffChecker instance with the specified // source and destination paths. It initializes the SrcFiles and DstFiles fields by // listing files in the corresponding directories. -func NewPackageDiffChecker(srcPath, dstPath string, srcIsGno bool) (*PackageDiffChecker, error) { +func NewPackageDiffChecker(srcPath, dstPath string) (*PackageDiffChecker, error) { srcFiles, err := listDirFiles(srcPath) if err != nil { return nil, err @@ -48,7 +48,6 @@ func NewPackageDiffChecker(srcPath, dstPath string, srcIsGno bool) (*PackageDiff SrcPath: srcPath, DstFiles: dstFiles, DstPath: dstPath, - SrcIsGno: srcIsGno, }, nil } @@ -114,11 +113,20 @@ func (p *PackageDiffChecker) listAllPossibleFiles() []string { // inferFileExtensions by returning the src and dst files extensions. func (p *PackageDiffChecker) inferFileExtensions() (string, string) { - if p.SrcIsGno { - return ".gno", ".go" + var goFiles, gnoFiles int + for _, file := range p.SrcFiles { + switch filepath.Ext(file) { + case ".go": + goFiles++ + case ".gno": + gnoFiles++ + } + } + if goFiles > gnoFiles { + return ".go", ".gno" } - return ".go", ".gno" + return ".gno", ".go" } // getStatus determines the diff status based on the differences in source and destination. @@ -155,6 +163,9 @@ func listDirFiles(dirPath string) ([]string, error) { } for _, dirEntry := range dirEntries { + if dirEntry.IsDir() { + continue + } // Only list .go and .gno files if !strings.Contains(dirEntry.Name(), ".go") && !strings.Contains(dirEntry.Name(), ".gno") { continue diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index 69c3d26db36..a0e124e7efa 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -25,7 +25,6 @@ type ReportBuilder struct { SrcPath string // Source directory path. DstPath string // Destination directory path. OutDir string // Output directory path for the reports. - SrcIsGno bool // Indicates if the Src files are gno files. packageTemplate *template.Template // Template for generating reports. indexTemplate *template.Template // Template for generating index file of the reports. } @@ -56,7 +55,7 @@ type LinkToReport struct { // NewReportBuilder creates a new ReportBuilder instance with the specified // source path, destination path, and output directory. It also initializes // the packageTemplate using the provided HTML template file. -func NewReportBuilder(srcPath, dstPath, outDir string, srcIsGno bool) (*ReportBuilder, error) { +func NewReportBuilder(srcPath, dstPath, outDir string) (*ReportBuilder, error) { packageTemplate, err := template.New("").Parse(packageDiffTemplate) if err != nil { return nil, err @@ -67,17 +66,18 @@ func NewReportBuilder(srcPath, dstPath, outDir string, srcIsGno bool) (*ReportBu return nil, err } - realSrcPath, err := getRealPath(srcPath) + //filepath.EvalSymlinks will return the original path if there are no simlinks associated to the given path + realSrcPath, err := filepath.EvalSymlinks(srcPath) if err != nil { return nil, err } - realDstPath, err := getRealPath(dstPath) + realDstPath, err := filepath.EvalSymlinks(dstPath) if err != nil { return nil, err } - realOutPath, err := getRealPath(outDir) + realOutPath, err := filepath.EvalSymlinks(outDir) if err != nil { return nil, err } @@ -86,7 +86,6 @@ func NewReportBuilder(srcPath, dstPath, outDir string, srcIsGno bool) (*ReportBu SrcPath: strings.TrimSuffix(realSrcPath, `/`), DstPath: strings.TrimSuffix(realDstPath, `/`), OutDir: strings.TrimSuffix(realOutPath, `/`), - SrcIsGno: srcIsGno, packageTemplate: packageTemplate, indexTemplate: indexTemplate, }, nil @@ -147,7 +146,7 @@ func (builder *ReportBuilder) ExecuteDiffTemplate(directory *Directory) error { srcPackagePath := builder.SrcPath + "/" + directory.Path dstPackagePath := builder.DstPath + "/" + directory.Path - packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath, builder.SrcIsGno) + packageChecker, err := NewPackageDiffChecker(srcPackagePath, dstPackagePath) if err != nil { return fmt.Errorf("can't create new PackageDiffChecker: %w", err) } @@ -274,25 +273,6 @@ func (builder *ReportBuilder) writePackageTemplate(templateData any, packageName return nil } -// getRealPath will check if the directory is a symbolic link and resolve if path before returning it -func getRealPath(path string) (string, error) { - info, err := os.Lstat(path) - if err != nil { - return "", err - } - - if info.Mode()&fs.ModeSymlink != 0 { - // File is symbolic link, no need to resolve - link, err := os.Readlink(path) - if err != nil { - return "", fmt.Errorf("can't resolve symbolic link: %w", err) - } - return link, nil - } - - return path, nil -} - func (builder *ReportBuilder) findDirectories() ([]string, map[string]bool, map[string]bool, error) { destDirectories, err := builder.getAllSubdirectories(builder.DstPath) if err != nil { diff --git a/misc/stdlib_diff/templates/package_diff_template.html b/misc/stdlib_diff/templates/package_diff_template.html index b582253d412..f7b0d90a03b 100644 --- a/misc/stdlib_diff/templates/package_diff_template.html +++ b/misc/stdlib_diff/templates/package_diff_template.html @@ -53,6 +53,7 @@ - +

    {{ .PackageName }} package differences

    From 14ed42a68398a0a0c48836c67c67d360cdb9d195 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sat, 14 Dec 2024 08:48:40 -0500 Subject: [PATCH 33/35] create output dir if not exists --- misc/stdlib_diff/report.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/misc/stdlib_diff/report.go b/misc/stdlib_diff/report.go index a0e124e7efa..6ad9d002d53 100644 --- a/misc/stdlib_diff/report.go +++ b/misc/stdlib_diff/report.go @@ -3,6 +3,7 @@ package main import ( "bytes" _ "embed" + "errors" "fmt" "html/template" "io/fs" @@ -79,7 +80,15 @@ func NewReportBuilder(srcPath, dstPath, outDir string) (*ReportBuilder, error) { realOutPath, err := filepath.EvalSymlinks(outDir) if err != nil { - return nil, err + if !errors.Is(err, fs.ErrNotExist) { + return nil, err + } + // Create output if not exist + err = os.MkdirAll(outDir, 0777) + if err != nil { + return nil, err + } + realOutPath = outDir } return &ReportBuilder{ // Trim suffix / in order to standardize paths accept path with or without `/` From 2e2b2c2a0cf71e9f17caf91421d2cb17b889ebc1 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sat, 14 Dec 2024 09:26:28 -0500 Subject: [PATCH 34/35] github pages action --- .github/workflows/gh-pages.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 1b955b52cd0..686098e5a0f 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -25,11 +25,16 @@ jobs: with: go-version-file: go.mod - run: "cd misc/gendocs && make install gen" + - run: "cd misc/stdlib_diff && make install gen" + -run | # Combine files into a single directory for deployment + mkdir -p output/combined + cp -r ./misc/gendocs/godoc/* output/combined/ + cp -r ./misc/stdlib_diff/gnoreport/* output/combined/gnoreport - uses: actions/configure-pages@v5 id: pages - uses: actions/upload-pages-artifact@v3 with: - path: ./misc/gendocs/godoc + path: ./output/combined deploy: if: ${{ github.repository == 'gnolang/gno' }} # Alternatively, validate based on provided tokens and permissions. From 4f4dfb05afa923a205ee4880230addfb7bf42561 Mon Sep 17 00:00:00 2001 From: Miguel Victoria Date: Sat, 14 Dec 2024 09:30:46 -0500 Subject: [PATCH 35/35] action on pull --- .github/.fossa.yml | 15 - .github/codecov.yml | 46 -- .github/dependabot.yml | 35 - .github/golangci.yml | 85 --- .github/goreleaser.yaml | 753 -------------------- .github/labeler.yml | 24 - .github/workflows/auto-author-assign.yml | 18 - .github/workflows/autocounterd.yml | 50 -- .github/workflows/benchmark-master-push.yml | 70 -- .github/workflows/bot.yml | 93 --- .github/workflows/build_template.yml | 31 - .github/workflows/codeql.yml | 89 --- .github/workflows/contribs.yml | 30 - .github/workflows/dependabot-tidy.yml | 41 -- .github/workflows/dependabot-validate.yml | 13 - .github/workflows/deploy-docs.yml | 22 - .github/workflows/docs.yml | 34 - .github/workflows/examples.yml | 103 --- .github/workflows/fossa.yml | 43 -- .github/workflows/genesis-verify.yml | 57 -- .github/workflows/gh-pages.yml | 2 +- .github/workflows/gnofmt_template.yml | 24 - .github/workflows/gnoland.yml | 18 - .github/workflows/gnovm.yml | 23 - .github/workflows/labeler.yml | 13 - .github/workflows/lint-pr-title.yml | 20 - .github/workflows/lint_template.yml | 28 - .github/workflows/main_template.yml | 41 -- .github/workflows/misc.yml | 29 - .github/workflows/mod-tidy.yml | 26 - .github/workflows/portal-loop.yml | 104 --- .github/workflows/releaser-master.yml | 49 -- .github/workflows/releaser-nightly.yml | 46 -- .github/workflows/releaser.yml | 45 -- .github/workflows/stale-bot.yml | 23 - .github/workflows/test_template.yml | 84 --- .github/workflows/tm2.yml | 17 - 37 files changed, 1 insertion(+), 2243 deletions(-) delete mode 100644 .github/.fossa.yml delete mode 100644 .github/codecov.yml delete mode 100644 .github/dependabot.yml delete mode 100644 .github/golangci.yml delete mode 100644 .github/goreleaser.yaml delete mode 100644 .github/labeler.yml delete mode 100644 .github/workflows/auto-author-assign.yml delete mode 100644 .github/workflows/autocounterd.yml delete mode 100644 .github/workflows/benchmark-master-push.yml delete mode 100644 .github/workflows/bot.yml delete mode 100644 .github/workflows/build_template.yml delete mode 100644 .github/workflows/codeql.yml delete mode 100644 .github/workflows/contribs.yml delete mode 100644 .github/workflows/dependabot-tidy.yml delete mode 100644 .github/workflows/dependabot-validate.yml delete mode 100644 .github/workflows/deploy-docs.yml delete mode 100644 .github/workflows/docs.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/fossa.yml delete mode 100644 .github/workflows/genesis-verify.yml delete mode 100644 .github/workflows/gnofmt_template.yml delete mode 100644 .github/workflows/gnoland.yml delete mode 100644 .github/workflows/gnovm.yml delete mode 100644 .github/workflows/labeler.yml delete mode 100644 .github/workflows/lint-pr-title.yml delete mode 100644 .github/workflows/lint_template.yml delete mode 100644 .github/workflows/main_template.yml delete mode 100644 .github/workflows/misc.yml delete mode 100644 .github/workflows/mod-tidy.yml delete mode 100644 .github/workflows/portal-loop.yml delete mode 100644 .github/workflows/releaser-master.yml delete mode 100644 .github/workflows/releaser-nightly.yml delete mode 100644 .github/workflows/releaser.yml delete mode 100644 .github/workflows/stale-bot.yml delete mode 100644 .github/workflows/test_template.yml delete mode 100644 .github/workflows/tm2.yml diff --git a/.github/.fossa.yml b/.github/.fossa.yml deleted file mode 100644 index d639b393e98..00000000000 --- a/.github/.fossa.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: 3 - -# https://github.com/fossas/fossa-cli/blob/master/docs/references/files/fossa-yml.md - -project: - id: github.com/gnolang/gno - name: gno - -targets: - only: - - type: gomod - -paths: - exclude: - - ./misc/ diff --git a/.github/codecov.yml b/.github/codecov.yml deleted file mode 100644 index d1ecba7ade3..00000000000 --- a/.github/codecov.yml +++ /dev/null @@ -1,46 +0,0 @@ -codecov: - require_ci_to_pass: true - notify: - wait_for_ci: true - -comment: - require_changes: false - -coverage: - round: down - precision: 2 - status: - project: - default: - target: auto - threshold: 10 # Let's decrease this later. - base: parent - if_no_uploads: error - if_not_found: success - if_ci_failed: error - only_pulls: false - patch: - default: - target: auto - threshold: 10 # Let's decrease this later. - base: auto - if_no_uploads: error - if_not_found: success - if_ci_failed: error - only_pulls: false - -flag_management: - default_rules: - carryforward: true - statuses: - - type: project - target: auto - threshold: 10 # Let's decrease this later. - - type: patch - target: auto # Let's decrease this later. - threshold: 10 - -ignore: - - "gnovm/stdlibs/generated.go" - - "gnovm/tests/stdlibs/generated.go" - - "**/*.pb.go" diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 6a2a2966370..00000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,35 +0,0 @@ -version: 2 -updates: - - # Maintain dependencies for GitHub Actions - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "daily" - labels: - - "github_actions" - groups: - actions: - patterns: - - "*" - - # Maintain dependencies for top level Go modules - - package-ecosystem: gomod - directory: / - target-branch: "master" - schedule: - interval: weekly - labels: - - "dependencies" - groups: - golang-x: - patterns: - - "golang.org/x/*" - everything-else: - patterns: - - "*" - open-pull-requests-limit: 10 - pull-request-branch-name: - separator: "-" - reviewers: - - "moul" diff --git a/.github/golangci.yml b/.github/golangci.yml deleted file mode 100644 index b8bd5537135..00000000000 --- a/.github/golangci.yml +++ /dev/null @@ -1,85 +0,0 @@ -run: - concurrency: 8 - timeout: 10m - issue-exit-code: 1 - tests: true - skip-dirs-use-default: true - modules-download-mode: readonly - allow-parallel-runners: false - go: "" - -output: - uniq-by-line: false - path-prefix: "" - sort-results: true - -linters: - fast: false - disable-all: true - enable: - - whitespace # Tool for detection of leading and trailing whitespace - - unconvert # Unnecessary type conversions - - tparallel # Detects inappropriate usage of t.Parallel() method in your Go test codes - - thelper # Detects golang test helpers without t.Helper() call and checks the consistency of test helpers - - stylecheck # Stylecheck is a replacement for golint - - prealloc # Finds slice declarations that could potentially be pre-allocated - - predeclared # Finds code that shadows one of Go's predeclared identifiers - - nolintlint # Ill-formed or insufficient nolint directives - - misspell # Misspelled English words in comments - - makezero # Finds slice declarations with non-zero initial length - - importas # Enforces consistent import aliases - - govet # same as 'go vet' - - gosec # Security problems - - gofmt # Whether the code was gofmt-ed - - goimports # Unused imports - - goconst # Repeated strings that could be replaced by a constant - - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) - - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error - - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13 - - gofumpt # Stricter gofmt - - unused # Checks Go code for unused constants, variables, functions and types - - gomodguard # Enforces an allow and block list for direct Go module dependencies - - forbidigo # Forbids some custom-set identifiers, like regexp.MatchString - -linters-settings: - gofmt: - simplify: true - goconst: - min-len: 3 - min-occurrences: 3 - gosec: - excludes: - - G204 # Subprocess launched with a potential tainted input or cmd arguments - - G306 # Expect WriteFile permissions to be 0600 or less - - G115 # Integer overflow conversion, no solution to check the overflow in time of convert, so linter shouldn't check the overflow. - stylecheck: - checks: [ "all", "-ST1022", "-ST1003" ] - errorlint: - asserts: false - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - forbidigo: - forbid: - - p: '^regexp\.(Match|MatchString)$' - msg: it will re-compile the regexp for each execution; compile the regexp with regexp.Compile and store it as a singleton - -issues: - whole-files: true - max-issues-per-linter: 0 - max-same-issues: 0 - new: false - fix: false - exclude-rules: - - path: _test\.go - linters: - - gosec # Disabled linting of weak number generators - - makezero # Disabled linting of intentional slice appends - - goconst # Disabled linting of common mnemonics and test case strings - - path: _\.gno - linters: - - errorlint # Disabled linting of error comparisons, because of lacking std lib support diff --git a/.github/goreleaser.yaml b/.github/goreleaser.yaml deleted file mode 100644 index 71a8ba98745..00000000000 --- a/.github/goreleaser.yaml +++ /dev/null @@ -1,753 +0,0 @@ -# yaml-language-server: $schema=https://goreleaser.com/static/schema-pro.json -project_name: gno -version: 2 - -env: - - TAG_VERSION={{ if index .Env "TAG_VERSION" }}{{ .Env.TAG_VERSION }}{{ else }}latest{{ end }} - # supported in next versions -> https://github.com/goreleaser/goreleaser/issues/5059 - # - TAG_VERSION="{{ envOrDefault "TAG_VERSION" "latest" }}" - -before: - hooks: - - go mod tidy - -builds: - - id: gno - main: ./gnovm/cmd/gno - binary: gno - env: - - CGO_ENABLED=0 - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - - arm - goarm: - - "6" - - "7" - - id: gnoland - main: ./gno.land/cmd/gnoland - binary: gnoland - env: - - CGO_ENABLED=0 - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - - arm - goarm: - - "6" - - "7" - - id: gnokey - main: ./gno.land/cmd/gnokey - binary: gnokey - env: - - CGO_ENABLED=0 - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - - arm - goarm: - - "6" - - "7" - - id: gnoweb - main: ./gno.land/cmd/gnoweb - binary: gnoweb - env: - - CGO_ENABLED=0 - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - - arm - goarm: - - "6" - - "7" - - id: gnofaucet - dir: ./contribs/gnofaucet - binary: gnofaucet - env: - - CGO_ENABLED=0 - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - - arm - goarm: - - "6" - - "7" - # Gno Contribs - # NOTE: Contribs binary will be added in a single docker image below: gnocontribs - - id: gnobro - dir: ./contribs/gnodev/cmd/gnobro - binary: gnobro - env: - - CGO_ENABLED=0 - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - - arm - goarm: - - "6" - - "7" - - id: gnogenesis - dir: ./contribs/gnogenesis - binary: gnogenesis - env: - - CGO_ENABLED=0 - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - - arm - goarm: - - "6" - - "7" - -gomod: - proxy: true - -archives: - # https://goreleaser.com/customization/archive/ - - files: - # Standard Release Files - - LICENSE.md - - README.md - -signs: - - cmd: cosign - env: - - COSIGN_EXPERIMENTAL=1 - certificate: "${artifact}.pem" - args: - - sign-blob - - "--output-certificate=${certificate}" - - "--output-signature=${signature}" - - "${artifact}" - - "--yes" # needed on cosign 2.0.0+ - artifacts: checksum - output: true - -dockers: - # https://goreleaser.com/customization/docker/ - - # gno - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: amd64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }}-amd64" - - "ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }}-amd64" - build_flag_templates: - - "--target=gno" - - "--platform=linux/amd64" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gno - extra_files: - - examples - - gnovm/stdlibs - - gnovm/tests/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }}-arm64v8" - - "ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }}-arm64v8" - build_flag_templates: - - "--target=gno" - - "--platform=linux/arm64/v8" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gno - extra_files: - - examples - - gnovm/stdlibs - - gnovm/tests/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 6 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }}-armv6" - - "ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }}-armv6" - build_flag_templates: - - "--target=gno" - - "--platform=linux/arm/v6" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gno - extra_files: - - examples - - gnovm/stdlibs - - gnovm/tests/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 7 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }}-armv7" - - "ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }}-armv7" - build_flag_templates: - - "--target=gno" - - "--platform=linux/arm/v7" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gno - extra_files: - - examples - - gnovm/stdlibs - - gnovm/tests/stdlibs - - # gnoland - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: amd64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }}-amd64" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }}-amd64" - build_flag_templates: - - "--target=gnoland" - - "--platform=linux/amd64" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnoland" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnoland - extra_files: - - gno.land/genesis/genesis_balances.txt - - gno.land/genesis/genesis_txs.jsonl - - examples - - gnovm/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }}-arm64v8" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }}-arm64v8" - build_flag_templates: - - "--target=gnoland" - - "--platform=linux/arm64/v8" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnoland" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnoland - extra_files: - - gno.land/genesis/genesis_balances.txt - - gno.land/genesis/genesis_txs.jsonl - - examples - - gnovm/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 6 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }}-armv6" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }}-armv6" - build_flag_templates: - - "--target=gnoland" - - "--platform=linux/arm/v6" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnoland" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnoland - extra_files: - - gno.land/genesis/genesis_balances.txt - - gno.land/genesis/genesis_txs.jsonl - - examples - - gnovm/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 7 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }}-armv7" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }}-armv7" - build_flag_templates: - - "--target=gnoland" - - "--platform=linux/arm/v7" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnoland" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnoland - extra_files: - - gno.land/genesis/genesis_balances.txt - - gno.land/genesis/genesis_txs.jsonl - - examples - - gnovm/stdlibs - - # gnokey - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: amd64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }}-amd64" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }}-amd64" - build_flag_templates: - - "--target=gnokey" - - "--platform=linux/amd64" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnokey" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnokey - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }}-arm64v8" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }}-arm64v8" - build_flag_templates: - - "--target=gnokey" - - "--platform=linux/arm64/v8" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnokey" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnokey - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 6 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }}-armv6" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }}-armv6" - build_flag_templates: - - "--target=gnokey" - - "--platform=linux/arm/v6" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnokey" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnokey - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 7 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }}-armv7" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }}-armv7" - build_flag_templates: - - "--target=gnokey" - - "--platform=linux/arm/v7" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnokey" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnokey - - # gnoweb - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: amd64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }}-amd64" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }}-amd64" - build_flag_templates: - - "--target=gnoweb" - - "--platform=linux/amd64" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnoweb" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnoweb - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }}-arm64v8" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }}-arm64v8" - build_flag_templates: - - "--target=gnoweb" - - "--platform=linux/arm64/v8" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnoweb" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnoweb - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 6 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }}-armv6" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }}-armv6" - build_flag_templates: - - "--target=gnoweb" - - "--platform=linux/arm/v6" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnoweb" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnoweb - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 7 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }}-armv7" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }}-armv7" - build_flag_templates: - - "--target=gnoweb" - - "--platform=linux/arm/v7" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnoweb" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnoweb - - # gnofaucet - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: amd64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }}-amd64" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-amd64" - build_flag_templates: - - "--target=gnofaucet" - - "--platform=linux/amd64" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnofaucet" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnofaucet - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }}-arm64v8" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-arm64v8" - build_flag_templates: - - "--target=gnofaucet" - - "--platform=linux/arm64/v8" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnofaucet" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnofaucet - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 6 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }}-armv6" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-armv6" - build_flag_templates: - - "--target=gnofaucet" - - "--platform=linux/arm/v6" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnofaucet" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnofaucet - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 7 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }}-armv7" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-armv7" - build_flag_templates: - - "--target=gnofaucet" - - "--platform=linux/arm/v7" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnofaucet" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnofaucet - - # gnocontribs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: amd64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}-amd64" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }}-amd64" - build_flag_templates: - - "--target=gnocontribs" - - "--platform=linux/amd64" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnocontribs" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnobro - - gnogenesis - extra_files: - - gno.land/genesis/genesis_balances.txt - - gno.land/genesis/genesis_txs.jsonl - - examples - - gnovm/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm64 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}-arm64v8" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }}-arm64v8" - build_flag_templates: - - "--target=gnocontribs" - - "--platform=linux/arm64/v8" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnocontribs" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnobro - - gnogenesis - extra_files: - - gno.land/genesis/genesis_balances.txt - - gno.land/genesis/genesis_txs.jsonl - - examples - - gnovm/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 6 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}-armv6" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }}-armv6" - build_flag_templates: - - "--target=gnocontribs" - - "--platform=linux/arm/v6" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnocontribs" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnobro - - gnogenesis - extra_files: - - gno.land/genesis/genesis_balances.txt - - gno.land/genesis/genesis_txs.jsonl - - examples - - gnovm/stdlibs - - use: buildx - dockerfile: Dockerfile.release - goos: linux - goarch: arm - goarm: 7 - image_templates: - - "ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}-armv7" - - "ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }}-armv7" - build_flag_templates: - - "--target=gnocontribs" - - "--platform=linux/arm/v7" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.title={{.ProjectName}}/gnocontribs" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - ids: - - gnobro - - gnogenesis - extra_files: - - gno.land/genesis/genesis_balances.txt - - gno.land/genesis/genesis_txs.jsonl - - examples - - gnovm/stdlibs - -docker_manifests: - # https://goreleaser.com/customization/docker_manifest/ - - # gno - - name_template: ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}:{{ .Version }}-armv7 - - name_template: ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}:{{ .Env.TAG_VERSION }}-armv7 - - # gnoland - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Version }}-armv7 - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoland:{{ .Env.TAG_VERSION }}-armv7 - - # gnokey - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Version }}-armv7 - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnokey:{{ .Env.TAG_VERSION }}-armv7 - - # gnoweb - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Version }}-armv7 - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnoweb:{{ .Env.TAG_VERSION }}-armv7 - - # gnofaucet - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Version }}-armv7 - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnofaucet:{{ .Env.TAG_VERSION }}-armv7 - - # gnocontribs - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Version }}-armv7 - - name_template: ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }} - image_templates: - - ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }}-amd64 - - ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }}-arm64v8 - - ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }}-armv6 - - ghcr.io/gnolang/{{ .ProjectName }}/gnocontribs:{{ .Env.TAG_VERSION }}-armv7 - -docker_signs: - - cmd: cosign - env: - - COSIGN_EXPERIMENTAL=1 - artifacts: images - output: true - args: - - "sign" - - "${artifact}" - - "--yes" # needed on cosign 2.0.0+ - -checksum: - name_template: "checksums.txt" - -changelog: - sort: asc - -source: - enabled: true - -sboms: - - artifacts: archive - - id: source # Two different sbom configurations need two different IDs - artifacts: source - -release: - disable: '{{ if eq .Env.TAG_VERSION "master" }}true{{ else }}false{{ end }}' - skip_upload: '{{ if eq .Env.TAG_VERSION "master" }}true{{ else }}false{{ end }}' - draft: true - replace_existing_draft: true - prerelease: auto - mode: append - footer: | - ### Container Images - - You can find all docker images at: - - https://github.com/orgs/gnolang/packages?repo_name={{ .ProjectName }} - -# Only valid for nightly build -nightly: - tag_name: nightly - publish_release: true - keep_single_release: true - version_template: "{{ incpatch .Version }}-{{ .ShortCommit }}-{{ .Env.TAG_VERSION }}" - -git: - ignore_tag_prefixes: - - "chain/" diff --git a/.github/labeler.yml b/.github/labeler.yml deleted file mode 100644 index 64075fd1860..00000000000 --- a/.github/labeler.yml +++ /dev/null @@ -1,24 +0,0 @@ -":receipt: package/realm": -- changed-files: - - any-glob-to-any-file: - - examples/**/* - -":package: :robot: gnovm": -- changed-files: - - any-glob-to-any-file: - - gnovm/**/* - -":package: :globe_with_meridians: tendermint v2": -- changed-files: - - any-glob-to-any-file: - - tm2/**/* - -":package: :mountain: gno.land": -- changed-files: - - any-glob-to-any-file: - - "gno.land/**/*" - -":book: documentation": -- changed-files: - - any-glob-to-any-file: - - docs/**/*" diff --git a/.github/workflows/auto-author-assign.yml b/.github/workflows/auto-author-assign.yml deleted file mode 100644 index 06dfb4ab903..00000000000 --- a/.github/workflows/auto-author-assign.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: auto-author-assign - -on: - pull_request_target: - types: [ opened, reopened ] - -permissions: - pull-requests: write - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - assign-author: - runs-on: ubuntu-latest - steps: - - uses: toshimaru/auto-author-assign@v2.1.1 diff --git a/.github/workflows/autocounterd.yml b/.github/workflows/autocounterd.yml deleted file mode 100644 index 9217fe2eef2..00000000000 --- a/.github/workflows/autocounterd.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: autocounterd - -on: - pull_request: - branches: - - master - push: - paths: - - misc/autocounterd - - misc/loop - - .github/workflows/autocounterd.yml - branches: - - "master" - - "misc/autocounterd" - tags: - - "v*" - -permissions: - contents: read - packages: write - -jobs: - autocounterd: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Docker metadata autocounterd - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/${{ github.repository }}/autocounterd - tags: | - type=raw,value=latest - type=semver,pattern=v{{version}} - - - name: Build and push - uses: docker/build-push-action@v6 - with: - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/benchmark-master-push.yml b/.github/workflows/benchmark-master-push.yml deleted file mode 100644 index 622baefc0de..00000000000 --- a/.github/workflows/benchmark-master-push.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: run benchmarks when pushing on main branch - -on: - push: - branches: - - master - paths: - - contribs/** - - gno.land/** - - gnovm/** - - tm2/** - -permissions: - # deployments permission to deploy GitHub pages website - deployments: write - # contents permission to update benchmark contents in gh-pages branch - contents: write - -env: - CGO_ENABLED: 0 - -jobs: - benchmarks: - if: ${{ github.repository == 'gnolang/gno' }} - runs-on: [self-hosted, Linux, X64, benchmarks] - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Run benchmark - # add more benchmarks by adding additional lines for different packages; - # or modify the -bench regexp. - run: | - set -xeuo pipefail && ( - go test ./gnovm/pkg/gnolang -bench='BenchmarkBenchdata' -benchmem -run='^$' -v -cpu=1,2 - ) | tee benchmarks.txt - - - name: Download previous benchmark data - uses: actions/cache@v4 - with: - path: ./cache - key: ${{ runner.os }}-benchmark - - - name: Store benchmark results into `gh-benchmarks` branch - uses: benchmark-action/github-action-benchmark@v1 - # see https://github.com/benchmark-action/github-action-benchmark?tab=readme-ov-file#action-inputs - with: - name: Go Benchmarks - tool: "go" - output-file-path: benchmarks.txt - max-items-in-chart: 100 - # Show alert with commit comment on detecting possible performance regression - alert-threshold: "120%" - fail-on-alert: false - comment-on-alert: true - alert-comment-cc-users: "@ajnavarro,@thehowl,@zivkovicmilos" - # Enable Job Summary for PRs - summary-always: true - github-token: ${{ secrets.GITHUB_TOKEN }} - # NOTE you need to use a separate GITHUB PAT token that has a write access to the specified repository. - # gh-repository: 'github.com/gnolang/benchmarks' # on gh-pages branch - gh-pages-branch: gh-benchmarks - benchmark-data-dir-path: . - auto-push: true diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml deleted file mode 100644 index 300a5928e25..00000000000 --- a/.github/workflows/bot.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: GitHub Bot - -on: - # Watch for changes on PR state, assignees, labels, head branch and draft/ready status - pull_request_target: - types: - - assigned - - unassigned - - labeled - - unlabeled - - opened - - reopened - - synchronize # PR head updated - - converted_to_draft - - ready_for_review - - # Watch for changes on PR reviews - pull_request_review: - types: [submitted, edited, dismissed] - - # Watch for changes on PR comment - issue_comment: - types: [created, edited, deleted] - - # Manual run from GitHub Actions interface - workflow_dispatch: - inputs: - pull-request-list: - description: "PR(s) to process: specify 'all' or a comma separated list of PR numbers, e.g. '42,1337,7890'" - required: true - default: all - type: string - -jobs: - # This job creates a matrix of PR numbers based on the inputs from the various - # events that can trigger this workflow so that the process-pr job below can - # handle the parallel processing of the pull-requests - define-prs-matrix: - name: Define PRs matrix - # Prevent bot from retriggering itself and ignore event emitted by codecov - if: ${{ github.actor != vars.GH_BOT_LOGIN && github.actor != 'codecov[bot]' }} - runs-on: ubuntu-latest - permissions: - pull-requests: read - outputs: - pr-numbers: ${{ steps.pr-numbers.outputs.pr-numbers }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version-file: contribs/github-bot/go.mod - - - name: Generate matrix from event - id: pr-numbers - working-directory: contribs/github-bot - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: go run . matrix -matrix-key 'pr-numbers' -verbose - - # This job processes each pull request in the matrix individually while ensuring - # that a same PR cannot be processed concurrently by mutliple runners - process-pr: - name: Process PR - needs: define-prs-matrix - # Just skip this job if PR numbers matrix is empty (prevent failed state) - if: ${{ needs.define-prs-matrix.outputs.pr-numbers != '[]' && needs.define-prs-matrix.outputs.pr-numbers != '' }} - runs-on: ubuntu-latest - strategy: - matrix: - # Run one job for each PR to process - pr-number: ${{ fromJSON(needs.define-prs-matrix.outputs.pr-numbers) }} - concurrency: - # Prevent running concurrent jobs for a given PR number - group: ${{ matrix.pr-number }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version-file: contribs/github-bot/go.mod - - - name: Run GitHub Bot - working-directory: contribs/github-bot - env: - GITHUB_TOKEN: ${{ secrets.GH_BOT_PAT }} - run: go run . check -pr-numbers '${{ matrix.pr-number }}' -verbose diff --git a/.github/workflows/build_template.yml b/.github/workflows/build_template.yml deleted file mode 100644 index a2c96f2d37e..00000000000 --- a/.github/workflows/build_template.yml +++ /dev/null @@ -1,31 +0,0 @@ -on: - workflow_call: - inputs: - modulepath: - required: true - type: string - go-version: - required: true - type: string - -jobs: - generated: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: ${{ inputs.go-version }} - - - name: Check generated files are up to date - working-directory: ${{ inputs.modulepath }} - run: | - go generate -x ./... - if [ "$(git status -s)" != "" ]; then - echo "command 'go generate' creates file that differ from git tree, please run 'go generate' and commit:" - git status -s - exit 1 - fi diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index d2eef9d7445..00000000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,89 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ "master", "chain/*" ] - pull_request: - branches: [ "master", "chain/*" ] - schedule: - - cron: '22 17 * * 3' - -jobs: - analyze: - name: Analyze (${{ matrix.language }}) - # Runner size impacts CodeQL analysis time. To learn more, please see: - # - https://gh.io/recommended-hardware-resources-for-running-codeql - # - https://gh.io/supported-runners-and-hardware-resources - # - https://gh.io/using-larger-runners (GitHub.com only) - # Consider using larger runners or machines with greater resources for possible analysis time improvements. - runs-on: ubuntu-latest - timeout-minutes: 360 - permissions: - # required for all workflows - security-events: write - - # only required for workflows in private repositories - actions: read - contents: read - - strategy: - fail-fast: false - matrix: - include: - - language: go - build-mode: autobuild - # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' - # Use `c-cpp` to analyze code written in C, C++ or both - # Use 'java-kotlin' to analyze code written in Java, Kotlin or both - # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both - # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, - # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. - # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how - # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - build-mode: ${{ matrix.build-mode }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - # If the analyze step fails for one of the languages you are analyzing with - # "We were unable to automatically build your code", modify the matrix above - # to set the build mode to "manual" for that language. Then modify this step - # to build your code. - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - if: matrix.build-mode == 'manual' - run: | - echo 'If you are using a "manual" build mode for one or more of the' \ - 'languages you are analyzing, replace this with the commands to build' \ - 'your code, for example:' - echo ' make bootstrap' - echo ' make release' - exit 1 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" diff --git a/.github/workflows/contribs.yml b/.github/workflows/contribs.yml deleted file mode 100644 index 3739339f7be..00000000000 --- a/.github/workflows/contribs.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: contribs - -on: - push: - branches: - - master - workflow_dispatch: - pull_request: - -jobs: - setup: - runs-on: ubuntu-latest - outputs: - programs: ${{ steps.set-matrix.outputs.programs }} - steps: - - uses: actions/checkout@v4 - - id: set-matrix - run: echo "::set-output name=programs::$(ls -d contribs/*/ | cut -d/ -f2 | jq -R -s -c 'split("\n")[:-1]')" - main: - needs: setup - strategy: - fail-fast: false - matrix: - program: ${{ fromJson(needs.setup.outputs.programs) }} - name: Run Main - uses: ./.github/workflows/main_template.yml - with: - modulepath: contribs/${{ matrix.program }} - secrets: - codecov-token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/dependabot-tidy.yml b/.github/workflows/dependabot-tidy.yml deleted file mode 100644 index 39fed8b0172..00000000000 --- a/.github/workflows/dependabot-tidy.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Dependabot Tidy Go Mods - -on: - pull_request: - paths: - - '.github/workflows/**' - - '**/go.mod' - - '**/go.sum' - -jobs: - tidy_go_mods: - runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} - permissions: - contents: write - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Tidy all Go mods - env: - VERIFY_MOD_SUMS: false - run: | - # Ensure Make is installed - make --version - - # Run the tidy target - make tidy - - - name: Commit changes, if any - uses: stefanzweifel/git-auto-commit-action@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - skip_dirty_check: false # Enable dirty check, and skip unnecessary committing - commit_message: "Run 'go mod tidy' via GitHub Actions" diff --git a/.github/workflows/dependabot-validate.yml b/.github/workflows/dependabot-validate.yml deleted file mode 100644 index b1387dc0bb2..00000000000 --- a/.github/workflows/dependabot-validate.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: dependabot validate - -on: - pull_request: - paths: - - '.github/dependabot.yml' - - '.github/workflows/dependabot-validate.yml' -jobs: - validate: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: marocchino/validate-dependabot@v3 diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml deleted file mode 100644 index d800147a498..00000000000 --- a/.github/workflows/deploy-docs.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: deploy docs on gnolang/docs.gno.land repository -on: - push: - branches: - - master - paths: - - "docs/**" - -jobs: - trigger-netlify-docs-deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.DOCS_DEPLOY_PAT }} - script: | - await github.rest.actions.createWorkflowDispatch({ - owner: 'gnolang', - repo: 'docs.gno.land', - workflow_id: 'netlify.yml', - ref: 'main' - }) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index c9d9af0fb6f..00000000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: "docs / lint" - -on: - push: - paths: - - master - pull_request: - paths: - - "docs/**" - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Install dependencies - run: go mod download - - - name: Build docs - run: make -C docs/ build - - - name: Check diff - run: git diff --exit-code || (echo "Some docs files are not formatted, please run 'make build'." && exit 1) - - - name: Run linter - run: make -C docs/ lint diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 41d579c4567..00000000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,103 +0,0 @@ -name: examples - -on: - pull_request: - push: - branches: ["master"] - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - gno2go: - strategy: - fail-fast: false - matrix: - goversion: - - "1.22.x" - runs-on: ubuntu-latest - timeout-minutes: 30 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.goversion }} - - run: go install -v ./gnovm/cmd/gno - - run: go run ./gnovm/cmd/gno transpile -v --gobuild ./examples - test: - strategy: - fail-fast: false - matrix: - goversion: - - "1.22.x" - # unittests: TODO: matrix with contracts - runs-on: ubuntu-latest - timeout-minutes: 30 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.goversion }} - - name: Set environment variables for debug mode - if: env.ACTIONS_STEP_DEBUG == 'true' - run: | - export LOG_PATH_DIR=${{ runner.temp }}/logs - mkdir -p $LOG_PATH_DIR - echo "LOG_LEVEL=debug" >> $GITHUB_ENV - echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV - - run: go install -v ./gnovm/cmd/gno - - run: go run ./gnovm/cmd/gno test -v -print-runtime-metrics -print-events ./examples/... - lint: - strategy: - fail-fast: false - matrix: - goversion: - - "1.22.x" - # unittests: TODO: matrix with contracts - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.goversion }} - # testing official directories, basically examples/ minus examples/.../x/. - - run: make lint -C ./examples - # TODO: consider running lint on every other directories, maybe in "warning" mode? - # TODO: track coverage - fmt: - strategy: - fail-fast: false - matrix: - goversion: ["1.22.x"] - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.goversion }} - - run: | - make fmt -C ./examples - # Check if there are changes after running make fmt - git diff --exit-code || (echo "Some gno files are not formatted, please run 'make fmt'." && exit 1) - mod-tidy: - strategy: - fail-fast: false - matrix: - go-version: ["1.22.x"] - # unittests: TODO: matrix with contracts - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v4 - - run: | - GNO_CMD="$(pwd)/gnovm/cmd/gno" - # Find all directories containing gno.mod file - find ./examples -name "gno.mod" -execdir go run "$GNO_CMD" mod tidy \; - # Check if there are changes after running gno mod tidy - git diff --exit-code || (echo "Some gno.mod files are not tidy, please run 'make tidy'." && exit 1) diff --git a/.github/workflows/fossa.yml b/.github/workflows/fossa.yml deleted file mode 100644 index 41d9a2cba94..00000000000 --- a/.github/workflows/fossa.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Dependency License Scanning - -on: - workflow_dispatch: - -permissions: - contents: read - -jobs: - fossa: - name: Fossa - runs-on: ubuntu-latest - if: github.repository == 'gnolang/gno' - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - # we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves - fetch-depth: 0 - - - name: Move .fossa.yml to root dir - run: mv .github/.fossa.yml . - - - name: Cache Coursier cache - uses: coursier/cache-action@v6.4.6 - - - name: Set up JDK 17 - uses: coursier/setup-action@v1.3.9 - with: - jvm: temurin:1.17 - - - name: Set up fossa CLI - run: "curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash" - - - name: FOSSA analyze - run: fossa analyze - env: - FOSSA_API_KEY: "${{secrets.FOSSA_API_KEY}}" - - - name: FOSSA test - run: fossa test - env: - FOSSA_API_KEY: "${{secrets.FOSSA_API_KEY}}" diff --git a/.github/workflows/genesis-verify.yml b/.github/workflows/genesis-verify.yml deleted file mode 100644 index 1288d588100..00000000000 --- a/.github/workflows/genesis-verify.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: genesis-verify - -on: - pull_request: - branches: - - master - paths: - - "misc/deployments/**/genesis.json" - - ".github/workflows/genesis-verify.yml" - -jobs: - verify: - strategy: - fail-fast: false - matrix: - testnet: ["test5.gno.land"] - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v45 - with: - files: "misc/deployments/${{ matrix.testnet }}/genesis.json" - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version-file: contribs/gnogenesis/go.mod - - - name: Build gnogenesis - run: make -C contribs/gnogenesis - - - name: Verify each genesis file - run: | - for file in ${{ steps.changed-files.outputs.all_changed_files }}; do - echo "Verifying $file" - gnogenesis verify -genesis-path $file - done - - - name: Build gnoland - run: make -C gno.land install.gnoland - - - name: Running latest gnoland with each genesis file - run: | - for file in ${{ steps.changed-files.outputs.all_changed_files }}; do - echo "Running gnoland with $file" - timeout 60s gnoland start -lazy --genesis $file || exit_code=$? - if [ $exit_code -eq 124 ]; then - echo "Gnoland genesis state generated successfully" - else - echo "Gnoland failed to start with $file" - exit 1 - fi - done diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 686098e5a0f..8573ef89c8c 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -2,7 +2,7 @@ name: gh-pages on: - push: + pull_request: branches: [ "master" ] workflow_dispatch: diff --git a/.github/workflows/gnofmt_template.yml b/.github/workflows/gnofmt_template.yml deleted file mode 100644 index 1ba66d0fbe3..00000000000 --- a/.github/workflows/gnofmt_template.yml +++ /dev/null @@ -1,24 +0,0 @@ -on: - workflow_call: - inputs: - path: - required: true - type: string - go-version: - required: true - type: string - -jobs: - fmt: - runs-on: ubuntu-latest - steps: - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: ${{ inputs.go-version }} - - name: Checkout code - uses: actions/checkout@v4 - - name: Fmt - env: - GNOFMT_PATH: ${{ inputs.path }} - run: go run ./gnovm/cmd/gno fmt -v -diff $GNOFMT_PATH diff --git a/.github/workflows/gnoland.yml b/.github/workflows/gnoland.yml deleted file mode 100644 index 4817e2db0e3..00000000000 --- a/.github/workflows/gnoland.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: gno.land - -on: - push: - branches: - - master - workflow_dispatch: - pull_request: - -jobs: - main: - name: Run Main - uses: ./.github/workflows/main_template.yml - with: - modulepath: "gno.land" - tests-extra-args: "-coverpkg=github.com/gnolang/gno/gno.land/..." - secrets: - codecov-token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/gnovm.yml b/.github/workflows/gnovm.yml deleted file mode 100644 index 7e7586b23d9..00000000000 --- a/.github/workflows/gnovm.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: gnovm - -on: - push: - branches: - - master - workflow_dispatch: - pull_request: - -jobs: - main: - name: Run Main - uses: ./.github/workflows/main_template.yml - with: - modulepath: "gnovm" - secrets: - codecov-token: ${{ secrets.CODECOV_TOKEN }} - fmt: - name: Run Gno Fmt - uses: ./.github/workflows/gnofmt_template.yml - with: - path: "gnovm/stdlibs/..." - go-version: "1.22.x" diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index 06b2daa1d3d..00000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: "Pull Request Labeler" -on: -- pull_request_target - -jobs: - triage: - permissions: - contents: read - pull-requests: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/labeler@v5 diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml deleted file mode 100644 index 631f764c37f..00000000000 --- a/.github/workflows/lint-pr-title.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: "lint-pr-title" - -on: - pull_request_target: - types: - - opened - - edited - - synchronize - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -jobs: - pr-title: - runs-on: ubuntu-latest - steps: - - uses: amannn/action-semantic-pull-request@v5 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lint_template.yml b/.github/workflows/lint_template.yml deleted file mode 100644 index b7568d19c41..00000000000 --- a/.github/workflows/lint_template.yml +++ /dev/null @@ -1,28 +0,0 @@ -on: - workflow_call: - inputs: - modulepath: - required: true - type: string - go-version: - required: true - type: string - - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: ${{ inputs.go-version }} - - name: Lint - uses: golangci/golangci-lint-action@v6 - with: - working-directory: ${{ inputs.modulepath }} - args: - --config=${{ github.workspace }}/.github/golangci.yml - version: v1.62 # sync with misc/devdeps diff --git a/.github/workflows/main_template.yml b/.github/workflows/main_template.yml deleted file mode 100644 index 5b3437b54a1..00000000000 --- a/.github/workflows/main_template.yml +++ /dev/null @@ -1,41 +0,0 @@ -on: - workflow_call: - inputs: - modulepath: - required: true - type: string - tests-extra-args: - required: false - type: string - secrets: - codecov-token: - required: true - -# TODO: environment variables cannot be sent to reusable workflows: https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations -# env: -# GO_VERSION: "1.22.x" - -jobs: - lint: - name: Go Linter - uses: ./.github/workflows/lint_template.yml - with: - modulepath: ${{ inputs.modulepath }} - go-version: "1.22.x" - build: - name: Go Build - uses: ./.github/workflows/build_template.yml - with: - modulepath: ${{ inputs.modulepath }} - go-version: "1.22.x" - test: - name: Go Test - uses: ./.github/workflows/test_template.yml - with: - modulepath: ${{ inputs.modulepath }} - tests-timeout: "30m" - go-version: "1.22.x" - tests-extra-args: ${{ inputs.tests-extra-args }} - secrets: - codecov-token: ${{ secrets.codecov-token }} - diff --git a/.github/workflows/misc.yml b/.github/workflows/misc.yml deleted file mode 100644 index ad2c886e2ac..00000000000 --- a/.github/workflows/misc.yml +++ /dev/null @@ -1,29 +0,0 @@ -# tests the "misc" directory & tools -# (not meant for miscellaneous workflows) -name: misc - -on: - push: - branches: - - master - workflow_dispatch: - pull_request: - -jobs: - main: - strategy: - fail-fast: false - matrix: - # fixed list because we have some non go programs on that misc folder - program: - - autocounterd - - genproto - - genstd - - goscan - - loop - name: Run Main - uses: ./.github/workflows/main_template.yml - with: - modulepath: misc/${{ matrix.program }} - secrets: - codecov-token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/mod-tidy.yml b/.github/workflows/mod-tidy.yml deleted file mode 100644 index 24eab553d19..00000000000 --- a/.github/workflows/mod-tidy.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Ensure go.mods are tidied - -on: - push: - branches: - - master - workflow_dispatch: - pull_request: - -jobs: - main: - name: Ensure go.mods are tidied - runs-on: ubuntu-latest - steps: - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: ${{ inputs.go-version }} - - - name: Checkout code - uses: actions/checkout@v4 - - - name: Check go.mod files are up to date - working-directory: ${{ inputs.modulepath }} - run: | - make tidy VERIFY_MOD_SUMS=true diff --git a/.github/workflows/portal-loop.yml b/.github/workflows/portal-loop.yml deleted file mode 100644 index b898a149e9d..00000000000 --- a/.github/workflows/portal-loop.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: portal-loop - -on: - pull_request: - branches: - - master - push: - paths: - - "misc/loop/**" - - ".github/workflows/portal-loop.yml" - branches: - - "master" - # NOTE(albttx): branch name to simplify tests for this workflow - - "ci/portal-loop" - tags: - - "v*" - -permissions: - contents: read - packages: write - -jobs: - portal-loop: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Docker metadata portalloopd - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/${{ github.repository }}/portalloopd - tags: | - type=raw,value=latest - type=semver,pattern=v{{version}} - - - name: Build and push - uses: docker/build-push-action@v6 - with: - target: portalloopd - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - test-portal-loop-docker-compose: - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - name: "Checkout" - uses: actions/checkout@v4 - - - name: "Setup The portal loop docker compose" - run: | - cd misc/loop - echo "Making docker compose happy" - touch .env - make docker.ci - - - name: "Test1 - Portal loop start gnoland" - run: | - while - block_height=$(curl -s localhost:26657/status | jq -r '.result.sync_info.latest_block_height') - echo "Current block height: $block_height" - [[ "$block_height" -lt 10 ]] - do - sleep 1 - done - - curl -s localhost:26657/status | jq - - - name: "Buid new gnolang/gno image" - run: | - docker build -t ghcr.io/gnolang/gno/gnoland:master -f Dockerfile --target gnoland . - - - name: "Wait for new docker image" - run: | - ip_addr=$(cat misc/loop/traefik/gno.yml | grep -o "http://.*:26657") - while - new_ip_addr=$(cat misc/loop/traefik/gno.yml | grep -o "http://.*:26657") - echo "${ip_addr} -> ${new_ip_addr}" - [[ "${ip_addr}" == ${new_ip_addr} ]] - do - sleep 5 - done - - - name: "Test2 - Wait portal-loop start new image" - run: | - while - block_height=$(curl -s localhost:26657/status | jq -r '.result.sync_info.latest_block_height') - echo "Current block height: $block_height" - [[ "$block_height" -lt 10 ]] - do - sleep 5 - done - docker ps -a - curl -s localhost:26657/status | jq diff --git a/.github/workflows/releaser-master.yml b/.github/workflows/releaser-master.yml deleted file mode 100644 index 3d194e2cb4c..00000000000 --- a/.github/workflows/releaser-master.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Trigger master build - -on: - push: - branches: - - "master" - workflow_dispatch: - -permissions: - contents: write # needed to write releases - id-token: write # needed for keyless signing - packages: write # needed for ghcr access - -jobs: - goreleaser: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Create a dummy tag to avoid goreleaser failure - run: git tag v0.0.0 master - - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - cache: true - - - uses: sigstore/cosign-installer@v3.7.0 - - uses: anchore/sbom-action/download-syft@v0.17.8 - - - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - uses: goreleaser/goreleaser-action@v6 - with: - distribution: goreleaser-pro - version: ~> v2 - args: release --clean --nightly --config ./.github/goreleaser.yaml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} - TAG_VERSION: master diff --git a/.github/workflows/releaser-nightly.yml b/.github/workflows/releaser-nightly.yml deleted file mode 100644 index 4308f1c4a7d..00000000000 --- a/.github/workflows/releaser-nightly.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Trigger nightly build - -on: - schedule: - - cron: "0 0 * * 2-6" - workflow_dispatch: - -permissions: - contents: write # needed to write releases - id-token: write # needed for keyless signing - packages: write # needed for ghcr access - -jobs: - goreleaser: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - cache: true - - - uses: sigstore/cosign-installer@v3.7.0 - - uses: anchore/sbom-action/download-syft@v0.17.8 - - - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - uses: goreleaser/goreleaser-action@v6 - with: - distribution: goreleaser-pro - version: ~> v2 - args: release --clean --nightly --snapshot --config ./.github/goreleaser.yaml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} - TAG_VERSION: nightly diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml deleted file mode 100644 index 309664bdcce..00000000000 --- a/.github/workflows/releaser.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Go Releaser - -on: - push: - tags: - - "v*" - -permissions: - contents: write # needed to write releases - id-token: write # needed for keyless signing - packages: write # needed for ghcr access - -jobs: - goreleaser: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - cache: true - - - uses: sigstore/cosign-installer@v3.7.0 - - uses: anchore/sbom-action/download-syft@v0.17.8 - - - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - uses: goreleaser/goreleaser-action@v6 - with: - distribution: goreleaser-pro - version: ~> v2 - args: release --clean --config ./.github/goreleaser.yaml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} diff --git a/.github/workflows/stale-bot.yml b/.github/workflows/stale-bot.yml deleted file mode 100644 index 55a17ac60a8..00000000000 --- a/.github/workflows/stale-bot.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: "Close stale PRs" -on: - schedule: - - cron: "30 1 * * *" -permissions: - pull-requests: write - issues: write - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v9 - with: - exempt-all-milestones: true - stale-pr-message: "This PR is stale because it has been open 3 months with no activity. Remove stale label or comment or this will be closed in 3 months." - close-pr-message: "This PR was closed because it has been stalled for 3 months with no activity." - days-before-pr-stale: 90 - days-before-pr-close: 90 - stale-issue-message: "This issue is stale because it has been open 6 months with no activity. Remove stale label or comment or this will be closed in 3 months." - close-issue-message: "This issue was closed because it has been stalled for 3 months with no activity." - days-before-issue-stale: 180 - days-before-issue-close: 90 diff --git a/.github/workflows/test_template.yml b/.github/workflows/test_template.yml deleted file mode 100644 index c7956b4caf4..00000000000 --- a/.github/workflows/test_template.yml +++ /dev/null @@ -1,84 +0,0 @@ -on: - workflow_call: - inputs: - modulepath: - required: true - type: string - tests-timeout: - required: true - type: string - go-version: - required: true - type: string - tests-extra-args: - required: false - type: string - secrets: - codecov-token: - required: true - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Install Go - uses: actions/setup-go@v5 - with: - go-version: ${{ inputs.go-version }} - - name: Go test - working-directory: ${{ inputs.modulepath }} - env: - TXTARCOVERDIR: /tmp/txtarcoverdir # txtar cover output - GOCOVERDIR: /tmp/gocoverdir # go cover output - COVERDIR: /tmp/coverdir # final output - run: | - set -x # print commands - - mkdir -p "$GOCOVERDIR" "$TXTARCOVERDIR" "$COVERDIR" - - # Craft a filter flag based on the module path to avoid expanding coverage on unrelated tags. - export filter="-pkg=github.com/gnolang/gno/${{ inputs.modulepath }}/..." - - # codecov only supports "boolean" coverage (whether a line is - # covered or not); so using -covermode=count or atomic would be - # pointless here. - # XXX: Simplify coverage of txtar - the current setup is a bit - # confusing and meticulous. There will be some improvements in Go - # 1.23 regarding coverage, so we can use this as a workaround until - # then. - go test -covermode=set -timeout ${{ inputs.tests-timeout }} ${{ inputs.tests-extra-args }} ./... -test.gocoverdir=$GOCOVERDIR - - # Print results - (set +x; echo 'go coverage results:') - go tool covdata percent $filter -i=$GOCOVERDIR - (set +x; echo 'txtar coverage results:') - go tool covdata percent $filter -i=$TXTARCOVERDIR - - # Generate final coverage output - go tool covdata textfmt -v 1 $filter -i=$GOCOVERDIR,$TXTARCOVERDIR -o gocoverage.out - - - name: Upload go coverage to Codecov - uses: codecov/codecov-action@v5 - with: - disable_search: true - fail_ci_if_error: true - files: ${{ inputs.modulepath }}/gocoverage.out - flags: ${{ inputs.modulepath }} - token: ${{ secrets.codecov-token }} - verbose: true # keep this enable as it help debugging when coverage fail randomly on the CI - - # TODO: We have to fix race conditions before running this job - # test-with-race: - # runs-on: ubuntu-latest - # steps: - # - name: Install Go - # uses: actions/setup-go@v5 - # with: - # go-version: ${{ inputs.go-version }} - # - name: Checkout code - # uses: actions/checkout@v4 - # - name: Go race test - # run: go test -race -timeout ${{ inputs.tests-timeout }} ./... - # working-directory: ${{ inputs.modulepath }} diff --git a/.github/workflows/tm2.yml b/.github/workflows/tm2.yml deleted file mode 100644 index 57e84793c94..00000000000 --- a/.github/workflows/tm2.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: tm2 - -on: - push: - branches: - - master - workflow_dispatch: - pull_request: - -jobs: - main: - name: Run Main - uses: ./.github/workflows/main_template.yml - with: - modulepath: "tm2" - secrets: - codecov-token: ${{ secrets.CODECOV_TOKEN }}