@@ -504,7 +504,7 @@ func (tasks *BuildReleaseTasks) addBuildTasks(wd *wf.Definition, major int, vers
504
504
blockers = append (blockers , match )
505
505
if target .GOOS == "windows" {
506
506
zip = wf .Task1 (wd , "Get binary from distpack" , tasks .binaryArchiveFromDistpack , distpack )
507
- tar = wf .Task1 (wd , "Convert to .tgz" , tasks .convertZipToTGZ , zip )
507
+ tar = wf .Task1 (wd , "Convert zip to .tgz" , tasks .convertZipToTGZ , zip )
508
508
} else {
509
509
tar = wf .Task1 (wd , "Get binary from distpack" , tasks .binaryArchiveFromDistpack , distpack )
510
510
}
@@ -524,9 +524,10 @@ func (tasks *BuildReleaseTasks) addBuildTasks(wd *wf.Definition, major int, vers
524
524
case "darwin" :
525
525
pkg := wf .Task2 (wd , "Build PKG installer" , tasks .buildDarwinPKG , version , tar )
526
526
signedPKG := wf .Task2 (wd , "Sign PKG installer" , tasks .signArtifact , pkg , wf .Const (sign .BuildMacOS ))
527
- signedTGZ := wf .Task1 (wd , "Convert to .tgz" , tasks .convertPKGToTGZ , signedPKG )
527
+ signedTGZ := wf .Task1 (wd , "Convert PKG to .tgz" , tasks .convertPKGToTGZ , signedPKG )
528
+ mergedTGZ := wf .Task2 (wd , "Merge signed files into .tgz" , tasks .mergeSignedToTGZ , tar , signedTGZ )
528
529
mod = wf .Task4 (wd , "Merge signed files into module zip" , tasks .mergeSignedToModule , version , timestamp , mod , signedTGZ )
529
- artifacts = append (artifacts , signedPKG , signedTGZ )
530
+ artifacts = append (artifacts , signedPKG , mergedTGZ )
530
531
case "windows" :
531
532
msi := wf .Task1 (wd , "Build MSI installer" , tasks .buildWindowsMSI , tar )
532
533
signedMSI := wf .Task2 (wd , "Sign MSI installer" , tasks .signArtifact , msi , wf .Const (sign .BuildWindows ))
@@ -788,37 +789,68 @@ func (b *BuildReleaseTasks) modFilesFromBinary(ctx *wf.TaskContext, version stri
788
789
return result , nil
789
790
}
790
791
791
- func (b * BuildReleaseTasks ) mergeSignedToModule (ctx * wf.TaskContext , version string , timestamp time.Time , mod moduleArtifact , signed artifact ) (moduleArtifact , error ) {
792
- a , err := b .runBuildStep (ctx , nil , nil , signed , "signedmod.zip" , func (_ * task.BuildletStep , signed io.Reader , w io.Writer ) error {
793
- // Load binaries from the signed tar file.
794
- szr , err := gzip .NewReader (signed )
792
+ func (b * BuildReleaseTasks ) mergeSignedToTGZ (ctx * wf.TaskContext , unsigned , signed artifact ) (artifact , error ) {
793
+ return b .runBuildStep (ctx , unsigned .Target , nil , signed , "tar.gz" , func (_ * task.BuildletStep , signed io.Reader , w io.Writer ) error {
794
+ signedBinaries , err := loadBinaries (ctx , signed )
795
+
796
+ // Copy files from the tgz, overwriting with binaries from the signed tar.
797
+ scratchFS , err := gcsfs .FromURL (ctx , b .GCSClient , b .ScratchURL )
798
+ if err != nil {
799
+ return err
800
+ }
801
+ ur , err := scratchFS .Open (unsigned .ScratchPath )
795
802
if err != nil {
796
803
return err
797
804
}
798
- defer szr .Close ()
799
- str := tar .NewReader (szr )
805
+ defer ur .Close ()
806
+ uzr , err := gzip .NewReader (ur )
807
+ if err != nil {
808
+ return err
809
+ }
810
+ defer uzr .Close ()
811
+
812
+ utr := tar .NewReader (uzr )
813
+
814
+ zw , err := gzip .NewWriterLevel (w , gzip .BestCompression )
815
+ if err != nil {
816
+ return err
817
+ }
818
+ tw := tar .NewWriter (zw )
800
819
801
- binaries := map [string ][]byte {}
802
820
for {
803
- th , err := str .Next ()
821
+ th , err := utr .Next ()
804
822
if err == io .EOF {
805
823
break
806
824
} else if err != nil {
807
825
return err
808
826
}
809
- if ! strings .HasPrefix (th .Name , "go/bin/" ) && ! strings .HasPrefix (th .Name , "go/pkg/tool/" ) {
810
- continue
827
+
828
+ hdr := * th
829
+ src := io .NopCloser (utr )
830
+ if signed , ok := signedBinaries [th .Name ]; ok {
831
+ src = io .NopCloser (bytes .NewReader (signed ))
832
+ hdr .Size = int64 (len (signed ))
811
833
}
812
- if th .Typeflag != tar .TypeReg || th .Mode & 0100 == 0 {
813
- continue
834
+
835
+ if err := tw .WriteHeader (& hdr ); err != nil {
836
+ return err
814
837
}
815
- contents , err := io .ReadAll (str )
816
- if err != nil {
838
+ if _ , err := io .Copy (tw , src ); err != nil {
817
839
return err
818
840
}
819
- binaries [th .Name ] = contents
820
841
}
821
842
843
+ if err := tw .Close (); err != nil {
844
+ return err
845
+ }
846
+ return zw .Close ()
847
+ })
848
+ }
849
+
850
+ func (b * BuildReleaseTasks ) mergeSignedToModule (ctx * wf.TaskContext , version string , timestamp time.Time , mod moduleArtifact , signed artifact ) (moduleArtifact , error ) {
851
+ a , err := b .runBuildStep (ctx , nil , nil , signed , "signedmod.zip" , func (_ * task.BuildletStep , signed io.Reader , w io.Writer ) error {
852
+ signedBinaries , err := loadBinaries (ctx , signed )
853
+
822
854
// Copy files from the module zip, overwriting with binaries from the signed tar.
823
855
scratchFS , err := gcsfs .FromURL (ctx , b .GCSClient , b .ScratchURL )
824
856
if err != nil {
@@ -849,7 +881,7 @@ func (b *BuildReleaseTasks) mergeSignedToModule(ctx *wf.TaskContext, version str
849
881
if ! ok {
850
882
continue
851
883
}
852
- if contents , ok := binaries ["go/" + suffix ]; ok {
884
+ if contents , ok := signedBinaries ["go/" + suffix ]; ok {
853
885
in = io .NopCloser (bytes .NewReader (contents ))
854
886
} else {
855
887
in , err = f .Open ()
@@ -876,6 +908,39 @@ func (b *BuildReleaseTasks) mergeSignedToModule(ctx *wf.TaskContext, version str
876
908
return mod , nil
877
909
}
878
910
911
+ // loadBinaries reads binaries that we expect to have been signed by the
912
+ // macOS signing process from tgz.
913
+ func loadBinaries (ctx * wf.TaskContext , tgz io.Reader ) (map [string ][]byte , error ) {
914
+ zr , err := gzip .NewReader (tgz )
915
+ if err != nil {
916
+ return nil , err
917
+ }
918
+ defer zr .Close ()
919
+ tr := tar .NewReader (zr )
920
+
921
+ binaries := map [string ][]byte {}
922
+ for {
923
+ th , err := tr .Next ()
924
+ if err == io .EOF {
925
+ break
926
+ } else if err != nil {
927
+ return nil , err
928
+ }
929
+ if ! strings .HasPrefix (th .Name , "go/bin/" ) && ! strings .HasPrefix (th .Name , "go/pkg/tool/" ) {
930
+ continue
931
+ }
932
+ if th .Typeflag != tar .TypeReg || th .Mode & 0100 == 0 {
933
+ continue
934
+ }
935
+ contents , err := io .ReadAll (tr )
936
+ if err != nil {
937
+ return nil , err
938
+ }
939
+ binaries [th .Name ] = contents
940
+ }
941
+ return binaries , nil
942
+ }
943
+
879
944
func (b * BuildReleaseTasks ) buildBinary (ctx * wf.TaskContext , target * releasetargets.Target , source artifact ) (artifact , error ) {
880
945
bc := dashboard .Builders [target .Builder ]
881
946
return b .runBuildStep (ctx , target , bc , source , "tar.gz" , func (bs * task.BuildletStep , r io.Reader , w io.Writer ) error {
0 commit comments