-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add validation for Git settings in bundles #578
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
837a48c
Extend deployment modes
lennartkats-db 498aaa6
Simplify error messages
lennartkats-db 3767c1c
Fix service principal test for non-admins
lennartkats-db 1ab5598
Relax run_as/permissions check
lennartkats-db e795273
Update bundle/config/environment.go
lennartkats-db 2ab8dfb
Fix test
lennartkats-db 707c86f
Add TODO
lennartkats-db 1cb7774
Add clarifying comment
lennartkats-db 16daac2
Add Git checks
lennartkats-db dc34fc7
Only validate Git details when deploying
lennartkats-db 8732b53
Fix test
lennartkats-db fc9b525
Improve error
lennartkats-db b69f784
Allow --force to override Git validation
lennartkats-db a3e70a7
Merge remote-tracking branch 'databricks/main' into extend-deployment…
lennartkats-db ffaacec
Cleanup
lennartkats-db ea412da
Restore separate --force-lock option
lennartkats-db c704196
Cleanup
lennartkats-db 8d27d77
Fix missing return statement
lennartkats-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package mutator | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/databricks/cli/bundle" | ||
) | ||
|
||
type validateGitDetails struct{} | ||
|
||
func ValidateGitDetails() *validateGitDetails { | ||
return &validateGitDetails{} | ||
} | ||
|
||
func (m *validateGitDetails) Name() string { | ||
return "ValidateGitDetails" | ||
} | ||
|
||
func (m *validateGitDetails) Apply(ctx context.Context, b *bundle.Bundle) error { | ||
if b.Config.Bundle.Git.Branch == "" || b.Config.Bundle.Git.ActualBranch == "" { | ||
return nil | ||
} | ||
|
||
if b.Config.Bundle.Git.Branch != b.Config.Bundle.Git.ActualBranch && !b.Config.Bundle.Force { | ||
return fmt.Errorf("not on the right Git branch:\n expected according to configuration: %s\n actual: %s\nuse --force to override", b.Config.Bundle.Git.Branch, b.Config.Bundle.Git.ActualBranch) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package mutator | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidateGitDetailsMatchingBranches(t *testing.T) { | ||
bundle := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Bundle: config.Bundle{ | ||
Git: config.Git{ | ||
Branch: "main", | ||
ActualBranch: "main", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
m := ValidateGitDetails() | ||
err := m.Apply(context.Background(), bundle) | ||
|
||
assert.NoError(t, err) | ||
} | ||
|
||
func TestValidateGitDetailsNonMatchingBranches(t *testing.T) { | ||
bundle := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Bundle: config.Bundle{ | ||
Git: config.Git{ | ||
Branch: "main", | ||
ActualBranch: "feature", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
m := ValidateGitDetails() | ||
err := m.Apply(context.Background(), bundle) | ||
|
||
expectedError := "not on the right Git branch:\n expected according to configuration: main\n actual: feature\nuse --force to override" | ||
assert.EqualError(t, err, expectedError) | ||
} | ||
|
||
func TestValidateGitDetailsNotUsingGit(t *testing.T) { | ||
bundle := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Bundle: config.Bundle{ | ||
Git: config.Git{ | ||
Branch: "main", | ||
ActualBranch: "", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
m := ValidateGitDetails() | ||
err := m.Apply(context.Background(), bundle) | ||
|
||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
bundle: | ||
name: autoload git config test | ||
git: | ||
branch: foo | ||
|
||
environments: | ||
development: | ||
default: true | ||
|
||
production: | ||
# production can only be deployed from the 'main' branch | ||
git: | ||
branch: main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main thing to decide on for this PR is if we want customers to nest
git
underbundle
... That's a lot of nesting.This PR follows what's in
main
Git configuration forbundle
:But it also adds support for setting the branch at the environment level. One way to do so could be the following:
But the nesting is pretty problematic there 😓 Instead, this PR supports:
I'd still be interested in feedback on this!