From 8012bc7902ebda4c24ad657f932e54aa15313b98 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Thu, 14 Sep 2023 11:16:00 +0000 Subject: [PATCH 01/13] add `prebuildDefaultBranchOnly` to `Project.settings` --- .../gitpod-protocol/go/gitpod-service.go | 1 + .../src/teams-projects-protocol.ts | 5 + .../public-api-server/pkg/apiv1/project.go | 1 + .../gitpod/experimental/v1/projects.proto | 1 + .../go/experimental/v1/projects.pb.go | 190 ++++++++++-------- .../src/gitpod/experimental/v1/projects_pb.ts | 7 + .../server/src/projects/projects-service.ts | 1 + 7 files changed, 118 insertions(+), 88 deletions(-) diff --git a/components/gitpod-protocol/go/gitpod-service.go b/components/gitpod-protocol/go/gitpod-service.go index d5fc9e7c2b677f..4f74c930edd3a1 100644 --- a/components/gitpod-protocol/go/gitpod-service.go +++ b/components/gitpod-protocol/go/gitpod-service.go @@ -2274,6 +2274,7 @@ type Project struct { type ProjectSettings struct { EnablePrebuilds *bool `json:"enablePrebuilds,omitempty"` + PrebuildDefaultBranchOnly bool `json:"prebuildDefaultBranchOnly,omitempty"` UseIncrementalPrebuilds bool `json:"useIncrementalPrebuilds,omitempty"` UsePersistentVolumeClaim bool `json:"usePersistentVolumeClaim,omitempty"` KeepOutdatedPrebuildsRunning bool `json:"keepOutdatedPrebuildsRunning,omitempty"` diff --git a/components/gitpod-protocol/src/teams-projects-protocol.ts b/components/gitpod-protocol/src/teams-projects-protocol.ts index 0a0c54f2947b88..ff0d1f06b54a20 100644 --- a/components/gitpod-protocol/src/teams-projects-protocol.ts +++ b/components/gitpod-protocol/src/teams-projects-protocol.ts @@ -15,6 +15,11 @@ export interface ProjectConfig { export interface ProjectSettings { enablePrebuilds?: boolean; + /** + * Wether prebuilds (if enabled) should only be started on the default branch. + * Defaults to `true` on project creation. + */ + prebuildDefaultBranchOnly?: boolean; useIncrementalPrebuilds?: boolean; keepOutdatedPrebuildsRunning?: boolean; // whether new workspaces can start on older prebuilds and incrementally update diff --git a/components/public-api-server/pkg/apiv1/project.go b/components/public-api-server/pkg/apiv1/project.go index 7bdc352592d32a..96ddfd1b794ce0 100644 --- a/components/public-api-server/pkg/apiv1/project.go +++ b/components/public-api-server/pkg/apiv1/project.go @@ -170,6 +170,7 @@ func projectSettingsToAPIResponse(s *protocol.ProjectSettings) *v1.ProjectSettin return &v1.ProjectSettings{ Prebuild: &v1.PrebuildSettings{ EnablePrebuilds: s.EnablePrebuilds, + PrebuildDefaultBranchOnly: s.PrebuildDefaultBranchOnly, EnableIncrementalPrebuilds: s.UseIncrementalPrebuilds, KeepOutdatedPrebuildsRunning: s.KeepOutdatedPrebuildsRunning, UsePreviousPrebuilds: s.AllowUsingPreviousPrebuilds, diff --git a/components/public-api/gitpod/experimental/v1/projects.proto b/components/public-api/gitpod/experimental/v1/projects.proto index bc9583a88ece43..5c10f4f2fbe75d 100644 --- a/components/public-api/gitpod/experimental/v1/projects.proto +++ b/components/public-api/gitpod/experimental/v1/projects.proto @@ -48,6 +48,7 @@ message PrebuildSettings { bool use_previous_prebuilds = 3; int32 prebuild_every_nth = 4; optional bool enable_prebuilds = 5; + optional bool prebuild_default_branch_only = 6; } message WorkspaceSettings { diff --git a/components/public-api/go/experimental/v1/projects.pb.go b/components/public-api/go/experimental/v1/projects.pb.go index b9a485c1fd1254..e7dafec39a19a9 100644 --- a/components/public-api/go/experimental/v1/projects.pb.go +++ b/components/public-api/go/experimental/v1/projects.pb.go @@ -188,6 +188,7 @@ type PrebuildSettings struct { UsePreviousPrebuilds bool `protobuf:"varint,3,opt,name=use_previous_prebuilds,json=usePreviousPrebuilds,proto3" json:"use_previous_prebuilds,omitempty"` PrebuildEveryNth int32 `protobuf:"varint,4,opt,name=prebuild_every_nth,json=prebuildEveryNth,proto3" json:"prebuild_every_nth,omitempty"` EnablePrebuilds *bool `protobuf:"varint,5,opt,name=enable_prebuilds,json=enablePrebuilds,proto3,oneof" json:"enable_prebuilds,omitempty"` + PrebuildDefaultBranchOnly *bool `protobuf:"varint,6,opt,name=prebuild_default_branch_only,json=prebuildDefaultBranchOnly,proto3,oneof" json:"prebuild_default_branch_only,omitempty"` } func (x *PrebuildSettings) Reset() { @@ -257,6 +258,13 @@ func (x *PrebuildSettings) GetEnablePrebuilds() bool { return false } +func (x *PrebuildSettings) GetPrebuildDefaultBranchOnly() bool { + if x != nil && x.PrebuildDefaultBranchOnly != nil { + return *x.PrebuildDefaultBranchOnly + } + return false +} + type WorkspaceSettings struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -789,7 +797,7 @@ var file_gitpod_experimental_v1_projects_proto_rawDesc = []byte{ 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x52, 0x09, 0x77, 0x6f, 0x72, 0x6b, 0x73, - 0x70, 0x61, 0x63, 0x65, 0x22, 0xc4, 0x02, 0x0a, 0x10, 0x50, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, + 0x70, 0x61, 0x63, 0x65, 0x22, 0xab, 0x03, 0x0a, 0x10, 0x50, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x40, 0x0a, 0x1c, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x5f, 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, @@ -808,97 +816,103 @@ var file_gitpod_experimental_v1_projects_proto_rawDesc = []byte{ 0x65, 0x72, 0x79, 0x4e, 0x74, 0x68, 0x12, 0x2e, 0x0a, 0x10, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x48, 0x00, 0x52, 0x0f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x72, 0x65, 0x62, 0x75, 0x69, - 0x6c, 0x64, 0x73, 0x88, 0x01, 0x01, 0x42, 0x13, 0x0a, 0x11, 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, - 0x65, 0x5f, 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x73, 0x22, 0xb1, 0x01, 0x0a, 0x11, - 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, - 0x73, 0x12, 0x43, 0x0a, 0x1e, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x65, 0x72, 0x73, - 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x63, 0x6c, - 0x61, 0x69, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x65, 0x6e, 0x61, 0x62, 0x6c, - 0x65, 0x50, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x57, 0x0a, 0x0f, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, - 0x61, 0x63, 0x65, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x2e, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, - 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, - 0x63, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x52, - 0x0e, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x22, - 0x4e, 0x0a, 0x16, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x43, 0x6c, 0x61, 0x73, - 0x73, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x67, - 0x75, 0x6c, 0x61, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x67, 0x75, - 0x6c, 0x61, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x22, - 0x51, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x39, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, - 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, - 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x22, 0x52, 0x0a, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, - 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x07, 0x70, - 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, - 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, - 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x07, 0x70, - 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x32, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, - 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x70, - 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x09, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x49, 0x64, 0x22, 0x4f, 0x0a, 0x12, 0x47, 0x65, - 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x39, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, - 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x78, 0x0a, 0x13, 0x4c, - 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x65, 0x61, 0x6d, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x65, 0x61, 0x6d, 0x49, 0x64, 0x12, 0x42, 0x0a, 0x0a, 0x70, - 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x22, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, - 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4a, - 0x04, 0x08, 0x01, 0x10, 0x02, 0x22, 0x78, 0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, - 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, - 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x6c, 0x64, 0x73, 0x88, 0x01, 0x01, 0x12, 0x44, 0x0a, 0x1c, 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, + 0x6c, 0x64, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x5f, 0x62, 0x72, 0x61, 0x6e, 0x63, + 0x68, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x48, 0x01, 0x52, 0x19, + 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x42, + 0x72, 0x61, 0x6e, 0x63, 0x68, 0x4f, 0x6e, 0x6c, 0x79, 0x88, 0x01, 0x01, 0x42, 0x13, 0x0a, 0x11, + 0x5f, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, + 0x73, 0x42, 0x1f, 0x0a, 0x1d, 0x5f, 0x70, 0x72, 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x64, + 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x5f, 0x62, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x5f, 0x6f, 0x6e, + 0x6c, 0x79, 0x22, 0xb1, 0x01, 0x0a, 0x11, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, + 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x43, 0x0a, 0x1e, 0x65, 0x6e, 0x61, 0x62, + 0x6c, 0x65, 0x5f, 0x70, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x5f, 0x76, 0x6f, + 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x1b, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x50, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, + 0x6e, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x57, 0x0a, + 0x0f, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, + 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, + 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x53, 0x65, + 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x52, 0x0e, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, + 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x22, 0x4e, 0x0a, 0x16, 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, + 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x67, 0x75, 0x6c, 0x61, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x72, 0x65, 0x67, 0x75, 0x6c, 0x61, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, + 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, + 0x65, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x22, 0x51, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x39, + 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, - 0x52, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x12, 0x23, 0x0a, 0x0d, 0x74, 0x6f, - 0x74, 0x61, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x0c, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x22, - 0x35, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x6a, 0x65, - 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, - 0x6a, 0x65, 0x63, 0x74, 0x49, 0x64, 0x22, 0x17, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, - 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, - 0xc5, 0x03, 0x0a, 0x0f, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x12, 0x6e, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, - 0x6a, 0x65, 0x63, 0x74, 0x12, 0x2c, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, - 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, - 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x12, 0x65, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, - 0x74, 0x12, 0x29, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, - 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, - 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x67, - 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, - 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x6b, 0x0a, 0x0c, 0x4c, 0x69, - 0x73, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x12, 0x2b, 0x2e, 0x67, 0x69, 0x74, - 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, - 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, - 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, - 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x6e, 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x2c, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, + 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x52, 0x0a, 0x15, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x39, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, + 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x72, 0x6f, + 0x6a, 0x65, 0x63, 0x74, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x22, 0x32, 0x0a, + 0x11, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x49, + 0x64, 0x22, 0x4f, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x39, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, + 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, - 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, + 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x6a, 0x65, + 0x63, 0x74, 0x22, 0x78, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, + 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x65, 0x61, + 0x6d, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x65, 0x61, 0x6d, + 0x49, 0x64, 0x12, 0x42, 0x0a, 0x0a, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, - 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x46, 0x5a, 0x44, 0x67, 0x69, 0x74, 0x68, 0x75, - 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2d, 0x69, 0x6f, 0x2f, - 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, - 0x73, 0x2f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2d, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x6f, 0x2f, - 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2f, 0x76, 0x31, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x50, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x70, 0x61, 0x67, 0x69, + 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x22, 0x78, 0x0a, 0x14, + 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, + 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, + 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, + 0x73, 0x12, 0x23, 0x0a, 0x0d, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x75, 0x6c, + 0x74, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x22, 0x35, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, + 0x0a, 0x0a, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x09, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x49, 0x64, 0x22, 0x17, 0x0a, + 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xc5, 0x03, 0x0a, 0x0f, 0x50, 0x72, 0x6f, 0x6a, 0x65, + 0x63, 0x74, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6e, 0x0a, 0x0d, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x2c, 0x2e, 0x67, 0x69, + 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, + 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, + 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x67, 0x69, 0x74, 0x70, + 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, + 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x65, 0x0a, 0x0a, 0x47, 0x65, + 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x29, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, + 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, + 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, + 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x6b, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, + 0x73, 0x12, 0x2b, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, + 0x69, 0x6d, 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, + 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, + 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, + 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x6a, + 0x65, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x6e, + 0x0a, 0x0d, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x12, + 0x2c, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, + 0x65, 0x6e, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, + 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, + 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2e, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, + 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x72, 0x6f, + 0x6a, 0x65, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x46, + 0x5a, 0x44, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x69, 0x74, + 0x70, 0x6f, 0x64, 0x2d, 0x69, 0x6f, 0x2f, 0x67, 0x69, 0x74, 0x70, 0x6f, 0x64, 0x2f, 0x63, 0x6f, + 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2d, + 0x61, 0x70, 0x69, 0x2f, 0x67, 0x6f, 0x2f, 0x65, 0x78, 0x70, 0x65, 0x72, 0x69, 0x6d, 0x65, 0x6e, + 0x74, 0x61, 0x6c, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/components/public-api/typescript/src/gitpod/experimental/v1/projects_pb.ts b/components/public-api/typescript/src/gitpod/experimental/v1/projects_pb.ts index aed58ac41e16f4..a36f1458bb11b9 100644 --- a/components/public-api/typescript/src/gitpod/experimental/v1/projects_pb.ts +++ b/components/public-api/typescript/src/gitpod/experimental/v1/projects_pb.ts @@ -169,6 +169,11 @@ export class PrebuildSettings extends Message { */ enablePrebuilds?: boolean; + /** + * @generated from field: optional bool prebuild_default_branch_only = 6; + */ + prebuildDefaultBranchOnly?: boolean; + constructor(data?: PartialMessage) { super(); proto3.util.initPartial(data, this); @@ -182,6 +187,7 @@ export class PrebuildSettings extends Message { { no: 3, name: "use_previous_prebuilds", kind: "scalar", T: 8 /* ScalarType.BOOL */ }, { no: 4, name: "prebuild_every_nth", kind: "scalar", T: 5 /* ScalarType.INT32 */ }, { no: 5, name: "enable_prebuilds", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, + { no: 6, name: "prebuild_default_branch_only", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): PrebuildSettings { @@ -592,3 +598,4 @@ export class DeleteProjectResponse extends Message { return proto3.util.equals(DeleteProjectResponse, a, b); } } + diff --git a/components/server/src/projects/projects-service.ts b/components/server/src/projects/projects-service.ts index 0449ddf4d52a2e..667efca0036377 100644 --- a/components/server/src/projects/projects-service.ts +++ b/components/server/src/projects/projects-service.ts @@ -30,6 +30,7 @@ import { ScmService } from "./scm-service"; export class ProjectsService { public static PROJECT_SETTINGS_DEFAULTS: ProjectSettings = { enablePrebuilds: false, + prebuildDefaultBranchOnly: true, }; constructor( From 1f349821fd62d34ca8ff68eb7470500c3a7fd3c8 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Thu, 14 Sep 2023 11:43:43 +0000 Subject: [PATCH 02/13] evaluate prebuildDefaultBranchOnly in PrebuildManager --- .../server/src/prebuilds/bitbucket-app.ts | 2 +- .../src/prebuilds/bitbucket-server-app.ts | 2 +- components/server/src/prebuilds/github-app.ts | 4 ++-- .../src/prebuilds/github-enterprise-app.ts | 2 +- components/server/src/prebuilds/gitlab-app.ts | 4 ++-- .../server/src/prebuilds/prebuild-manager.ts | 20 ++++++++++++++++--- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/components/server/src/prebuilds/bitbucket-app.ts b/components/server/src/prebuilds/bitbucket-app.ts index a2fe1545068a5b..6e1653c3c8ff80 100644 --- a/components/server/src/prebuilds/bitbucket-app.ts +++ b/components/server/src/prebuilds/bitbucket-app.ts @@ -136,7 +136,7 @@ export class BitbucketApp { commit: context.revision, }); const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); - if (!this.prebuildManager.shouldPrebuild({ config, project })) { + if (!this.prebuildManager.shouldPrebuild({ config, project, context })) { log.info("Bitbucket push event: No prebuild.", { config, context }); await this.webhookEvents.updateEvent(event.id, { prebuildStatus: "ignored_unconfigured", diff --git a/components/server/src/prebuilds/bitbucket-server-app.ts b/components/server/src/prebuilds/bitbucket-server-app.ts index 2da6a7c2c4882b..bff94b2101a557 100644 --- a/components/server/src/prebuilds/bitbucket-server-app.ts +++ b/components/server/src/prebuilds/bitbucket-server-app.ts @@ -137,7 +137,7 @@ export class BitbucketServerApp { commit: context.revision, }); const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); - if (!this.prebuildManager.shouldPrebuild({ config, project })) { + if (!this.prebuildManager.shouldPrebuild({ config, project, context })) { log.info("Bitbucket Server push event: No prebuild.", { config, context }); await this.webhookEvents.updateEvent(event.id, { prebuildStatus: "ignored_unconfigured", diff --git a/components/server/src/prebuilds/github-app.ts b/components/server/src/prebuilds/github-app.ts index 0b76b5ab76a42e..2dccdd1cf0ea23 100644 --- a/components/server/src/prebuilds/github-app.ts +++ b/components/server/src/prebuilds/github-app.ts @@ -310,7 +310,7 @@ export class GithubApp { }); const runPrebuild = - this.prebuildManager.shouldPrebuild({ config, project }) && + this.prebuildManager.shouldPrebuild({ config, project, context }) && this.appRules.shouldRunPrebuild(config, branch == repo.default_branch, false, false); if (!runPrebuild) { const reason = `Not running prebuild, the user did not enable it for this context or did not configure prebuild task(s)`; @@ -538,7 +538,7 @@ export class GithubApp { const isFork = pr.head.repo.id !== pr.base.repo.id; const runPrebuild = - this.prebuildManager.shouldPrebuild({ config, project }) && + this.prebuildManager.shouldPrebuild({ config, project, context }) && this.appRules.shouldRunPrebuild(config, false, true, isFork); if (runPrebuild) { const commitInfo = await this.getCommitInfo(user, ctx.payload.repository.html_url, pr.head.sha); diff --git a/components/server/src/prebuilds/github-enterprise-app.ts b/components/server/src/prebuilds/github-enterprise-app.ts index def1c4c15a0b0b..273e29e91eb079 100644 --- a/components/server/src/prebuilds/github-enterprise-app.ts +++ b/components/server/src/prebuilds/github-enterprise-app.ts @@ -169,7 +169,7 @@ export class GitHubEnterpriseApp { const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); if ( - !this.prebuildManager.shouldPrebuild({ config, project }) || + !this.prebuildManager.shouldPrebuild({ config, project, context }) || !this.appRules.shouldRunPrebuild(config, context.ref === context.repository.defaultBranch, false, false) ) { log.info("GitHub Enterprise push event: No prebuild.", { config, context }); diff --git a/components/server/src/prebuilds/gitlab-app.ts b/components/server/src/prebuilds/gitlab-app.ts index 843ecdd47802bf..0b411463252090 100644 --- a/components/server/src/prebuilds/gitlab-app.ts +++ b/components/server/src/prebuilds/gitlab-app.ts @@ -160,8 +160,8 @@ export class GitLabApp { commit: context.revision, }); - const config = await this.prebuildManager.fetchConfig({ span }, user, context, project.teamId); - if (!this.prebuildManager.shouldPrebuild({ config, project })) { + const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); + if (!this.prebuildManager.shouldPrebuild({ config, project, context })) { log.info("GitLab push event: No prebuild.", { config, context }); await this.webhookEvents.updateEvent(event.id, { prebuildStatus: "ignored_unconfigured", diff --git a/components/server/src/prebuilds/prebuild-manager.ts b/components/server/src/prebuilds/prebuild-manager.ts index f99e4436583926..3f74b14447c2d5 100644 --- a/components/server/src/prebuilds/prebuild-manager.ts +++ b/components/server/src/prebuilds/prebuild-manager.ts @@ -341,8 +341,8 @@ export class PrebuildManager { } } - shouldPrebuild(params: { config: WorkspaceConfig; project: Project }): boolean { - const { config, project } = params; + shouldPrebuild(params: { config: WorkspaceConfig; project: Project; context: CommitContext }): boolean { + const { config, project, context } = params; if (!config || !config._origin || config._origin !== "repo") { // we demand an explicit gitpod config return false; @@ -353,7 +353,21 @@ export class PrebuildManager { return false; } - return Project.isPrebuildsEnabled(project); + const isPrebuildsEnabled = Project.isPrebuildsEnabled(project); + if (!isPrebuildsEnabled) { + return false; + } + + if (!project.settings?.prebuildDefaultBranchOnly) { + return true; + } + + const defaultBranch = context.repository.defaultBranch; + if (!defaultBranch) { + log.debug("CommitContext is missing the default branch.", { context }); + return true; + } + return context.ref === defaultBranch; } protected shouldPrebuildIncrementally(cloneUrl: string, project: Project): boolean { From 5ce8104d1a9ad6d7367a580180eb4e45d7a44b24 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Thu, 14 Sep 2023 12:41:10 +0000 Subject: [PATCH 03/13] add "Prebuild the default branch only" checkbox --- components/dashboard/src/projects/ProjectSettings.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/dashboard/src/projects/ProjectSettings.tsx b/components/dashboard/src/projects/ProjectSettings.tsx index 20988b98f3bd3a..f06588b8654efb 100644 --- a/components/dashboard/src/projects/ProjectSettings.tsx +++ b/components/dashboard/src/projects/ProjectSettings.tsx @@ -168,6 +168,13 @@ export default function ProjectSettingsView() { /> {enablePrebuilds && ( <> + updateProjectSettings({ prebuildDefaultBranchOnly: checked })} + />
Date: Thu, 14 Sep 2023 13:15:22 +0000 Subject: [PATCH 04/13] =?UTF-8?q?fix=20missin=20PAPI=20mapping=20?= =?UTF-8?q?=F0=9F=A4=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dashboard/src/service/public-api.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/components/dashboard/src/service/public-api.ts b/components/dashboard/src/service/public-api.ts index 73bce3c8e9e76f..88ac514b6c7d76 100644 --- a/components/dashboard/src/service/public-api.ts +++ b/components/dashboard/src/service/public-api.ts @@ -108,6 +108,7 @@ export function projectToProtocol(project: Project): ProtocolProject { appInstallationId: "undefined", settings: { enablePrebuilds: project.settings?.prebuild?.enablePrebuilds, + prebuildDefaultBranchOnly: project.settings?.prebuild?.prebuildDefaultBranchOnly, allowUsingPreviousPrebuilds: project.settings?.prebuild?.usePreviousPrebuilds, keepOutdatedPrebuildsRunning: project.settings?.prebuild?.keepOutdatedPrebuildsRunning, prebuildEveryNthCommit: project.settings?.prebuild?.prebuildEveryNth, From f17e190fb3fc13875a04faf6b95c73ce41eeb25a Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Fri, 15 Sep 2023 11:55:08 +0000 Subject: [PATCH 05/13] fix PrebuildDefaultBranchOnly in gitpod-service.go --- components/gitpod-protocol/go/gitpod-service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/gitpod-protocol/go/gitpod-service.go b/components/gitpod-protocol/go/gitpod-service.go index 4f74c930edd3a1..d24aaecc38bd51 100644 --- a/components/gitpod-protocol/go/gitpod-service.go +++ b/components/gitpod-protocol/go/gitpod-service.go @@ -2274,7 +2274,7 @@ type Project struct { type ProjectSettings struct { EnablePrebuilds *bool `json:"enablePrebuilds,omitempty"` - PrebuildDefaultBranchOnly bool `json:"prebuildDefaultBranchOnly,omitempty"` + PrebuildDefaultBranchOnly *bool `json:"prebuildDefaultBranchOnly,omitempty"` UseIncrementalPrebuilds bool `json:"useIncrementalPrebuilds,omitempty"` UsePersistentVolumeClaim bool `json:"usePersistentVolumeClaim,omitempty"` KeepOutdatedPrebuildsRunning bool `json:"keepOutdatedPrebuildsRunning,omitempty"` From 4c814ee6e1a174906415bf22e3d80c3e39f15b8e Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Mon, 18 Sep 2023 08:33:32 +0000 Subject: [PATCH 06/13] turn text input into select input --- .../src/projects/ProjectSettings.tsx | 29 +++++++++++++++---- .../src/teams-projects-protocol.ts | 17 +++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/components/dashboard/src/projects/ProjectSettings.tsx b/components/dashboard/src/projects/ProjectSettings.tsx index f06588b8654efb..48e8fdb72bd9a9 100644 --- a/components/dashboard/src/projects/ProjectSettings.tsx +++ b/components/dashboard/src/projects/ProjectSettings.tsx @@ -22,6 +22,7 @@ import { useRefreshProjects } from "../data/projects/list-projects-query"; import { useToast } from "../components/toasts/Toasts"; import classNames from "classnames"; import { InputField } from "../components/forms/InputField"; +import { SelectInputField } from "../components/forms/SelectInputField"; export function ProjectSettingsPage(props: { project?: Project; children?: React.ReactNode }) { return ( @@ -92,6 +93,16 @@ export default function ProjectSettingsView() { [project, setProject, toast], ); + const setPrebuildBranchStrategy = useCallback( + async (value: ProjectSettings.PrebuildBranchStrategy) => { + const prebuildDefaultBranchOnly = value === "defaultBranch"; + await updateProjectSettings({ + prebuildDefaultBranchOnly, + }); + }, + [updateProjectSettings], + ); + const setWorkspaceClass = useCallback( async (value: string) => { if (!project) { @@ -125,6 +136,8 @@ export default function ProjectSettingsView() { const enablePrebuilds = Project.isPrebuildsEnabled(project); + const prebuildBranchStrategy = Project.getPrebuildBranchStrategy(project); + return ( Project Name @@ -168,13 +181,17 @@ export default function ProjectSettingsView() { /> {enablePrebuilds && ( <> - updateProjectSettings({ prebuildDefaultBranchOnly: checked })} - /> + label="Build branches" + value={prebuildBranchStrategy} + topMargin={false} + onChange={(val) => setPrebuildBranchStrategy(val as ProjectSettings.PrebuildBranchStrategy)} + > + + + {/* */} +
Date: Mon, 18 Sep 2023 09:47:43 +0000 Subject: [PATCH 07/13] update styles on project settings page --- .../src/projects/ProjectSettings.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/components/dashboard/src/projects/ProjectSettings.tsx b/components/dashboard/src/projects/ProjectSettings.tsx index 48e8fdb72bd9a9..59cc96c6586e26 100644 --- a/components/dashboard/src/projects/ProjectSettings.tsx +++ b/components/dashboard/src/projects/ProjectSettings.tsx @@ -185,21 +185,23 @@ export default function ProjectSettingsView() { disabled={!enablePrebuilds} label="Build branches" value={prebuildBranchStrategy} - topMargin={false} + containerClassName="max-w-md ml-6 text-sm" onChange={(val) => setPrebuildBranchStrategy(val as ProjectSettings.PrebuildBranchStrategy)} > - + {/* */} - -
- -
+ + Date: Tue, 19 Sep 2023 06:02:13 +0000 Subject: [PATCH 08/13] mimic old behavior for pre-existing projects --- components/gitpod-protocol/src/teams-projects-protocol.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/gitpod-protocol/src/teams-projects-protocol.ts b/components/gitpod-protocol/src/teams-projects-protocol.ts index 3f51bc4c04a1b3..b0023c74ee5f14 100644 --- a/components/gitpod-protocol/src/teams-projects-protocol.ts +++ b/components/gitpod-protocol/src/teams-projects-protocol.ts @@ -84,7 +84,9 @@ export namespace Project { export function getPrebuildBranchStrategy(project: Project): ProjectSettings.PrebuildBranchStrategy { if (typeof project.settings?.enablePrebuilds === "undefined") { - return "defaultBranch"; // default value for `settings.prebuildDefaultBranchOnly` + // returning "all branches" to mimic the default value of projects which were added + // before introduction of persisted settings for prebuilds. + return "allBranches"; } if (typeof project.settings?.prebuildDefaultBranchOnly === "undefined") { return "defaultBranch"; // default value for `settings.prebuildDefaultBranchOnly` From d53d9eb7f7ab33f97971d8224620fa86a6936e58 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Tue, 19 Sep 2023 06:02:58 +0000 Subject: [PATCH 09/13] use getPrebuildBranchStrategy in PrebuildManager --- .../server/src/prebuilds/prebuild-manager.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/components/server/src/prebuilds/prebuild-manager.ts b/components/server/src/prebuilds/prebuild-manager.ts index 3f74b14447c2d5..f24ee819a1dd5f 100644 --- a/components/server/src/prebuilds/prebuild-manager.ts +++ b/components/server/src/prebuilds/prebuild-manager.ts @@ -358,16 +358,26 @@ export class PrebuildManager { return false; } - if (!project.settings?.prebuildDefaultBranchOnly) { + const strategy = Project.getPrebuildBranchStrategy(project); + if (strategy === "allBranches") { return true; } - const defaultBranch = context.repository.defaultBranch; - if (!defaultBranch) { - log.debug("CommitContext is missing the default branch.", { context }); - return true; + if (strategy === "defaultBranch") { + const defaultBranch = context.repository.defaultBranch; + if (!defaultBranch) { + log.debug("CommitContext is missing the default branch. Ignoring request.", { context }); + return false; + } + return context.ref === defaultBranch; + } + + if (strategy === "selectedBranches") { + // TODO support "selectedBranches" next } - return context.ref === defaultBranch; + + log.debug("Unknown prebuild branch strategy. Ignoring request.", { context, config }); + return false; } protected shouldPrebuildIncrementally(cloneUrl: string, project: Project): boolean { From 9aac05a0d30f84260ab188c11ee1fbc4af296b0a Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Wed, 20 Sep 2023 11:02:22 +0000 Subject: [PATCH 10/13] add tests for PrebuildManager.prebuildPrecondition --- .../server/src/prebuilds/bitbucket-app.ts | 4 +- .../src/prebuilds/bitbucket-server-app.ts | 4 +- components/server/src/prebuilds/github-app.ts | 8 +- .../src/prebuilds/github-enterprise-app.ts | 4 +- components/server/src/prebuilds/gitlab-app.ts | 4 +- .../src/prebuilds/prebuild-manager.spec.ts | 199 ++++++++++++++++++ .../server/src/prebuilds/prebuild-manager.ts | 26 ++- 7 files changed, 231 insertions(+), 18 deletions(-) create mode 100644 components/server/src/prebuilds/prebuild-manager.spec.ts diff --git a/components/server/src/prebuilds/bitbucket-app.ts b/components/server/src/prebuilds/bitbucket-app.ts index 6e1653c3c8ff80..9486b4bbab9b55 100644 --- a/components/server/src/prebuilds/bitbucket-app.ts +++ b/components/server/src/prebuilds/bitbucket-app.ts @@ -136,11 +136,13 @@ export class BitbucketApp { commit: context.revision, }); const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); - if (!this.prebuildManager.shouldPrebuild({ config, project, context })) { + const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); + if (!prebuildPrecondition.shouldRun) { log.info("Bitbucket push event: No prebuild.", { config, context }); await this.webhookEvents.updateEvent(event.id, { prebuildStatus: "ignored_unconfigured", status: "processed", + message: prebuildPrecondition.reason, }); return undefined; } diff --git a/components/server/src/prebuilds/bitbucket-server-app.ts b/components/server/src/prebuilds/bitbucket-server-app.ts index bff94b2101a557..34f6be72d9ec2b 100644 --- a/components/server/src/prebuilds/bitbucket-server-app.ts +++ b/components/server/src/prebuilds/bitbucket-server-app.ts @@ -137,11 +137,13 @@ export class BitbucketServerApp { commit: context.revision, }); const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); - if (!this.prebuildManager.shouldPrebuild({ config, project, context })) { + const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); + if (!prebuildPrecondition.shouldRun) { log.info("Bitbucket Server push event: No prebuild.", { config, context }); await this.webhookEvents.updateEvent(event.id, { prebuildStatus: "ignored_unconfigured", status: "processed", + message: prebuildPrecondition.reason, }); return undefined; } diff --git a/components/server/src/prebuilds/github-app.ts b/components/server/src/prebuilds/github-app.ts index 2dccdd1cf0ea23..afada83e9357bf 100644 --- a/components/server/src/prebuilds/github-app.ts +++ b/components/server/src/prebuilds/github-app.ts @@ -308,9 +308,9 @@ export class GithubApp { branch: context.ref, commit: context.revision, }); - + const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); const runPrebuild = - this.prebuildManager.shouldPrebuild({ config, project, context }) && + prebuildPrecondition.shouldRun && this.appRules.shouldRunPrebuild(config, branch == repo.default_branch, false, false); if (!runPrebuild) { const reason = `Not running prebuild, the user did not enable it for this context or did not configure prebuild task(s)`; @@ -537,9 +537,9 @@ export class GithubApp { const contextURL = pr.html_url; const isFork = pr.head.repo.id !== pr.base.repo.id; + const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); const runPrebuild = - this.prebuildManager.shouldPrebuild({ config, project, context }) && - this.appRules.shouldRunPrebuild(config, false, true, isFork); + prebuildPrecondition.shouldRun && this.appRules.shouldRunPrebuild(config, false, true, isFork); if (runPrebuild) { const commitInfo = await this.getCommitInfo(user, ctx.payload.repository.html_url, pr.head.sha); const result = await this.prebuildManager.startPrebuild(tracecContext, { diff --git a/components/server/src/prebuilds/github-enterprise-app.ts b/components/server/src/prebuilds/github-enterprise-app.ts index 273e29e91eb079..65c4b8d289d1c6 100644 --- a/components/server/src/prebuilds/github-enterprise-app.ts +++ b/components/server/src/prebuilds/github-enterprise-app.ts @@ -168,8 +168,9 @@ export class GitHubEnterpriseApp { }); const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); + const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); if ( - !this.prebuildManager.shouldPrebuild({ config, project, context }) || + !prebuildPrecondition.shouldRun || !this.appRules.shouldRunPrebuild(config, context.ref === context.repository.defaultBranch, false, false) ) { log.info("GitHub Enterprise push event: No prebuild.", { config, context }); @@ -177,6 +178,7 @@ export class GitHubEnterpriseApp { await this.webhookEvents.updateEvent(event.id, { prebuildStatus: "ignored_unconfigured", status: "processed", + message: prebuildPrecondition.reason, }); return undefined; } diff --git a/components/server/src/prebuilds/gitlab-app.ts b/components/server/src/prebuilds/gitlab-app.ts index 0b411463252090..f1144238abbaf0 100644 --- a/components/server/src/prebuilds/gitlab-app.ts +++ b/components/server/src/prebuilds/gitlab-app.ts @@ -161,11 +161,13 @@ export class GitLabApp { }); const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); - if (!this.prebuildManager.shouldPrebuild({ config, project, context })) { + const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); + if (!prebuildPrecondition.shouldRun) { log.info("GitLab push event: No prebuild.", { config, context }); await this.webhookEvents.updateEvent(event.id, { prebuildStatus: "ignored_unconfigured", status: "processed", + message: prebuildPrecondition.reason, }); return undefined; } diff --git a/components/server/src/prebuilds/prebuild-manager.spec.ts b/components/server/src/prebuilds/prebuild-manager.spec.ts new file mode 100644 index 00000000000000..399ad37c9f9c47 --- /dev/null +++ b/components/server/src/prebuilds/prebuild-manager.spec.ts @@ -0,0 +1,199 @@ +/** + * Copyright (c) 2023 Gitpod GmbH. All rights reserved. + * Licensed under the GNU Affero General Public License (AGPL). + * See License.AGPL.txt in the project root for license information. + */ + +import { Container, ContainerModule } from "inversify"; +import "mocha"; +import * as chai from "chai"; +import { PrebuildManager } from "./prebuild-manager"; +import { TracedWorkspaceDB } from "@gitpod/gitpod-db/lib"; +import { WorkspaceService } from "../workspace/workspace-service"; +import { HostContextProvider } from "../auth/host-context-provider"; +import { ConfigProvider } from "../workspace/config-provider"; +import { Config } from "../config"; +import { ProjectsService } from "../projects/projects-service"; +import { IncrementalPrebuildsService } from "./incremental-prebuilds-service"; +import { EntitlementService } from "../billing/entitlement-service"; +import { CommitContext, Project, ProjectSettings, Repository, WorkspaceConfig } from "@gitpod/gitpod-protocol"; + +const expect = chai.expect; + +const containerModule = new ContainerModule((bind) => { + bind(PrebuildManager).toSelf().inSingletonScope(); + + // #region: mocked dependencies of PrebuildManager + bind(TracedWorkspaceDB).toConstantValue({} as any); + bind(WorkspaceService).toConstantValue({} as any); + bind(HostContextProvider).toConstantValue({} as any); + bind(ConfigProvider).toConstantValue({} as any); + bind(Config).toConstantValue({} as any); + bind(ProjectsService).toConstantValue({} as any); + bind(IncrementalPrebuildsService).toConstantValue({} as any); + bind(EntitlementService).toConstantValue({} as any); + // #endregion +}); + +const container = new Container(); +container.load(containerModule); + +const createPrebuildManager = () => container.get(PrebuildManager); + +describe("PrebuildManager", () => { + const config: WorkspaceConfig = { + _origin: "repo", + tasks: [ + { + name: "foo", + init: "./foo", + }, + ], + }; + const context: CommitContext = { + title: "", + repository: { + defaultBranch: "main", + } as Repository, + revision: "", + ref: "main", + }; + const settings: ProjectSettings = { + enablePrebuilds: false, + }; + const project = { + settings, + } as Project; + + function clone(o: T, fn: (clone: T) => void) { + const clone = JSON.parse(JSON.stringify(o)); + fn(clone); + return clone; + } + + const checkPrebuildPreconditionCases = [ + { + title: "no-config", + shouldRun: false, + reason: "no-gitpod-config-in-repo", + config: clone(config, (c) => (c._origin = undefined)), + context, + project, + }, + { + title: "no-tasks", + shouldRun: false, + reason: "no-tasks-in-gitpod-config", + config: clone(config, (c) => (c.tasks = [])), + context, + project, + }, + { + title: "pre-existing-project/enable-by-default(1)", + shouldRun: true, + reason: "all-branches-selected", + config, + context, + project: clone(project, (p) => (p.settings = undefined)), + }, + { + title: "pre-existing-project/enable-by-default(2)", + shouldRun: true, + reason: "all-branches-selected", + config, + context, + project: clone(project, (p) => delete p.settings), + }, + { + title: "prebuilds-not-enabled", + shouldRun: false, + reason: "prebuilds-not-enabled", + config, + context, + project: clone(project, (p) => (p.settings!.enablePrebuilds = false)), + }, + { + title: "default-branch-only/matched(1)", + shouldRun: true, + reason: "default-branch-matched", + config, + context, + project: clone( + project, + (p) => + (p.settings = { + enablePrebuilds: true, + prebuildDefaultBranchOnly: true, + }), + ), + }, + { + title: "default-branch-only/matched(2)", + shouldRun: true, + reason: "default-branch-matched", + config, + context, + project: clone( + project, + (p) => + (p.settings = { + enablePrebuilds: true, + prebuildDefaultBranchOnly: undefined, + }), + ), + }, + { + title: "default-branch-only/unmatched", + shouldRun: false, + reason: "default-branch-unmatched", + config, + context: clone(context, (c) => (c.ref = "feature-branch")), + project: clone( + project, + (p) => + (p.settings = { + enablePrebuilds: true, + prebuildDefaultBranchOnly: true, + }), + ), + }, + { + title: "default-branch-only/default-branch-missing-in-context", + shouldRun: false, + reason: "default-branch-missing-in-commit-context", + config, + context: clone(context, (c) => delete c.repository.defaultBranch), + project: clone( + project, + (p) => + (p.settings = { + enablePrebuilds: true, + prebuildDefaultBranchOnly: true, + }), + ), + }, + { + title: "all-branches/matched", + shouldRun: true, + reason: "all-branches-selected", + config, + context: clone(context, (c) => (c.ref = "feature-branch")), + project: clone( + project, + (p) => + (p.settings = { + enablePrebuilds: true, + prebuildDefaultBranchOnly: false, + }), + ), + }, + ]; + + for (const { title, config, context, project, shouldRun, reason } of checkPrebuildPreconditionCases) { + it(`checkPrebuildPrecondition/${title}`, async () => { + const manager = createPrebuildManager(); + const precondition = manager.checkPrebuildPrecondition({ project, config, context }); + expect(precondition).to.deep.equal({ shouldRun, reason }); + }); + } +}); diff --git a/components/server/src/prebuilds/prebuild-manager.ts b/components/server/src/prebuilds/prebuild-manager.ts index f24ee819a1dd5f..7a07c2cd4473a9 100644 --- a/components/server/src/prebuilds/prebuild-manager.ts +++ b/components/server/src/prebuilds/prebuild-manager.ts @@ -4,7 +4,7 @@ * See License.AGPL.txt in the project root for license information. */ -import { DBWithTracing, TeamDB, TracedWorkspaceDB, WorkspaceDB } from "@gitpod/gitpod-db/lib"; +import { DBWithTracing, TracedWorkspaceDB, WorkspaceDB } from "@gitpod/gitpod-db/lib"; import { CommitContext, CommitInfo, @@ -59,7 +59,6 @@ export class PrebuildManager { @inject(Config) protected readonly config: Config; @inject(ProjectsService) protected readonly projectService: ProjectsService; @inject(IncrementalPrebuildsService) protected readonly incrementalPrebuildsService: IncrementalPrebuildsService; - @inject(TeamDB) protected readonly teamDB: TeamDB; @inject(EntitlementService) protected readonly entitlementService: EntitlementService; async abortPrebuildsForBranch(ctx: TraceContext, project: Project, user: User, branch: string): Promise { @@ -341,35 +340,42 @@ export class PrebuildManager { } } - shouldPrebuild(params: { config: WorkspaceConfig; project: Project; context: CommitContext }): boolean { + checkPrebuildPrecondition(params: { config: WorkspaceConfig; project: Project; context: CommitContext }): { + shouldRun: boolean; + reason: string; + } { const { config, project, context } = params; if (!config || !config._origin || config._origin !== "repo") { // we demand an explicit gitpod config - return false; + return { shouldRun: false, reason: "no-gitpod-config-in-repo" }; } const hasPrebuildTask = !!config.tasks && config.tasks.find((t) => !!t.before || !!t.init || !!t.prebuild); if (!hasPrebuildTask) { - return false; + return { shouldRun: false, reason: "no-tasks-in-gitpod-config" }; } const isPrebuildsEnabled = Project.isPrebuildsEnabled(project); if (!isPrebuildsEnabled) { - return false; + return { shouldRun: false, reason: "prebuilds-not-enabled" }; } const strategy = Project.getPrebuildBranchStrategy(project); if (strategy === "allBranches") { - return true; + return { shouldRun: true, reason: "all-branches-selected" }; } if (strategy === "defaultBranch") { const defaultBranch = context.repository.defaultBranch; if (!defaultBranch) { log.debug("CommitContext is missing the default branch. Ignoring request.", { context }); - return false; + return { shouldRun: false, reason: "default-branch-missing-in-commit-context" }; } - return context.ref === defaultBranch; + + if (context.ref === defaultBranch) { + return { shouldRun: true, reason: "default-branch-matched" }; + } + return { shouldRun: false, reason: "default-branch-unmatched" }; } if (strategy === "selectedBranches") { @@ -377,7 +383,7 @@ export class PrebuildManager { } log.debug("Unknown prebuild branch strategy. Ignoring request.", { context, config }); - return false; + return { shouldRun: false, reason: "unknown-strategy" }; } protected shouldPrebuildIncrementally(cloneUrl: string, project: Project): boolean { From fc3e77df8f46464994d14865c7b318f13eeff6e4 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Wed, 20 Sep 2023 11:15:57 +0000 Subject: [PATCH 11/13] fix getPrebuildEvents --- components/server/src/projects/projects-service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/components/server/src/projects/projects-service.ts b/components/server/src/projects/projects-service.ts index 667efca0036377..c0ec8e7c976644 100644 --- a/components/server/src/projects/projects-service.ts +++ b/components/server/src/projects/projects-service.ts @@ -423,6 +423,7 @@ export class ProjectsService { prebuildId: we.prebuildId, projectId: we.projectId, status: we.prebuildStatus || we.status, + message: we.message, })); } } From 6ec7dae25e9ebc9d2cf5d8582701c9d6dccbd8f6 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Wed, 20 Sep 2023 12:37:31 +0000 Subject: [PATCH 12/13] explicit settings under the project should have precedence --- components/gitpod-protocol/src/protocol.ts | 4 ++ .../src/teams-projects-protocol.ts | 10 +++-- .../server/src/prebuilds/github-app-rules.ts | 12 +++++- .../server/src/prebuilds/github-app.spec.ts | 1 + components/server/src/prebuilds/github-app.ts | 37 ++++++++++--------- .../src/prebuilds/github-enterprise-app.ts | 9 +++-- .../server/src/prebuilds/prebuild-manager.ts | 2 +- 7 files changed, 48 insertions(+), 27 deletions(-) diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index 8339ef1d77635d..94274db1b71d82 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -1366,6 +1366,10 @@ export namespace CommitContext { } return hasher.digest("hex"); } + + export function isDefaultBranch(commitContext: CommitContext): boolean { + return commitContext.ref === commitContext.repository.defaultBranch; + } } export interface GitCheckoutInfo extends Commit { diff --git a/components/gitpod-protocol/src/teams-projects-protocol.ts b/components/gitpod-protocol/src/teams-projects-protocol.ts index b0023c74ee5f14..d2cc710a95f8e4 100644 --- a/components/gitpod-protocol/src/teams-projects-protocol.ts +++ b/components/gitpod-protocol/src/teams-projects-protocol.ts @@ -75,15 +75,19 @@ export namespace Project { // Defaulting to `true` for backwards compatibility. Ignoring non-boolean for `enablePrebuilds` // for evaluation here allows to do any explicit migration of data or adjustment of the default // behavior at a later point in time. - if (typeof project.settings?.enablePrebuilds === "undefined") { + if (!hasPrebuildSettings(project)) { return true; } - return project.settings.enablePrebuilds; + return !!project.settings?.enablePrebuilds; + } + + export function hasPrebuildSettings(project: Project) { + return !(typeof project.settings?.enablePrebuilds === "undefined"); } export function getPrebuildBranchStrategy(project: Project): ProjectSettings.PrebuildBranchStrategy { - if (typeof project.settings?.enablePrebuilds === "undefined") { + if (!hasPrebuildSettings(project)) { // returning "all branches" to mimic the default value of projects which were added // before introduction of persisted settings for prebuilds. return "allBranches"; diff --git a/components/server/src/prebuilds/github-app-rules.ts b/components/server/src/prebuilds/github-app-rules.ts index b9e316df8e5fb9..553f65be17c55f 100644 --- a/components/server/src/prebuilds/github-app-rules.ts +++ b/components/server/src/prebuilds/github-app-rules.ts @@ -34,13 +34,23 @@ export class GithubAppRules { return deepmerge(defaultConfig, cfg.github); } + /** + * + * @deprecated + */ public shouldRunPrebuild( config: WorkspaceConfig | undefined, isDefaultBranch: boolean, isPR: boolean, isFork: boolean, ): boolean { - if (!config) { + if (!config || !config._origin || config._origin !== "repo") { + // we demand an explicit gitpod config + return false; + } + + const hasPrebuildTask = !!config.tasks && config.tasks.find((t) => !!t.before || !!t.init || !!t.prebuild); + if (!hasPrebuildTask) { return false; } diff --git a/components/server/src/prebuilds/github-app.spec.ts b/components/server/src/prebuilds/github-app.spec.ts index 900f4ee7f2ac8b..4dfe5bf9e2ef8c 100644 --- a/components/server/src/prebuilds/github-app.spec.ts +++ b/components/server/src/prebuilds/github-app.spec.ts @@ -35,6 +35,7 @@ describe("GitHub app", () => { prebuilds: pbcfg, }, tasks: [{ init: "ls" }], + _origin: "repo", }; chai.assert.equal( diff --git a/components/server/src/prebuilds/github-app.ts b/components/server/src/prebuilds/github-app.ts index afada83e9357bf..1c4d2a15fab8dc 100644 --- a/components/server/src/prebuilds/github-app.ts +++ b/components/server/src/prebuilds/github-app.ts @@ -309,16 +309,19 @@ export class GithubApp { commit: context.revision, }); const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); - const runPrebuild = - prebuildPrecondition.shouldRun && - this.appRules.shouldRunPrebuild(config, branch == repo.default_branch, false, false); - if (!runPrebuild) { - const reason = `Not running prebuild, the user did not enable it for this context or did not configure prebuild task(s)`; + + const shouldRun = Project.hasPrebuildSettings(project) + ? prebuildPrecondition.shouldRun + : this.appRules.shouldRunPrebuild(config, CommitContext.isDefaultBranch(context), false, false); + + if (!shouldRun) { + const reason = `GitHub push event: No prebuild.`; log.debug(logCtx, reason, { contextURL }); span.log({ "not-running": reason, config: config }); await this.webhookEvents.updateEvent(event.id, { prebuildStatus: "ignored_unconfigured", status: "processed", + message: prebuildPrecondition.reason, }); return; } @@ -538,9 +541,12 @@ export class GithubApp { const isFork = pr.head.repo.id !== pr.base.repo.id; const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); - const runPrebuild = - prebuildPrecondition.shouldRun && this.appRules.shouldRunPrebuild(config, false, true, isFork); - if (runPrebuild) { + + const shouldRun = Project.hasPrebuildSettings(project) + ? prebuildPrecondition.shouldRun + : this.appRules.shouldRunPrebuild(config, false, true, isFork); + + if (shouldRun) { const commitInfo = await this.getCommitInfo(user, ctx.payload.repository.html_url, pr.head.sha); const result = await this.prebuildManager.startPrebuild(tracecContext, { user, @@ -553,16 +559,11 @@ export class GithubApp { } return result; } else { - log.debug( - { userId: user.id }, - `Not running prebuild, the user did not enable it for this context or did not configure prebuild task(s)`, - null, - { - contextURL, - userId: user.id, - project, - }, - ); + log.debug({ userId: user.id }, `GitHub push event: No prebuild.`, { + contextURL, + userId: user.id, + project, + }); return; } } diff --git a/components/server/src/prebuilds/github-enterprise-app.ts b/components/server/src/prebuilds/github-enterprise-app.ts index 65c4b8d289d1c6..bb451f04e98da6 100644 --- a/components/server/src/prebuilds/github-enterprise-app.ts +++ b/components/server/src/prebuilds/github-enterprise-app.ts @@ -169,10 +169,11 @@ export class GitHubEnterpriseApp { const config = await this.prebuildManager.fetchConfig({ span }, user, context, project?.teamId); const prebuildPrecondition = this.prebuildManager.checkPrebuildPrecondition({ config, project, context }); - if ( - !prebuildPrecondition.shouldRun || - !this.appRules.shouldRunPrebuild(config, context.ref === context.repository.defaultBranch, false, false) - ) { + + const shouldRun = Project.hasPrebuildSettings(project) + ? prebuildPrecondition.shouldRun + : this.appRules.shouldRunPrebuild(config, CommitContext.isDefaultBranch(context), false, false); + if (!shouldRun) { log.info("GitHub Enterprise push event: No prebuild.", { config, context }); await this.webhookEvents.updateEvent(event.id, { diff --git a/components/server/src/prebuilds/prebuild-manager.ts b/components/server/src/prebuilds/prebuild-manager.ts index 7a07c2cd4473a9..35ef5e139270bb 100644 --- a/components/server/src/prebuilds/prebuild-manager.ts +++ b/components/server/src/prebuilds/prebuild-manager.ts @@ -372,7 +372,7 @@ export class PrebuildManager { return { shouldRun: false, reason: "default-branch-missing-in-commit-context" }; } - if (context.ref === defaultBranch) { + if (CommitContext.isDefaultBranch(context)) { return { shouldRun: true, reason: "default-branch-matched" }; } return { shouldRun: false, reason: "default-branch-unmatched" }; From 31a14091f05d1a46b878b563f1ff0f6f9d691dcd Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Fri, 22 Sep 2023 09:39:30 +0000 Subject: [PATCH 13/13] render changes to project settings immediately --- components/dashboard/src/projects/ProjectSettings.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/dashboard/src/projects/ProjectSettings.tsx b/components/dashboard/src/projects/ProjectSettings.tsx index 59cc96c6586e26..0a5d4065a6f381 100644 --- a/components/dashboard/src/projects/ProjectSettings.tsx +++ b/components/dashboard/src/projects/ProjectSettings.tsx @@ -82,15 +82,18 @@ export default function ProjectSettingsView() { async (settings: ProjectSettings) => { if (!project) return; + const oldSettings = { ...project.settings }; const newSettings = { ...project.settings, ...settings }; + setProject({ ...project, settings: newSettings }); try { await getGitpodService().server.updateProjectPartial({ id: project.id, settings: newSettings }); - setProject({ ...project, settings: newSettings }); + toast(`Project ${projectName} updated.`); } catch (error) { + setProject({ ...project, settings: oldSettings }); toast(error?.message || "Oh no, there was a problem with updating project settings."); } }, - [project, setProject, toast], + [project, setProject, toast, projectName], ); const setPrebuildBranchStrategy = useCallback(