@@ -22,6 +22,7 @@ import (
2222 "log/slog"
2323 "os"
2424 "strings"
25+ "time"
2526
2627 cloudbuild "cloud.google.com/go/cloudbuild/apiv1/v2"
2728 "cloud.google.com/go/cloudbuild/apiv1/v2/cloudbuildpb"
@@ -63,7 +64,7 @@ func (c *wrappedCloudBuildClient) ListBuildTriggers(ctx context.Context, req *cl
6364}
6465
6566// RunCommand triggers a command for each registered repository that supports it.
66- func RunCommand (ctx context.Context , command string , projectId string , push bool , build bool ) error {
67+ func RunCommand (ctx context.Context , command string , projectId string , push bool , build bool , forceRun bool ) error {
6768 c , err := cloudbuild .NewClient (ctx )
6869 if err != nil {
6970 return fmt .Errorf ("error creating cloudbuild client: %w" , err )
@@ -76,25 +77,32 @@ func RunCommand(ctx context.Context, command string, projectId string, push bool
7677 if err != nil {
7778 return fmt .Errorf ("error creating github client: %w" , err )
7879 }
79- return runCommandWithClient (ctx , wrappedClient , ghClient , command , projectId , push , build )
80+ return runCommandWithClient (ctx , wrappedClient , ghClient , command , projectId , push , build , forceRun , time . Now () )
8081}
8182
82- func runCommandWithClient (ctx context.Context , client CloudBuildClient , ghClient GitHubClient , command string , projectId string , push bool , build bool ) error {
83+ func runCommandWithClient (ctx context.Context , client CloudBuildClient , ghClient GitHubClient , command string , projectId string , push bool , build bool , forceRun bool , dateTime time. Time ) error {
8384 config , err := loadRepositoriesConfig ()
8485 if err != nil {
8586 slog .Error ("error loading repositories config" , slog .Any ("err" , err ))
8687 return err
8788 }
88- return runCommandWithConfig (ctx , client , ghClient , command , projectId , push , build , config )
89+ return runCommandWithConfig (ctx , client , ghClient , command , projectId , push , build , forceRun , config , dateTime )
8990}
9091
91- func runCommandWithConfig (ctx context.Context , client CloudBuildClient , ghClient GitHubClient , command string , projectId string , push bool , build bool , config * RepositoriesConfig ) error {
92+ func runCommandWithConfig (ctx context.Context , client CloudBuildClient , ghClient GitHubClient , command string , projectId string , push bool , build bool , forceRun bool , config * RepositoriesConfig , dateTime time. Time ) error {
9293 // validate command is allowed
9394 triggerName := triggerNameByCommandName [command ]
9495 if triggerName == "" {
95- return fmt .Errorf ("unsuppoted command: %s" , command )
96+ return fmt .Errorf ("unsupported command: %s" , command )
9697 }
9798
99+ if triggerName == "stage-release" {
100+ _ , week := dateTime .ISOWeek ()
101+ if week % 2 == 0 && ! forceRun {
102+ slog .Info ("Skipping stage-release on an even week." )
103+ return nil
104+ }
105+ }
98106 errs := make ([]error , 0 )
99107
100108 repositories := config .RepositoriesForCommand (command )
0 commit comments