Skip to content

CLOUDP-279514 Detect and block breaking changes #4064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 30, 2025
Merged
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
59 changes: 59 additions & 0 deletions .github/workflows/breaking-changes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Detect Breaking Changes

on:
pull_request:

jobs:
breaking-changes-manifest:
name: Generate Breaking Changes Manifest
runs-on: ubuntu-latest
outputs:
breaking-changes: ${{ steps.breakvalidator.outputs.JSON }}
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
with:
config: ${{ vars.PERMISSIONS_CONFIG }}
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install dependencies
run: go mod download
- name: Run breaking changes validator
id: breakvalidator
run: |
set -e
go run ./tools/cmd/breakvalidator generate > main.json
- name: Upload manifest
uses: actions/upload-artifact@v4
with:
name: breaking-changes-manifest
path: main.json
detect-breaking-changes:
name: Detect Breaking Changes
runs-on: ubuntu-latest
needs: breaking-changes-manifest
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
with:
config: ${{ vars.PERMISSIONS_CONFIG }}
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Download manifest
uses: actions/download-artifact@v4
with:
name: breaking-changes-manifest
path: main.json
- name: Run breaking changes validator
run: |
set -e
go run ./tools/cmd/breakvalidator generate > changed.json
go run ./tools/cmd/breakvalidator validate -m main.json -c changed.json
3 changes: 3 additions & 0 deletions .github/workflows/close-jira.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'auto_close_jira')
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
with:
config: ${{ vars.PERMISSIONS_CONFIG }}
- name: set jira key (branch name)
if: ${{ startsWith(github.event.pull_request.head.ref, 'CLOUDP') }}
env:
Expand Down
1 change: 1 addition & 0 deletions scripts/add-copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ find_files() {
\( \
-wholename '*mock*' \
-o -wholename '*third_party*' \
-o -wholename '*docs/command*' \
\) -prune \
\) \
\( -name '*.go' -o -name '*.sh' \)
Expand Down
73 changes: 73 additions & 0 deletions tools/cmd/breakvalidator/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2025 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"encoding/json"
"io"

"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/root"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

func generateCmd(cmd *cobra.Command) cmdData {
data := cmdData{}
if len(cmd.Aliases) > 0 {
data.Aliases = cmd.Aliases
}
flags := false
data.Flags = map[string]flagData{}
cmd.Flags().VisitAll(func(f *pflag.Flag) {
data.Flags[f.Name] = flagData{
Type: f.Value.Type(),
Default: f.DefValue,
Short: f.Shorthand,
}
flags = true
})
if !flags {
data.Flags = nil
}
return data
}

func generateCmds(cmd *cobra.Command) map[string]cmdData {
data := map[string]cmdData{}
data[cmd.CommandPath()] = generateCmd(cmd)
for _, c := range cmd.Commands() {
for k, v := range generateCmds(c) {
data[k] = v
}
}
return data
}

func generateCmdRun(output io.Writer) error {
cliCmd := root.Builder()
data := generateCmds(cliCmd)
return json.NewEncoder(output).Encode(data)
}

func buildGenerateCmd() *cobra.Command {
generateCmd := &cobra.Command{
Use: "generate",
Short: "Generate the CLI command structure.",
RunE: func(cmd *cobra.Command, _ []string) error {
return generateCmdRun(cmd.OutOrStdout())
},
}
return generateCmd
}
48 changes: 48 additions & 0 deletions tools/cmd/breakvalidator/generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2025 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"reflect"
"testing"

"github.com/spf13/cobra"
)

func TestGenerateCmds(t *testing.T) {
cliCmd := &cobra.Command{
Use: "test",
Aliases: []string{"testa"},
}
cliCmd.Flags().StringP("flag1", "f", "default1", "flag1")
generatedData := generateCmds(cliCmd)

expectedData := map[string]cmdData{
"test": {
Aliases: []string{"testa"},
Flags: map[string]flagData{
"flag1": {
Type: "string",
Default: "default1",
Short: "f",
},
},
},
}

if !reflect.DeepEqual(generatedData, expectedData) {
t.Fatalf("got: %v, expected: %v", generatedData, expectedData)
}
}
51 changes: 51 additions & 0 deletions tools/cmd/breakvalidator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2025 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"os"

"github.com/spf13/cobra"
)

type flagData struct {
Type string `json:"type"`
Default string `json:"default"`
Short string `json:"short"`
}

type cmdData struct {
Aliases []string `json:"aliases"`
Flags map[string]flagData `json:"flags"`
}

func buildRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "breakvalidator",
Short: "CLI tool to validate breaking changes in the CLI.",
}
rootCmd.AddCommand(buildGenerateCmd())
rootCmd.AddCommand(buildValidateCmd())

return rootCmd
}

func main() {
rootCmd := buildRootCmd()
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
Loading
Loading