monodiff

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2020 License: MIT Imports: 9 Imported by: 0

README

monodiff

monodiff is a simple and language-agnostic tool to detect modified part of monorepo.

Once you declare sub-projects and their dependencies in monodiff.json, monodiff reads a list of changed files, typically result of git diff —name-only origin/master, from standard input, then outputs affected sub-projects by the changes. Using its output, you can easily build or deploy only affected projects in CI/CD.

Real-world example

See the following example repoistory to use monodiff with Gradle multi-project build:

https://github.com/orangain/monodiff-example-multi-project

Install

Pre-compiled binary

Download from the releases page and put it onto your $PATH.

Docker

Docker image is available at Docker Hub.

https://hub.docker.com/r/orangain/monodiff

Configuration

Create a file monodiff.json at the root directory of Git repository. In the monodiff.json, you need to declare sub-projects and their dependencies.

This is an example monodiff.json.

{
  "apps/account-app": {
    "deps": ["build.gradle.kts", "settings.gradle.kts", "libs/greeter", "libs/profile"]
  },
  "apps/inventory-app": {
    "deps": ["build.gradle.kts", "settings.gradle.kts", "libs/profile"]
  }
}

Each key, e.g. apps/account-app, represents a directory of the sub-project. When a file under the directory is changed, the sub-project is determined to be changed.

Additionally, each sub-project can have a deps list. The deps represents dependencies. Each item of the deps is a path to a file or directory. When the file or a file under the directory is changed, the sub-project is also determined to be changed.

All the paths in the monodiff.json should be a relative path to the root of Git repository.

CLI Usage

$ monodiff --help
NAME:
   monodiff - Simple tool to detect modified part of monorepo

USAGE:
   monodiff [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --prefix value     Prefix of output line
   --suffix value     Suffix of output line
   --separator value  Path separator of output line
   --help, -h         show help (default: false)

License

MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var App = &cli.App{
	Name:  "monodiff",
	Usage: "Simple tool to detect modified part of monorepo",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:  "prefix",
			Value: "",
			Usage: "Prefix of output line",
		},
		&cli.StringFlag{
			Name:  "suffix",
			Value: "",
			Usage: "Suffix of output line",
		},
		&cli.StringFlag{
			Name:  "separator",
			Value: "",
			Usage: "Path separator of output line",
		},
	},
	Action: func(c *cli.Context) error {
		prefix := c.String("prefix")
		suffix := c.String("suffix")
		separator := c.String("separator")

		spec, err := loadSpec()
		if err != nil {
			return err
		}

		changedFiles := []string{}
		stdin := bufio.NewScanner(os.Stdin)
		for stdin.Scan() {
			text := stdin.Text()
			if text != "" {
				changedFiles = append(changedFiles, text)
			}
		}

		changedProjects, err := detectChanges(spec, changedFiles)
		for _, changedProject := range changedProjects {
			name := changedProject.Name
			if separator != "" {
				name = strings.ReplaceAll(name, "/", separator)
			}
			fmt.Println(prefix + name + suffix)
		}

		return nil
	},
}

App is a CLI app of monodiff using urfave/cli/v2.

Functions

This section is empty.

Types

type FilesDependency

type FilesDependency struct {
	GlobPattern string
}

FilesDependency represents dependency to files.

type Project

type Project struct {
	Name                string
	FilesDependencies   []FilesDependency
	ProjectDependencies []ProjectDependency
}

Project represents unit of build.

type ProjectDependency

type ProjectDependency struct {
	ProjectName string
}

ProjectDependency represents dependency to other project.

type ProjectJSON

type ProjectJSON struct {
	Deps []string `json:"deps"`
}

ProjectJSON represents a project configuration in monodiff.json

type Spec

type Spec struct {
	Projects []*Project
}

Spec represents set of projects.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL