Skip to content

Commit 284933e

Browse files
committed
Enable default workflows config by default
1 parent a5cbb06 commit 284933e

File tree

8 files changed

+94
-12
lines changed

8 files changed

+94
-12
lines changed

docs/workflows-config.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ sidebar_label: Workflows configuration
55
---
66

77
Once you've linked your repo to BuildBuddy via
8-
[BuildBuddy workflows](workflows-setup.md), BuildBuddy will automatically
9-
run `bazel test //...` on each push to your repo, reporting results to the
10-
BuildBuddy UI.
8+
[BuildBuddy workflows](workflows-setup.md), there are two ways to start running Workflows.
119

12-
But you may wish to configure multiple test commands with different test
10+
The default workflow config runs `bazel test //...` whenever a commit is pushed to your repo's default branch or a pull request branch is updated. In order to enable this, click `Enable default workflow config`
11+
in the three-dot dropdown for your repository on the Workflows page.
12+
13+
You may wish to configure multiple test commands with different test
1314
tag filters, or run the same tests on multiple different platform
1415
configurations (running some tests on Linux, and some on macOS, for
1516
example).

docs/workflows-setup.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ To enable workflows, take the following steps:
3333

3434
## Running workflows
3535

36-
Once a repository is linked, BuildBuddy will automatically run `bazel test //...` whenever a commit is pushed to your repo's default branch
37-
or whenever a pull request branch is updated. It will report commit
38-
statuses to GitHub, which you can see on the repo's home page or in pull
39-
request branches. The "Details" links in these statuses point to the
40-
BuildBuddy UI, where you can see the result of the workflow run.
36+
After you've linked a repository, there are two ways to start running Workflows:
4137

42-
## Configuring your workflow
38+
The default workflow config runs `bazel test //...` whenever a commit is pushed to your repo's default branch or a pull request branch is updated. In order to enable this, click `Enable default workflow config`
39+
in the three-dot dropdown for your repository on the Workflows page.
4340

44-
To learn how to change the default configuration, see [workflows configuration](workflows-config.md).
41+
In order to configure more complex workflows - i.e. different trigger conditions or running different commands - you will need to add a file called `buildbuddy.yaml` to the root of your git repo. See [workflows configuration](workflows-config.md) for more details..
42+
43+
Workflows will report commit statuses to GitHub, which you can see on the repo's home page or in pull request branches. The "Details" links in these statuses point to the BuildBuddy UI, where you can see the result of the workflow run.
4544

4645
## Setting up branch protection rules
4746

enterprise/server/githubapp/githubapp.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,13 @@ func (s *GitHubAppService) GetLinkedGitHubRepos(ctx context.Context) (*ghpb.GetL
271271
`, u.GetGroupID())
272272
res := &ghpb.GetLinkedReposResponse{}
273273
err = db.ScanEach(rq, func(ctx context.Context, row *tables.GitRepository) error {
274+
// TODO(Maggie): Clean up after BE change is deployed
274275
res.RepoUrls = append(res.RepoUrls, row.RepoURL)
276+
277+
res.Repos = append(res.Repos, &ghpb.GitRepository{
278+
RepoUrl: row.RepoURL,
279+
UseDefaultWorkflowConfig: row.UseDefaultWorkflowConfig,
280+
})
275281
return nil
276282
})
277283
if err != nil {
@@ -862,6 +868,31 @@ func (a *GitHubApp) UnlinkGitHubRepo(ctx context.Context, req *ghpb.UnlinkRepoRe
862868
return &ghpb.UnlinkRepoResponse{}, nil
863869
}
864870

871+
func (a *GitHubApp) UpdateRepoSettings(ctx context.Context, req *ghpb.UpdateRepoSettingsRequest) (*ghpb.UpdateRepoSettingsResponse, error) {
872+
norm, err := gitutil.NormalizeRepoURL(req.GetRepoUrl())
873+
if err != nil {
874+
return nil, status.InvalidArgumentErrorf("failed to parse repo URL: %s", err)
875+
}
876+
normalizedURL := norm.String()
877+
u, err := a.env.GetAuthenticator().AuthenticatedUser(ctx)
878+
if err != nil {
879+
return nil, err
880+
}
881+
result := a.env.GetDBHandle().NewQuery(ctx, "githubapp_update_repo_settings").Raw(`
882+
UPDATE "GitRepositories"
883+
SET use_default_workflow_config = ?
884+
WHERE group_id = ?
885+
AND repo_url = ?
886+
`, req.GetUseDefaultWorkflowConfig(), u.GetGroupID(), normalizedURL).Exec()
887+
if result.Error != nil {
888+
return nil, status.InternalErrorf("failed to update repo settings: %s", result.Error)
889+
}
890+
if result.RowsAffected == 0 {
891+
return nil, status.NotFoundError("repo not found")
892+
}
893+
return &ghpb.UpdateRepoSettingsResponse{}, nil
894+
}
895+
865896
func (a *GitHubApp) GetAccessibleGitHubRepos(ctx context.Context, req *ghpb.GetAccessibleReposRequest) (*ghpb.GetAccessibleReposResponse, error) {
866897
req.Query = strings.TrimSpace(req.Query)
867898

proto/buildbuddy_service.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ service BuildBuddyService {
205205
rpc LinkGitHubRepo(github.LinkRepoRequest) returns (github.LinkRepoResponse);
206206
rpc UnlinkGitHubRepo(github.UnlinkRepoRequest)
207207
returns (github.UnlinkRepoResponse);
208+
rpc UpdateGitHubRepoSettings(github.UpdateRepoSettingsRequest)
209+
returns (github.UpdateRepoSettingsResponse);
208210

209211
// Installation-repos API (authenticates w/ GitHub using
210212
// installation access token)

proto/github.proto

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,24 @@ message GetLinkedReposRequest {
182182
context.RequestContext request_context = 1;
183183
}
184184

185+
message GitRepository {
186+
string repo_url = 1;
187+
188+
// Whether to use the default workflow config if buildbuddy.yaml is missing.
189+
// If enabled, workflows will automatically start running for a git repo when linked,
190+
// even if buildbuddy.yaml is missing from the repo. If disabled, workflows will only run
191+
// when buildbuddy.yaml is present in the repo.
192+
bool use_default_workflow_config = 2;
193+
}
194+
185195
message GetLinkedReposResponse {
186196
context.ResponseContext response_context = 1;
187197

188-
repeated string repo_urls = 2;
198+
repeated GitRepository repos = 3;
199+
200+
// DEPRECATED: Use repos instead.
201+
repeated string repo_urls = 2 [deprecated = true];
202+
189203
}
190204

191205
// A request to link a repo to the authenticated org.
@@ -218,6 +232,18 @@ message UnlinkRepoResponse {
218232
context.ResponseContext response_context = 1;
219233
}
220234

235+
message UpdateRepoSettingsRequest {
236+
context.RequestContext request_context = 1;
237+
238+
string repo_url = 2;
239+
240+
bool use_default_workflow_config = 3;
241+
}
242+
243+
message UpdateRepoSettingsResponse {
244+
context.ResponseContext response_context = 1;
245+
}
246+
221247
message GetGithubAppInstallPathRequest {
222248
context.RequestContext request_context = 1;
223249
}

server/buildbuddy_server/buildbuddy_server.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,27 @@ func (s *BuildBuddyServer) UnlinkGitHubRepo(ctx context.Context, req *ghpb.Unlin
17561756
}
17571757
return rsp, nil
17581758
}
1759+
1760+
func (s *BuildBuddyServer) UpdateGitHubRepoSettings(ctx context.Context, req *ghpb.UpdateRepoSettingsRequest) (*ghpb.UpdateRepoSettingsResponse, error) {
1761+
gh := s.env.GetGitHubAppService()
1762+
if gh == nil {
1763+
return nil, status.UnimplementedError("Not implemented")
1764+
}
1765+
repo, err := git.ParseGitHubRepoURL(req.GetRepoUrl())
1766+
if err != nil {
1767+
return nil, err
1768+
}
1769+
a, err := gh.GetGitHubAppForOwner(ctx, repo.Owner)
1770+
if err != nil {
1771+
return nil, err
1772+
}
1773+
rsp, err := a.UpdateRepoSettings(ctx, req)
1774+
if err != nil {
1775+
return nil, err
1776+
}
1777+
return rsp, nil
1778+
}
1779+
17591780
func (s *BuildBuddyServer) GetGitHubAppInstallPath(ctx context.Context, req *ghpb.GetGithubAppInstallPathRequest) (*ghpb.GetGithubAppInstallPathResponse, error) {
17601781
gh := s.env.GetGitHubAppService()
17611782
if gh == nil {

server/capabilities_filter/capabilities_filter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ var (
166166
"GetGitHubAppInstallPath",
167167
"LinkGitHubRepo",
168168
"UnlinkGitHubRepo",
169+
"UpdateGitHubRepoSettings",
169170
// Org API key management
170171
"CreateApiKey",
171172
"UpdateApiKey",

server/interfaces/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ type GitHubApp interface {
682682

683683
LinkGitHubRepo(ctx context.Context, repoURL string) (*ghpb.LinkRepoResponse, error)
684684
UnlinkGitHubRepo(context.Context, *ghpb.UnlinkRepoRequest) (*ghpb.UnlinkRepoResponse, error)
685+
UpdateRepoSettings(context.Context, *ghpb.UpdateRepoSettingsRequest) (*ghpb.UpdateRepoSettingsResponse, error)
685686

686687
GetAccessibleGitHubRepos(context.Context, *ghpb.GetAccessibleReposRequest) (*ghpb.GetAccessibleReposResponse, error)
687688

0 commit comments

Comments
 (0)