Giter Club home page Giter Club logo

gwd's Introduction

What is this tool for ?

gwd stands for go workspace diff

This is tool must be used with a go workspace file (go.work) introduced in the 1.18 release of go.

It allows you to easily track :

  • when a module change
  • when packages of a module change and packages that import them

As an example, suppose a change is committed which modifies a package, libs/hypervisor. Suppose this package is imported by another package, services/controller. gwd is used to inspect your files based on a list of changes and determine that both of these packages must be tested, although only the first package was changed.

If you think you've already read that, it's true. This excerpt comes from the blog of digitalocean in which they talk about the organization of their monorepository.

Install

go install github.com/alexisvisco/gwd@latest 

Commands

Do gwd --help to see the list of commands and their usage.

gwd --stdin

This command is used to determine which modules changed based on a list of file change provided in stdin.

!Example:

$ cat go.work                 
go 1.18

use (
        ./services/competition-vacuum
        ./services/dummy
        ./services/vote
)

$ git diff 2022.0728.1850 --name-only | cat
.gitlab-ci.yml
.gitlab-ci/get-previous-ref.sh
Makefile
Makefile.common
services/competition-vacuum/cmd/competition-vacuum/main.go
services/competition-vacuum/internal/clients/kkbb/client.go
services/competition-vacuum/internal/clients/kkbb/types.go
services/competition-vacuum/internal/clients/ulule/client.go
services/competition-vacuum/internal/services/competition_vacuum/vacuum.go
tools/deploy.sh

$ git diff 2022.0728.1850 --name-only | gwd --stdin
services/competition-vacuum

$ git diff 2022.0728.1850 --name-only | gwd --stdin -v
"miimosa.com/services/competition-vacuum":
 - "services/competition-vacuum/internal/clients/ulule/client.go"
   imported by:
   ∟ "miimosa.com/services/competition-vacuum/cmd/competition-vacuum" (1 times) module "miimosa.com/services/competition-vacuum"
 - "services/competition-vacuum/internal/services/competition_vacuum/vacuum.go"
   imported by:
   ∟ "miimosa.com/services/competition-vacuum/cmd/competition-vacuum" (1 times) module "miimosa.com/services/competition-vacuum"
 - "services/competition-vacuum/cmd/competition-vacuum/main.go"
 - "services/competition-vacuum/internal/clients/kkbb/client.go"
   imported by:
   ∟ "miimosa.com/services/competition-vacuum/cmd/competition-vacuum" (1 times) module "miimosa.com/services/competition-vacuum"

As you can see only "miimosa.com/services/competition-vacuum" has been changed.

This command can take one argument, if it is specified it will show only diff for packages in the module specified.

check

This command is used to check if a module from the go workspace has change. This command takes one argument, the name of the module, it can be a path or a module name.

Flags

Each of theses commands have in common 2 flags:

  • --stdin read stdin, used in conjuncture with git diff --name-only for example.
  • --file read a file, each line must be a file path

Global flags

  • --json or -j output commands as json
  • --verbose or -v output commands with more details that the default output
  • --go-work or -w set the go workspace file name which is by default parsed from the the go.mod file

Why using a pkg folder ?

I don't use internal for open source because maybe you will use some packages for your usage.

gwd's People

Contributors

alexisvisco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dolanor-galaxy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.