diff --git a/bot/internal/bot/verify.go b/bot/internal/bot/verify.go index a624d2d9..d30b32e5 100644 --- a/bot/internal/bot/verify.go +++ b/bot/internal/bot/verify.go @@ -16,20 +16,40 @@ import ( // Verify is a catch-all for verifying the PR doesn't have any issues. func (b *Bot) Verify(ctx context.Context) error { + var err error switch b.c.Environment.Repository { + case env.AccessGraphRepo: + err = b.verifyAccessGraph(ctx) case env.CloudRepo: - err := b.verifyCloud(ctx) - if err != nil { - return trace.Wrap(err) - } + err = b.verifyCloud(ctx) } - return nil + return trace.Wrap(err) +} + +// verifyAccessGraph runs verification checks for the access-graph repo. +func (b *Bot) verifyAccessGraph(ctx context.Context) error { + // exec DB migration verification + return trace.Wrap(b.verifyDBMigrations(ctx)) } // verifyCloud runs verification checks for cloud repos. // E.g. it is used to verify DB migration files are ordered properly in the Cloud repo. func (b *Bot) verifyCloud(ctx context.Context) error { // exec DB migration verification + return trace.Wrap(b.verifyDBMigrations(ctx)) +} + +// migrationConfig enables the DB migration verification for a repo/path. +// +// map[repo]: [...path] +var migrationConfig = map[string][]string{ + env.AccessGraphRepo: {"migrations/public", "migrations/tenant"}, + env.CloudRepo: {"db/salescenter/migrations"}, +} + +// verifyDBMigrations runs verifyDBMigration for each +// of the migration paths defined for the current repository +func (b *Bot) verifyDBMigrations(ctx context.Context) error { for _, path := range migrationConfig[b.c.Environment.Repository] { err := b.verifyDBMigration(ctx, path) if err != nil { @@ -39,12 +59,6 @@ func (b *Bot) verifyCloud(ctx context.Context) error { return nil } -// migrationConfig enables the DB migration verification for a repo/path. -// map[repo]: [...path] -var migrationConfig = map[string][]string{ - env.CloudRepo: []string{"db/salescenter/migrations"}, -} - // verifyDBMigration ensures the DB migration files in a PR have a timestamp // that is more recent than the migration files in the base branch. func (b *Bot) verifyDBMigration(ctx context.Context, pathPrefix string) error { @@ -77,7 +91,7 @@ func (b *Bot) verifyDBMigration(ctx context.Context, pathPrefix string) error { // no PR migration files if len(prIDs) == 0 { - log.Print("Verify:cloudDBMigration: no migration files in this PR") + log.Printf("Verify:cloudDBMigration: no migration files in %s in this PR", pathPrefix) return nil } @@ -132,7 +146,7 @@ func (b *Bot) verifyDBMigration(ctx context.Context, pathPrefix string) error { // the prefix ID of each file or returns an error if the file does not have an // integer prefix. The returned IDs are sorted in ascending order. // -// 202301031500_subscription-alter.up.sql => 202301031500 +// 202301031500_subscription-alter.up.sql => 202301031500 func parseMigrationFileIDs(pathPrefix string, files []string) ([]int, error) { var ids []int for _, file := range files { diff --git a/bot/internal/env/env.go b/bot/internal/env/env.go index da4ae3ee..63b0fd72 100644 --- a/bot/internal/env/env.go +++ b/bot/internal/env/env.go @@ -27,9 +27,10 @@ import ( const ( // Repo slugs - CloudRepo = "cloud" - TeleportRepo = "teleport" - TeleportERepo = "teleport.e" + AccessGraphRepo = "access-graph" + CloudRepo = "cloud" + TeleportRepo = "teleport" + TeleportERepo = "teleport.e" // Teams CoreTeam = "Core" diff --git a/bot/main.go b/bot/main.go index 82776603..0a48cb52 100644 --- a/bot/main.go +++ b/bot/main.go @@ -36,7 +36,7 @@ import ( func main() { flags, err := parseFlags() if err != nil { - log.Fatalf("Failed to parse flags: %v.", err) + log.Fatalf("Failed to parse flags: %#v.", err) } // Cancel run if it takes longer than 5 minutes. @@ -48,7 +48,7 @@ func main() { b, err := createBot(ctx, flags) if err != nil { - log.Fatalf("Failed to create bot: %v.", err) + log.Fatalf("Failed to create bot: %#v.", err) } log.Printf("Running %v.", flags.workflow)