Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions docs/public/docs/guide/cli/breaking-changes/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ breaking:
- "experimental"
- "internal/proto"
- "vendor"

# Additional options to braking check
use:
- FILE
```

### Configuration Options

| Option | Description | Default | Required |
|--------|-------------|---------|----------|
| `against_git_ref` | Git reference to compare against | `"master"` | No |
| `ignore` | List of directories to exclude from analysis | `[]` | No |
| Option | Description | Default | Required |
|-------------------|----------------------------------------------|---------|----------|
| `against_git_ref` | Git reference to compare against | `"master"` | No |
| `ignore` | List of directories to exclude from analysis | `[]` | No |
| `use` | List of braking check options | `[]` | No |

## Usage

Expand Down Expand Up @@ -137,7 +142,7 @@ EasyP detects the following types of breaking changes:
|----------------|-------------|---------------|
| **WIRE** | Wire format compatibility only | ✅ **Full support** |
| **WIRE+** | Wire + element deletion detection | ✅ **Current level** |
| **FILE** | Generated code compatibility | ❌ Partial (planned) |
| **FILE** | Generated code compatibility | ✅ **Current level** |
## Breaking Change Rules

EasyP detects the following categories of breaking changes. Each rule has detailed documentation with examples:
Expand Down
2 changes: 1 addition & 1 deletion docs/public/search/index.en.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions example.easyp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ breaking:
ignore:
- some_dir
against_git_ref: master
use:
- FILE

generate:
inputs:
Expand Down
4 changes: 4 additions & 0 deletions internal/api/temporaly_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log/slog"
"os"
"path/filepath"
"slices"
"strings"

"github.com/samber/lo"
Expand Down Expand Up @@ -95,9 +96,12 @@ func buildCore(_ context.Context, log logger.Logger, cfg config.Config, dirWalke
linterIgnoreDirs := append(cfg.Lint.Ignore, vendorPath)
breakingCheckIgnoreDirs := append(cfg.BreakingCheck.Ignore, vendorPath)

filesCheck := slices.Contains(cfg.BreakingCheck.Use, core.BreakingCheckFilesCheck)

breakingCheckConfig := core.BreakingCheckConfig{
IgnoreDirs: breakingCheckIgnoreDirs,
AgainstGitRef: cfg.BreakingCheck.AgainstGitRef,
FilesCheck: filesCheck,
}

// Convert managed mode configuration
Expand Down
3 changes: 2 additions & 1 deletion internal/config/breaking_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ package config
type BreakingCheck struct {
Ignore []string `json:"ignore,omitempty" yaml:"ignore,omitempty"`
// git ref to compare with
AgainstGitRef string `json:"against_git_ref,omitempty" yaml:"against_git_ref,omitempty"`
AgainstGitRef string `json:"against_git_ref,omitempty" yaml:"against_git_ref,omitempty"`
Use []string `json:"use,omitempty" yaml:"use,omitempty"`
}
Comment on lines +7 to 9
8 changes: 8 additions & 0 deletions internal/core/breaking_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ import (

var ErrRootOutsideProject = fmt.Errorf("breaking check root must be inside the git repository")

const (
BreakingCheckFilesCheck string = "FILE"
)

type BreakingCheckConfig struct {
// branch name to compare with
AgainstGitRef string
// dirs should be ignored
IgnoreDirs []string

FilesCheck bool
}

func (c *Core) BreakingCheck(ctx context.Context, projectRoot, workingDir, path string) ([]IssueInfo, error) {
Expand Down Expand Up @@ -68,6 +74,8 @@ func (c *Core) BreakingCheck(ctx context.Context, projectRoot, workingDir, path
breakingChecker := &BreakingChecker{
against: againstProtoData,
current: currentProtoData,

filesCheck: c.breakingCheckConfig.FilesCheck,
}

return breakingChecker.Check()
Expand Down
70 changes: 70 additions & 0 deletions internal/core/breaking_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const breakingCheckRuleName = "BREAKING_CHECK"
type BreakingChecker struct {
against ProtoData
current ProtoData

filesCheck bool
}

func (b *BreakingChecker) Check() ([]IssueInfo, error) {
Expand Down Expand Up @@ -86,6 +88,11 @@ func (b *BreakingChecker) checkService(againstService Service) []IssueInfo {
return res
}

if b.hasFilesCheckError(currentService.ProtoFilePath, againstService.ProtoFilePath) {
issue := getServiceMovedIssue(currentService, againstService)
res = append(res, issue)
}

Comment on lines +91 to +95
// check RPCs
for _, againstRPC := range againstService.ServiceBody.RPCs {
// rpc was deleted
Expand Down Expand Up @@ -142,6 +149,11 @@ func (b *BreakingChecker) checkMessage(againstMessage Message) []IssueInfo {
return res
}

if b.hasFilesCheckError(currentMessage.ProtoFilePath, againstMessage.ProtoFilePath) {
issue := getMessageMovedIssue(currentMessage, againstMessage)
res = append(res, issue)
}

// check fields
for _, againstField := range againstMessage.MessageBody.Fields {
currentField, ok := searchField(currentMessage.MessageBody.Fields, againstField.FieldNumber)
Expand Down Expand Up @@ -182,6 +194,11 @@ func (b *BreakingChecker) checkOneOf(againstOneOf OneOf) []IssueInfo {
return res
}

if b.hasFilesCheckError(currentOneOf.ProtoFilePath, againstOneOf.ProtoFilePath) {
issue := getOneOfMovedIssue(currentOneOf, againstOneOf)
res = append(res, issue)
}

// check fields
for _, againstField := range againstOneOf.OneofFields {
currentField, ok := searchOneOfField(currentOneOf.OneofFields, againstField.FieldNumber)
Expand Down Expand Up @@ -213,6 +230,11 @@ func (b *BreakingChecker) checkEnum(againstEnum Enum) []IssueInfo {
return res
}

if b.hasFilesCheckError(currentEnum.ProtoFilePath, againstEnum.ProtoFilePath) {
issue := getEnumMovedIssue(currentEnum, againstEnum)
res = append(res, issue)
}

for _, againstField := range againstEnum.EnumBody.EnumFields {
currentField, ok := searchEnumField(currentEnum.EnumBody.EnumFields, againstField.Number)
if !ok {
Expand All @@ -233,6 +255,14 @@ func (b *BreakingChecker) checkEnum(againstEnum Enum) []IssueInfo {

// ===== utils =====

func (b *BreakingChecker) hasFilesCheckError(path1, path2 string) bool {
if b.filesCheck && path1 != path2 {
return true
}

return false
}

func getImport(source ProtoData, packageName PackageName, importPath ImportPath) (Import, bool) {
collection, ok := source[packageName]
if !ok {
Expand Down Expand Up @@ -407,6 +437,46 @@ func getMessageDeletedIssue(againstMessage Message) IssueInfo {
return buildBreakingCheckIssue(againstMessage.ProtoFilePath, message, againstMessage.Meta.Pos)
}

func getMessageMovedIssue(currentMessage, againstMessage Message) IssueInfo {
message := fmt.Sprintf(
"Previously present Message \"%s\" was moved from \"%s\" file to \"%s\" file\n",
againstMessage.MessagePath,
againstMessage.ProtoFilePath,
currentMessage.ProtoFilePath,
)
return buildBreakingCheckIssue(againstMessage.ProtoFilePath, message, againstMessage.Meta.Pos)
}

func getServiceMovedIssue(currentService, againstService Service) IssueInfo {
message := fmt.Sprintf(
"Previously present Service \"%s\" was moved from \"%s\" file to \"%s\" file\n",
againstService.ServiceName,
againstService.ProtoFilePath,
currentService.ProtoFilePath,
)
return buildBreakingCheckIssue(againstService.ProtoFilePath, message, againstService.Meta.Pos)
}

func getOneOfMovedIssue(currentOneOf, againstOneOf OneOf) IssueInfo {
message := fmt.Sprintf(
"Previously present OneOf \"%s\" was moved from \"%s\" file to \"%s\" file\n",
againstOneOf.OneofName,
againstOneOf.ProtoFilePath,
currentOneOf.ProtoFilePath,
)
return buildBreakingCheckIssue(againstOneOf.ProtoFilePath, message, againstOneOf.Meta.Pos)
}

func getEnumMovedIssue(currentEnum, againstEnum Enum) IssueInfo {
message := fmt.Sprintf(
"Previously present Enum \"%s\" was moved from \"%s\" file to \"%s\" file\n",
againstEnum.EnumName,
againstEnum.ProtoFilePath,
currentEnum.ProtoFilePath,
)
return buildBreakingCheckIssue(againstEnum.ProtoFilePath, message, againstEnum.Meta.Pos)
}

func getFieldDeletedIssue(againstMessage Message, againstField *parser.Field) IssueInfo {
message := fmt.Sprintf("Previously present field \"%s\" with name \"%s\" "+
"on message \"%s\" was deleted.",
Expand Down
6 changes: 6 additions & 0 deletions schemas/easyp-config-v1.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@
},
"against_git_ref": {
"type": "string"
},
"use": {
"items": {
"type": "string"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down
6 changes: 6 additions & 0 deletions schemas/easyp-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@
},
"against_git_ref": {
"type": "string"
},
"use": {
"items": {
"type": "string"
},
"type": "array"
}
},
"additionalProperties": false,
Expand Down
Loading