66 "fmt"
77 "log"
88 "os"
9+ "os/exec"
10+ "path/filepath"
911 "strings"
1012 "time"
1113
@@ -291,8 +293,64 @@ func (rm *ReleaseManager) DeleteRemoteTag(version string) error {
291293 return nil
292294}
293295
294- // CreateGitHubRelease creates a GitHub release (optional)
295- func (rm * ReleaseManager ) CreateGitHubRelease (version string ) error {
296+ // BuildCLIBinaries builds CLI binaries for multiple architectures
297+ func (rm * ReleaseManager ) BuildCLIBinaries (version string ) ([]string , error ) {
298+ // Define target platforms
299+ platforms := []struct {
300+ GOOS string
301+ GOARCH string
302+ name string
303+ }{
304+ {"linux" , "amd64" , "linux-amd64" },
305+ {"linux" , "arm64" , "linux-arm64" },
306+ {"darwin" , "amd64" , "darwin-amd64" },
307+ {"darwin" , "arm64" , "darwin-arm64" },
308+ {"windows" , "amd64" , "windows-amd64" },
309+ }
310+
311+ // Create output directory
312+ outputDir := "release-binaries"
313+ if err := os .MkdirAll (outputDir , 0755 ); err != nil {
314+ return nil , fmt .Errorf ("failed to create output directory: %w" , err )
315+ }
316+
317+ var binaries []string
318+
319+ for _ , platform := range platforms {
320+ outputName := fmt .Sprintf ("dbos-%s-%s" , version , platform .name )
321+ if platform .GOOS == "windows" {
322+ outputName += ".exe"
323+ }
324+ outputPath := filepath .Join (outputDir , outputName )
325+
326+ fmt .Printf ("Building CLI for %s/%s...\n " , platform .GOOS , platform .GOARCH )
327+
328+ cmd := exec .Command ("go" , "build" ,
329+ "-ldflags" , fmt .Sprintf ("-X main.Version=%s" , version ),
330+ "-o" , outputPath ,
331+ "./dbos/cmd" )
332+
333+ cmd .Env = append (os .Environ (),
334+ fmt .Sprintf ("GOOS=%s" , platform .GOOS ),
335+ fmt .Sprintf ("GOARCH=%s" , platform .GOARCH ),
336+ "CGO_ENABLED=0" ,
337+ )
338+
339+ output , err := cmd .CombinedOutput ()
340+ if err != nil {
341+ return nil , fmt .Errorf ("failed to build for %s/%s: %w\n Output: %s" ,
342+ platform .GOOS , platform .GOARCH , err , output )
343+ }
344+
345+ binaries = append (binaries , outputPath )
346+ fmt .Printf ("✓ Built %s\n " , outputName )
347+ }
348+
349+ return binaries , nil
350+ }
351+
352+ // CreateGitHubRelease creates a GitHub release with CLI binaries
353+ func (rm * ReleaseManager ) CreateGitHubRelease (version string , binaries []string ) error {
296354 ctx := context .Background ()
297355
298356 v , err := semver .NewVersion (version )
@@ -301,14 +359,14 @@ func (rm *ReleaseManager) CreateGitHubRelease(version string) error {
301359 }
302360
303361 release := & github.RepositoryRelease {
304- TagName : github .String (version ),
305- TargetCommitish : github .String ("main" ),
306- Name : github .String (fmt .Sprintf ("Release %s" , version )),
307- Prerelease : github .Bool (v .Prerelease () != "" ),
308- GenerateReleaseNotes : github .Bool (true ),
362+ TagName : github .Ptr (version ),
363+ TargetCommitish : github .Ptr ("main" ),
364+ Name : github .Ptr (fmt .Sprintf ("Release %s" , version )),
365+ Prerelease : github .Ptr (v .Prerelease () != "" ),
366+ GenerateReleaseNotes : github .Ptr (true ),
309367 }
310368
311- _ , _ , err = rm .client .Repositories .CreateRelease (
369+ createdRelease , _ , err : = rm .client .Repositories .CreateRelease (
312370 ctx ,
313371 rm .githubOwner ,
314372 rm .githubRepo ,
@@ -320,6 +378,36 @@ func (rm *ReleaseManager) CreateGitHubRelease(version string) error {
320378 }
321379
322380 fmt .Printf ("✓ GitHub release %s created\n " , version )
381+
382+ // Upload CLI binaries as release assets
383+ for _ , binaryPath := range binaries {
384+ file , err := os .Open (binaryPath )
385+ if err != nil {
386+ fmt .Printf ("Warning: failed to open binary %s: %v\n " , binaryPath , err )
387+ continue
388+ }
389+ defer file .Close ()
390+
391+ opts := & github.UploadOptions {
392+ Name : filepath .Base (binaryPath ),
393+ }
394+
395+ _ , _ , err = rm .client .Repositories .UploadReleaseAsset (
396+ ctx ,
397+ rm .githubOwner ,
398+ rm .githubRepo ,
399+ * createdRelease .ID ,
400+ opts ,
401+ file ,
402+ )
403+
404+ if err != nil {
405+ fmt .Printf ("Warning: failed to upload %s: %v\n " , filepath .Base (binaryPath ), err )
406+ } else {
407+ fmt .Printf ("✓ Uploaded %s\n " , filepath .Base (binaryPath ))
408+ }
409+ }
410+
323411 return nil
324412}
325413
@@ -389,11 +477,39 @@ func main() {
389477 log .Fatalf ("Failed to create release branch: %v" , err )
390478 }
391479
392- // Optionally create GitHub release
480+ // Build CLI binaries for multiple platforms
481+ fmt .Printf ("\n Building CLI binaries...\n " )
482+ binaries , err := rm .BuildCLIBinaries (version )
483+ if err != nil {
484+ // Rollback: delete the remote tag
485+ if deleteErr := rm .DeleteRemoteTag (version ); deleteErr != nil {
486+ fmt .Printf ("Warning: failed to cleanup remote tag %s: %v\n " , version , deleteErr )
487+ }
488+ // Delete the local tag
489+ if deleteErr := rm .repo .DeleteTag (version ); deleteErr != nil {
490+ fmt .Printf ("Warning: failed to cleanup local tag %s: %v\n " , version , deleteErr )
491+ }
492+ log .Fatalf ("Failed to build CLI binaries: %v" , err )
493+ }
494+
495+ // Create GitHub release with CLI binaries
393496 fmt .Printf ("\n Creating GitHub release...\n " )
394- if err := rm .CreateGitHubRelease (version ); err != nil {
497+ if err := rm .CreateGitHubRelease (version , binaries ); err != nil {
498+ // Rollback: delete the remote tag
499+ if deleteErr := rm .DeleteRemoteTag (version ); deleteErr != nil {
500+ fmt .Printf ("Warning: failed to cleanup remote tag %s: %v\n " , version , deleteErr )
501+ }
502+ // Delete the local tag
503+ if deleteErr := rm .repo .DeleteTag (version ); deleteErr != nil {
504+ fmt .Printf ("Warning: failed to cleanup local tag %s: %v\n " , version , deleteErr )
505+ }
395506 log .Fatalf ("Failed to create GitHub release: %v" , err )
396507 }
397508
509+ // Clean up binaries directory
510+ if err := os .RemoveAll ("release-binaries" ); err != nil {
511+ fmt .Printf ("Warning: failed to cleanup release-binaries directory: %v\n " , err )
512+ }
513+
398514 fmt .Printf ("\n 🎉 Release %s completed successfully!\n " , version )
399515}
0 commit comments