@@ -300,6 +300,13 @@ func buildBinaries(cfg *Config) error {
300300 outDir = "dist"
301301 }
302302
303+ // Clean the output directory if it exists
304+ if _ , err := os .Stat (outDir ); err == nil {
305+ if err := os .RemoveAll (outDir ); err != nil {
306+ return fmt .Errorf ("failed to clean output directory: %w" , err )
307+ }
308+ }
309+
303310 // Create the build directory
304311 if err := os .MkdirAll (outDir , 0o755 ); err != nil {
305312 return fmt .Errorf ("failed to create output directory: %w" , err )
@@ -579,6 +586,9 @@ func createArchives(cfg *Config, artifactsDir string) error {
579586 return fmt .Errorf ("failed to read artifacts directory: %w" , err )
580587 }
581588
589+ // Track which files were archived
590+ archivedFiles := make (map [string ]bool )
591+
582592 // Create archives for each file according to configuration
583593 for _ , file := range files {
584594 if file .IsDir () {
@@ -627,6 +637,8 @@ func createArchives(cfg *Config, artifactsDir string) error {
627637 if err := createTarGz (filepath .Join (artifactsDir , fileName ), archivePath ); err != nil {
628638 return fmt .Errorf ("failed to create tar.gz archive: %w" , err )
629639 }
640+ // Mark the source file as archived
641+ archivedFiles [fileName ] = true
630642 // Here you can add support for other archive formats
631643 default :
632644 log .Printf ("Unsupported archive format: %s" , format )
@@ -635,6 +647,20 @@ func createArchives(cfg *Config, artifactsDir string) error {
635647 }
636648 }
637649
650+ // Remove all source files that were archived
651+ for _ , file := range files {
652+ if file .IsDir () {
653+ continue
654+ }
655+ fileName := file .Name ()
656+ if archivedFiles [fileName ] {
657+ filePath := filepath .Join (artifactsDir , fileName )
658+ if err := os .Remove (filePath ); err != nil {
659+ log .Printf ("Warning: failed to remove source file %s: %v" , filePath , err )
660+ }
661+ }
662+ }
663+
638664 return nil
639665}
640666
0 commit comments