Skip to content

Commit 3b9e401

Browse files
committed
merge main, resolve conflicts from MeasureChart refactor (#8752)
Conflict resolution: - `annotations-selectors.ts`: adopt main's `createAnnotationsQuery` API (flat params, `select` transform) and convert to use `RuntimeClient` - `queries.ts`: merge imports, use v2 request-priorities path - `MeasuresContainer.svelte`: take main's `chartWhere`/`chartReady` pattern - `MetricsTimeSeriesCharts.svelte`: take main's structural changes (exploreValidSpec, handlePan, chartReady), use v2 `useRuntimeClient` Semantic fixes (auto-merged but broken): - `MeasureBigNumber.svelte`: convert from `instanceId` prop to `useRuntimeClient()` context; update `createQueryServiceMetricsViewAggregation` to v2 call signature - `MeasureChart.svelte`: same conversion for `createQueryServiceMetricsViewTimeSeries`, `createDimensionAggregationQuery`, `createAnnotationsQuery`; replace `HTTPError` with `ConnectError` - `use-dimension-data.ts`: convert `createDimensionAggregationQuery` from `instanceId` to `RuntimeClient`; replace `HTTPError` with `ConnectError`
2 parents fc5c049 + 658f941 commit 3b9e401

178 files changed

Lines changed: 7363 additions & 8065 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cli/cmd/deploy/deploy_test.go

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,56 @@ func TestManagedDeploy(t *testing.T) {
7575
verifyGithubRepoContents(t, ghClient, resp.Project.GitRemote, changes)
7676
}
7777

78+
func TestManagedDeployWithPrimaryBranch(t *testing.T) {
79+
testmode.Expensive(t)
80+
adm := testadmin.New(t)
81+
82+
_, c := adm.NewUser(t)
83+
u1 := testcli.New(t, adm, c.Token)
84+
85+
result := u1.Run(t, "org", "create", "github-branch-test")
86+
require.Equal(t, 0, result.ExitCode)
87+
88+
// set up a git repo with two branches having different content:
89+
// - main: models/model.sql contains SELECT 'main' AS env
90+
// - staging: models/model.sql contains SELECT 'staging' AS env
91+
// The repo is left on the staging branch for the deploy.
92+
tempDir := initRillProject(t)
93+
initGitWithTwoBranches(t, tempDir)
94+
95+
result = u1.Run(t, "project", "deploy", "--interactive=false", "--org=github-branch-test", "--project=rill-mgd-branch", "--skip-deploy=true", "--primary-branch=staging", "--path="+tempDir)
96+
require.Equal(t, 0, result.ExitCode, result.Output)
97+
98+
// verify the project is correctly created
99+
resp, err := c.GetProject(t.Context(), &adminv1.GetProjectRequest{
100+
Org: "github-branch-test",
101+
Project: "rill-mgd-branch",
102+
})
103+
require.NoError(t, err)
104+
require.Equal(t, "rill-mgd-branch", resp.Project.Name)
105+
106+
// verify the primary branch is set to "staging"
107+
require.Equal(t, "staging", resp.Project.PrimaryBranch)
108+
109+
// get a github client
110+
installationID, err := adm.Admin.Github.ManagedOrgInstallationID()
111+
require.NoError(t, err)
112+
ghClient := adm.Admin.Github.InstallationClient(installationID, nil)
113+
114+
// cleanup repo
115+
t.Cleanup(func() {
116+
owner, repo, ok := gitutil.SplitGithubRemote(resp.Project.GitRemote)
117+
require.True(t, ok, "invalid github remote: %s", resp.Project.GitRemote)
118+
_, err = ghClient.Repositories.Delete(context.Background(), owner, repo)
119+
require.NoError(t, err, "failed to delete github repo %s/%s: %v", owner, repo, err)
120+
})
121+
122+
// verify the model file is present on the "staging" branch
123+
verifyGithubRepoBranchContents(t, ghClient, resp.Project.GitRemote, "staging", map[string]string{
124+
"models/model.sql": `SELECT 'staging' AS env`,
125+
})
126+
}
127+
78128
// This test require gh cli to be installed on the system.
79129
// Alternatively a personal access token can be set via RILL_TEST_GH_TOKEN environment variable.
80130
// TODO: Set personal acccess token for CI/CD tests.
@@ -286,12 +336,23 @@ func testSelfHostedMonorepoDeploy(t *testing.T, adminClient *client.Client, ghCl
286336
}
287337

288338
func verifyGithubRepoContents(t *testing.T, client *github.Client, remote string, changes map[string]string) {
339+
t.Helper()
340+
verifyGithubRepoBranchContents(t, client, remote, "", changes)
341+
}
342+
343+
func verifyGithubRepoBranchContents(t *testing.T, client *github.Client, remote string, branch string, changes map[string]string) {
344+
t.Helper()
289345
owner, repo, ok := gitutil.SplitGithubRemote(remote)
290346
require.True(t, ok, "invalid github remote: %s", remote)
291347

348+
var opts *github.RepositoryContentGetOptions
349+
if branch != "" {
350+
opts = &github.RepositoryContentGetOptions{Ref: branch}
351+
}
352+
292353
// TODO: consider downloading the repo and checking the files locally instead of making multiple API calls
293354
for path, expectedContent := range changes {
294-
con, _, _, err := client.Repositories.GetContents(t.Context(), owner, repo, path, nil)
355+
con, _, _, err := client.Repositories.GetContents(t.Context(), owner, repo, path, opts)
295356
require.NoError(t, err)
296357
contents, err := con.GetContent()
297358
require.NoError(t, err)
@@ -381,6 +442,39 @@ olap_connector: duckdb`,
381442
return tempDir
382443
}
383444

445+
// initGitWithTwoBranches initializes a git repository in dir with two branches:
446+
// - "main" with models/model.sql = SELECT 'main' AS env
447+
// - "staging" with models/model.sql = SELECT 'staging' AS env
448+
// The repo is left checked out on the "staging" branch.
449+
func initGitWithTwoBranches(t *testing.T, dir string) {
450+
t.Helper()
451+
runGitCmd := func(args ...string) {
452+
cmd := exec.Command("git", args...)
453+
cmd.Dir = dir
454+
out, err := cmd.CombinedOutput()
455+
require.NoError(t, err, "git %v failed: %s", args, out)
456+
}
457+
458+
runGitCmd("init", "-b", "main")
459+
runGitCmd("config", "user.email", "test@rilldata.com")
460+
runGitCmd("config", "user.name", "Rill Test User")
461+
462+
// commit initial content on main
463+
putFiles(t, dir, map[string]string{
464+
"models/model.sql": `SELECT 'main' AS env`,
465+
})
466+
runGitCmd("add", ".")
467+
runGitCmd("commit", "-m", "initial commit on main")
468+
469+
// create staging branch with different content
470+
runGitCmd("checkout", "-b", "staging")
471+
putFiles(t, dir, map[string]string{
472+
"models/model.sql": `SELECT 'staging' AS env`,
473+
})
474+
runGitCmd("add", ".")
475+
runGitCmd("commit", "-m", "staging changes")
476+
}
477+
384478
func cloneRepo(ctx context.Context, repoURL, path string) error {
385479
cmd := exec.CommandContext(ctx, "git", "clone", repoURL, path)
386480
out, err := cmd.CombinedOutput()

cli/cmd/project/deploy.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,12 @@ func DeployWithUploadFlow(ctx context.Context, ch *cmdutil.Helper, opts *DeployO
402402
}
403403
req.ArchiveAssetId = assetID
404404
} else {
405-
gitRepo, err := ch.GitHelper(ch.Org, opts.Name, localProjectPath).PushToNewManagedRepo(ctx)
405+
gitRepo, err := ch.GitHelper(ch.Org, opts.Name, localProjectPath).PushToNewManagedRepo(ctx, opts.PrimaryBranch)
406406
if err != nil {
407407
return err
408408
}
409409
req.GitRemote = gitRepo.Remote
410+
req.PrimaryBranch = gitRepo.DefaultBranch
410411
}
411412
printer.ColorGreenBold.Printf("All files uploaded successfully.\n\n")
412413

@@ -506,14 +507,15 @@ func redeployProject(ctx context.Context, ch *cmdutil.Helper, opts *DeployOpts)
506507
}
507508
} else {
508509
// need to migrate to rill managed git
509-
gitRepo, err := ch.GitHelper(ch.Org, opts.Name, opts.LocalProjectPath()).PushToNewManagedRepo(ctx)
510+
gitRepo, err := ch.GitHelper(ch.Org, opts.Name, opts.LocalProjectPath()).PushToNewManagedRepo(ctx, opts.PrimaryBranch)
510511
if err != nil {
511512
return err
512513
}
513514
updateProjReq = &adminv1.UpdateProjectRequest{
514-
Org: ch.Org,
515-
Project: opts.Name,
516-
GitRemote: &gitRepo.Remote,
515+
Org: ch.Org,
516+
Project: opts.Name,
517+
GitRemote: &gitRepo.Remote,
518+
PrimaryBranch: &gitRepo.DefaultBranch,
517519
}
518520
}
519521
// Update the project

cli/pkg/cmdutil/githelper.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (g *GitHelper) GitConfig(ctx context.Context) (*gitutil.Config, error) {
7676
return g.gitConfig, nil
7777
}
7878

79-
func (g *GitHelper) PushToNewManagedRepo(ctx context.Context) (*adminv1.CreateManagedGitRepoResponse, error) {
79+
func (g *GitHelper) PushToNewManagedRepo(ctx context.Context, primaryBranch string) (*adminv1.CreateManagedGitRepoResponse, error) {
8080
c, err := g.h.Client()
8181
if err != nil {
8282
return nil, err
@@ -89,6 +89,11 @@ func (g *GitHelper) PushToNewManagedRepo(ctx context.Context) (*adminv1.CreateMa
8989
if err != nil {
9090
return nil, err
9191
}
92+
// git does not allow setting default branch on repo on creation
93+
// but there is no restriction to push to any branch so directly update default branch here
94+
if primaryBranch != "" {
95+
gitRepo.DefaultBranch = primaryBranch
96+
}
9297
author, err := g.h.GitSignature(ctx, g.localPath)
9398
if err != nil {
9499
return nil, err
@@ -101,6 +106,7 @@ func (g *GitHelper) PushToNewManagedRepo(ctx context.Context) (*adminv1.CreateMa
101106
DefaultBranch: gitRepo.DefaultBranch,
102107
ManagedRepo: true,
103108
}
109+
104110
err = gitutil.CommitAndPush(ctx, g.localPath, config, "", author)
105111
if err != nil {
106112
return nil, err

cli/pkg/local/server.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ func (s *Server) DeployProject(ctx context.Context, r *connect.Request[localv1.D
353353
ArchiveAssetId: assetID,
354354
}
355355
} else if r.Msg.Upload { // upload repo to rill managed storage instead of github
356-
ghRepo, err := s.app.ch.GitHelper(r.Msg.Org, r.Msg.ProjectName, s.app.ProjectPath).PushToNewManagedRepo(ctx)
356+
gitBranch, err := currentGitBranch(s.app.ProjectPath)
357+
if err != nil {
358+
return nil, err
359+
}
360+
ghRepo, err := s.app.ch.GitHelper(r.Msg.Org, r.Msg.ProjectName, s.app.ProjectPath).PushToNewManagedRepo(ctx, gitBranch)
357361
if err != nil {
358362
return nil, err
359363
}
@@ -369,6 +373,7 @@ func (s *Server) DeployProject(ctx context.Context, r *connect.Request[localv1.D
369373
Public: false,
370374
DirectoryName: directoryName,
371375
GitRemote: ghRepo.Remote,
376+
PrimaryBranch: ghRepo.DefaultBranch,
372377
}
373378
} else {
374379
userStatus, err := c.GetGithubUserStatus(ctx, &adminv1.GetGithubUserStatusRequest{})
@@ -528,14 +533,19 @@ func (s *Server) RedeployProject(ctx context.Context, r *connect.Request[localv1
528533
}
529534
} else if projResp.Project.ArchiveAssetId != "" || r.Msg.CreateManagedRepo {
530535
// project was previously deployed using zip and ship, or we are overwriting another project already connected to github
531-
ghRepo, err := s.app.ch.GitHelper(projResp.Project.OrgName, projResp.Project.Name, s.app.ProjectPath).PushToNewManagedRepo(ctx)
536+
gitBranch, err := currentGitBranch(s.app.ProjectPath)
537+
if err != nil {
538+
return nil, err
539+
}
540+
ghRepo, err := s.app.ch.GitHelper(projResp.Project.OrgName, projResp.Project.Name, s.app.ProjectPath).PushToNewManagedRepo(ctx, gitBranch)
532541
if err != nil {
533542
return nil, err
534543
}
535544
_, err = c.UpdateProject(ctx, &adminv1.UpdateProjectRequest{
536-
Org: projResp.Project.OrgName,
537-
Project: projResp.Project.Name,
538-
GitRemote: &ghRepo.Remote,
545+
Org: projResp.Project.OrgName,
546+
Project: projResp.Project.Name,
547+
GitRemote: &ghRepo.Remote,
548+
PrimaryBranch: &ghRepo.DefaultBranch,
539549
})
540550
if err != nil {
541551
return nil, err
@@ -1058,3 +1068,20 @@ func (s *Server) traceHandler() http.Handler {
10581068
}
10591069
})
10601070
}
1071+
1072+
// currentGitBranch returns the current git branch of the repository at the given path.
1073+
// It does not return error if the repo does not exist.
1074+
func currentGitBranch(path string) (string, error) {
1075+
repo, err := git.PlainOpen(path)
1076+
if err != nil {
1077+
return "", nil
1078+
}
1079+
head, err := repo.Head()
1080+
if err != nil {
1081+
return "", err
1082+
}
1083+
if head.Name().IsBranch() {
1084+
return head.Name().Short(), nil
1085+
}
1086+
return "", fmt.Errorf("HEAD is not a branch. Checkout a branch to deploy")
1087+
}

netlify.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
Content-Security-Policy = """\
1313
default-src 'self'; \
1414
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.usepylon.com https://*.pusher.com; \
15-
style-src 'self' 'unsafe-inline'; \
15+
style-src 'self' 'unsafe-inline' https://*.usepylon.com; \
1616
img-src https: data: blob:; \
1717
frame-src 'self' https://www.youtube.com/ https://www.loom.com/ https://www.vimeo.com https://portal.withorb.com blob: data:; \
1818
frame-ancestors 'self'; \
1919
form-action 'self'; \
2020
object-src 'none'; \
21-
connect-src 'self' https://*.rilldata.com https://*.usepylon.com https://docs.google.com https://storage.googleapis.com https://cdn.prod.website-files.com https://*.stripe.com wss://*.pusher.com; \
21+
connect-src 'self' https://*.rilldata.com https://*.rilldata.io https://*.rilldata.in https://*.usepylon.com https://docs.google.com https://storage.googleapis.com https://cdn.prod.website-files.com https://*.stripe.com wss://*.pusher.com; \
2222
font-src 'self' https://fonts.gstatic.com https://*.usepylon.com;
2323
"""
2424
Permissions-Policy = "geolocation=(),midi=(),sync-xhr=(self),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()"
@@ -42,7 +42,7 @@
4242
frame-ancestors https:; \
4343
form-action 'self'; \
4444
object-src 'none'; \
45-
connect-src 'self' https://*.rilldata.com https://*.usepylon.com https://docs.google.com https://storage.googleapis.com https://cdn.prod.website-files.com https://*.stripe.com wss://*.pusher.com; \
45+
connect-src 'self' https://*.rilldata.com https://*.rilldata.io https://*.rilldata.in https://*.usepylon.com https://docs.google.com https://storage.googleapis.com https://cdn.prod.website-files.com https://*.stripe.com wss://*.pusher.com; \
4646
font-src 'self' https://fonts.gstatic.com https://*.usepylon.com;
4747
"""
4848

@@ -59,6 +59,6 @@
5959
frame-ancestors https:; \
6060
form-action 'self'; \
6161
object-src 'none'; \
62-
connect-src 'self' https://*.rilldata.com https://*.usepylon.com https://docs.google.com https://storage.googleapis.com https://cdn.prod.website-files.com https://*.stripe.com wss://*.pusher.com; \
62+
connect-src 'self' https://*.rilldata.com https://*.rilldata.io https://*.rilldata.in https://*.usepylon.com https://docs.google.com https://storage.googleapis.com https://cdn.prod.website-files.com https://*.stripe.com wss://*.pusher.com; \
6363
font-src 'self' https://fonts.gstatic.com https://*.usepylon.com;
6464
"""

0 commit comments

Comments
 (0)