Skip to content
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 18 commits into from
Jul 30, 2023

Conversation

lennartkats-db
Copy link
Contributor

@lennartkats-db lennartkats-db commented Jul 17, 2023

Changes

This checks whether the Git settings are consistent with the actual Git state of a source directory.

(This PR adds to #577.)

Previously, we would silently let users configure their Git branch to e.g. main and deploy with that metadata even if they were actually on a different branch.

With these changes, the following config would result in an error when deployed from any other branch than main:

bundle:
  name: example

workspace:
  git:
    branch: main

environments:
  ...

not on the right Git branch:
expected according to configuration: main
actual: my-feature-branch

It's not very useful to set the same branch for all environments, though. For development, it's better to just let the CLI auto-detect the right branch. Therefore, it's now possible to set the branch just for a single environment:

bundle:
  name: example 2

environments:
  development:
    default: true

  production:
    # production can only be deployed from the 'main' branch
    git:
      branch: main

Adding to that, the mode: production option actually checks that users explicitly set the Git branch as seen above. Setting that branch helps avoid mistakes, where someone accidentally deploys to production from the wrong branch. (I could see us offering an escape hatch for that in the future.)

Testing

Manual testing to validate the experience and error messages. Automated unit tests.

@@ -22,6 +22,10 @@ func mockBundle(mode config.Mode) *bundle.Bundle {
Config: config.Root{
Bundle: config.Bundle{
Mode: mode,
Git: config.Git{
Copy link
Contributor Author

@lennartkats-db lennartkats-db Jul 18, 2023

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 under bundle... That's a lot of nesting.

This PR follows what's in main Git configuration for bundle:

bundle:
  git:
    branch: main

But it also adds support for setting the branch at the environment level. One way to do so could be the following:

environment:
  production:
    bundle:
      git:
        branch: main

But the nesting is pretty problematic there 😓 Instead, this PR supports:

environment:
  production:
    git:
      branch: main

I'd still be interested in feedback on this!

@lennartkats-db lennartkats-db force-pushed the extend-deployment-modes-git branch 2 times, most recently from 093e92a to 53ba4cf Compare July 24, 2023 07:57
@lennartkats-db
Copy link
Contributor Author

I updated this PR so it now supports --force to override the config-specified branch.

@lennartkats-db lennartkats-db marked this pull request as ready for review July 24, 2023 08:21
bundle/config/mutator/process_environment_mode.go Outdated Show resolved Hide resolved
bundle/config/lock.go Outdated Show resolved Hide resolved
bundle/config/root.go Outdated Show resolved Hide resolved
@lennartkats-db lennartkats-db force-pushed the extend-deployment-modes-production branch from 1628ea3 to 1cb7774 Compare July 30, 2023 07:15
Base automatically changed from extend-deployment-modes-production to main July 30, 2023 07:25
@lennartkats-db lennartkats-db added this pull request to the merge queue Jul 30, 2023
Merged via the queue into main with commit 433f401 Jul 30, 2023
4 checks passed
@lennartkats-db lennartkats-db deleted the extend-deployment-modes-git branch July 30, 2023 12:51
pietern added a commit that referenced this pull request Aug 10, 2023
CLI:
 * Infer host from profile during `auth login` ([#629](#629)).

Bundles:
 * Extend deployment mode support ([#577](#577)).
 * Add validation for Git settings in bundles ([#578](#578)).
 * Only treat files with .tmpl extension as templates ([#594](#594)).
 * Add JSON schema validation for input template parameters ([#598](#598)).
 * Add DATABRICKS_BUNDLE_INCLUDE_PATHS to specify include paths through env vars ([#591](#591)).
 * Initialise a empty default bundle if BUNDLE_ROOT and DATABRICKS_BUNDLE_INCLUDES env vars are present ([#604](#604)).
 * Regenerate bundle resource structs from latest Terraform provider ([#633](#633)).
 * Fixed processing jobs libraries with remote path ([#638](#638)).
 * Add unit test for file name execution during rendering ([#640](#640)).
 * Add bundle init command and support for prompting user for input values ([#631](#631)).
 * Fix bundle git branch validation ([#645](#645)).

Internal:
 * Fix mkdir integration test on GCP ([#620](#620)).
 * Fix git clone integration test for non-existing repo ([#610](#610)).
 * Remove push to main trigger for build workflow ([#621](#621)).
 * Remove workflow to publish binaries to S3 ([#622](#622)).
 * Fix failing fs mkdir test on azure ([#627](#627)).
 * Print y/n options when displaying prompts using cmdio.Ask ([#650](#650)).

API Changes:
 * Changed `databricks account metastore-assignments create` command to not return anything.
 * Added `databricks account network-policy` command group.

OpenAPI commit 7b57ba3a53f4de3d049b6a24391fe5474212daf8 (2023-07-28)

Dependency updates:
 * Bump OpenAPI specification & Go SDK Version ([#624](#624)).
 * Bump golang.org/x/term from 0.10.0 to 0.11.0 ([#643](#643)).
 * Bump golang.org/x/text from 0.11.0 to 0.12.0 ([#642](#642)).
 * Bump golang.org/x/oauth2 from 0.10.0 to 0.11.0 ([#641](#641)).
@pietern pietern mentioned this pull request Aug 10, 2023
github-merge-queue bot pushed a commit that referenced this pull request Aug 10, 2023
CLI:
* Infer host from profile during `auth login`
([#629](#629)).

Bundles:
* Extend deployment mode support
([#577](#577)).
* Add validation for Git settings in bundles
([#578](#578)).
* Only treat files with .tmpl extension as templates
([#594](#594)).
* Add JSON schema validation for input template parameters
([#598](#598)).
* Add DATABRICKS_BUNDLE_INCLUDE_PATHS to specify include paths through
env vars ([#591](#591)).
* Initialise a empty default bundle if BUNDLE_ROOT and
DATABRICKS_BUNDLE_INCLUDES env vars are present
([#604](#604)).
* Regenerate bundle resource structs from latest Terraform provider
([#633](#633)).
* Fixed processing jobs libraries with remote path
([#638](#638)).
* Add unit test for file name execution during rendering
([#640](#640)).
* Add bundle init command and support for prompting user for input
values ([#631](#631)).
* Fix bundle git branch validation
([#645](#645)).

Internal:
* Fix mkdir integration test on GCP
([#620](#620)).
* Fix git clone integration test for non-existing repo
([#610](#610)).
* Remove push to main trigger for build workflow
([#621](#621)).
* Remove workflow to publish binaries to S3
([#622](#622)).
* Fix failing fs mkdir test on azure
([#627](#627)).
* Print y/n options when displaying prompts using cmdio.Ask
([#650](#650)).

API Changes:
* Changed `databricks account metastore-assignments create` command to
not return anything.
 * Added `databricks account network-policy` command group.

OpenAPI commit 7b57ba3a53f4de3d049b6a24391fe5474212daf8 (2023-07-28)

Dependency updates:
* Bump OpenAPI specification & Go SDK Version
([#624](#624)).
* Bump golang.org/x/term from 0.10.0 to 0.11.0
([#643](#643)).
* Bump golang.org/x/text from 0.11.0 to 0.12.0
([#642](#642)).
* Bump golang.org/x/oauth2 from 0.10.0 to 0.11.0
([#641](#641)).
github-merge-queue bot pushed a commit that referenced this pull request Aug 15, 2023
## Changes
As discussed here, the name for this flag should be `force-lock`:
#578 (comment)

## Tests
Manually and existing tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants