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

Improve git config section validation #1940

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

denik
Copy link
Contributor

@denik denik commented Nov 27, 2024

Previously we checked if ActualBranch (from .git) and Branch disagreed and issued an error unless --force was passed.

We still do that, but also:

  • if --force is passed, we now log this as a warning (previously it went silent)
  • we do the same logic for commit (previously unchecked)
  • we do similar logic for originURL except it always logs warning and never prevent the deployment

I removed separate mutator (validate_git_details.go) and put everything into load_git_details.go.

@denik denik temporarily deployed to test-trigger-is November 27, 2024 21:28 — with GitHub Actions Inactive
@denik denik requested a review from shreyas-goenka November 27, 2024 21:28
@denik denik temporarily deployed to test-trigger-is November 27, 2024 21:28 — with GitHub Actions Inactive
@denik denik requested a review from pietern November 27, 2024 21:28
@denik denik temporarily deployed to test-trigger-is November 28, 2024 08:54 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is November 28, 2024 08:54 — with GitHub Actions Inactive
@denik denik requested a review from shreyas-goenka November 28, 2024 08:56
@denik denik force-pushed the DECO-24125--no_override_commit branch from 53c07da to a141e3f Compare November 28, 2024 10:18
@denik denik temporarily deployed to test-trigger-is November 28, 2024 10:18 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is November 28, 2024 10:18 — with GitHub Actions Inactive
@denik denik marked this pull request as draft November 29, 2024 16:34
@denik denik force-pushed the DECO-24125--no_override_commit branch from a141e3f to afc065f Compare December 4, 2024 10:19
@denik denik temporarily deployed to test-trigger-is December 4, 2024 10:19 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 4, 2024 10:19 — with GitHub Actions Inactive
@denik denik changed the base branch from main to DECO-24125--fetch-git-details December 4, 2024 10:19
@denik denik changed the title Always read commit and originUrl from the repo Improve git config section validation Dec 4, 2024
@denik denik force-pushed the DECO-24125--no_override_commit branch from afc065f to 39806c9 Compare December 4, 2024 10:49
@denik denik temporarily deployed to test-trigger-is December 4, 2024 10:49 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 4, 2024 10:50 — with GitHub Actions Inactive
Base automatically changed from DECO-24125--fetch-git-details to main December 5, 2024 10:19
Previously we checked if ActualBranch (from .git) and Branch disagreed
and issued an error unless --force was passed.

We still do that, but also:
 - if --force is passed, we now log this as a warning (previously it went silent)
 - we do the same logic for commit (previously unchecked)
 - we do similar logic for originURL except it always logs warning and never
   prevent the deployment

I removed separate mutator (validate_git_details.go) and put everything into load_git_details.go.
@denik denik force-pushed the DECO-24125--no_override_commit branch from 39806c9 to 23169cd Compare December 9, 2024 15:02
@denik denik temporarily deployed to test-trigger-is December 9, 2024 15:02 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 9, 2024 15:02 — with GitHub Actions Inactive
@denik denik requested review from andrewnester and pietern December 9, 2024 15:05
@denik denik marked this pull request as ready for review December 9, 2024 15:22
@denik denik temporarily deployed to test-trigger-is December 9, 2024 15:37 — with GitHub Actions Inactive
@denik denik marked this pull request as draft December 9, 2024 15:37
@denik denik temporarily deployed to test-trigger-is December 9, 2024 15:37 — with GitHub Actions Inactive
On CI info.CurrentBranch is "" but according to original logic it is still Inferred
because it only checks if Config value is empty string.
@denik denik temporarily deployed to test-trigger-is December 9, 2024 15:43 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 9, 2024 15:43 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 9, 2024 15:50 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 9, 2024 15:50 — with GitHub Actions Inactive
@denik denik marked this pull request as ready for review December 9, 2024 15:55
@denik denik enabled auto-merge December 9, 2024 15:58
@denik denik requested a review from lennartkats-db December 9, 2024 16:09
@denik denik temporarily deployed to test-trigger-is December 9, 2024 16:43 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 9, 2024 16:43 — with GitHub Actions Inactive
Copy link
Contributor

@pietern pietern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks great!

Does the e2e coverage of LoadGitDetails cover this as well?

bundle/config/mutator/load_git_details.go Outdated Show resolved Hide resolved
bundle/config/mutator/load_git_details.go Outdated Show resolved Hide resolved
return []diag.Diagnostic{{
Severity: severity,
Summary: fmt.Sprintf(tmpl, field, *configValue, fetchedValue, extra),
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens only if the configuration is explicitly set. Can you include the location information here? You can access it through b.Config.GetLocations() for the relevant paths in the configuration.

This means the user can Cmd-click on it to jump to the problematic location.

Separate: I see this matches the existing warning and that's fine, but this should really be broken out into a short single-line summary and longer multi-line "detail" field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this is a good change but I think it can be a follow up?

This PR focuses on the logic but keeps the message exactly the same (it just shows up in more places where relevant). Follow up PR can add location info and split summary/detail without changing the logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also prefer to have this addressed here. The PR adds additional logic for commit and url check anyway and thus the message is different, so having location info is useful.

@denik denik temporarily deployed to test-trigger-is December 9, 2024 16:54 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 9, 2024 16:59 — with GitHub Actions Inactive
@denik denik temporarily deployed to test-trigger-is December 9, 2024 17:01 — with GitHub Actions Inactive
Copy link

github-actions bot commented Dec 9, 2024

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 1940
  • Commit SHA: 48e6b9215e4d908926dc2117bba11f187dbe9fd3

Checks will be approved automatically on success.

@denik denik temporarily deployed to test-trigger-is December 9, 2024 17:01 — with GitHub Actions Inactive
@eng-dev-ecosystem-bot
Copy link
Collaborator

Test Details: go/deco-tests/12240512958

@denik
Copy link
Contributor Author

denik commented Dec 10, 2024

Thanks, this looks great!

Does the e2e coverage of LoadGitDetails cover this as well?

Not, E2E, but there is https://github.com/databricks/cli/blob/main/bundle/tests/git_test.go#L45 that checks Branch validation behavior.

@denik denik requested a review from pietern December 10, 2024 13:19
Copy link
Contributor

@andrewnester andrewnester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a potential breaking change because the validation used to happen after bundle variables were resolved but now it happens before. There's a chance (like in here #1255) that someone is using variable for Git option settings and thus validation will fail

return diags
}

func checkMatch(field, fetchedValue string, configValue *string, allowedToMismatch bool) []diag.Diagnostic {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be renamed because it has side effects of setting configValue, not simply doing the check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setIfEmptyAndCompare maybe? Which hints and maybe refactoring this into 2 separate functions but I'm fine with both

return []diag.Diagnostic{{
Severity: severity,
Summary: fmt.Sprintf(tmpl, field, *configValue, fetchedValue, extra),
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also prefer to have this addressed here. The PR adds additional logic for commit and url check anyway and thus the message is different, so having location info is useful.

@denik denik disabled auto-merge December 12, 2024 10:09
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.

5 participants