@@ -75,101 +75,149 @@ func realMain() int {
7575 return 1
7676 }
7777
78- // If we have no items to sign then its probably an error
79- if len (cfg .Source ) == 0 {
80- color .New (color .Bold , color .FgRed ).Fprintf (os .Stdout , "❗️ No source files specified\n " )
81- color .New (color .FgRed ).Fprintf (os .Stdout ,
82- "Your configuration had an empty 'source' value. This must be populated with\n " +
83- "at least one file to sign, package, and notarize.\n " )
84- return 1
85- }
86-
8778 // The files to notarize should be added to this. We'll submit one notarization
8879 // request per file here.
8980 var items []* item
9081
91- // Perform codesigning
92- color . New ( color . Bold ). Fprintf ( os . Stdout , "==> %s Signing files... \n " , iconSign )
93- err = sign . Sign ( context . Background (), & sign. Options {
94- Files : cfg .Source ,
95- Identity : cfg . Sign . ApplicationIdentity ,
96- Logger : logger . Named ( "sign" ) ,
97- })
98- if err != nil {
99- fmt . Fprintf ( os . Stdout , color . RedString ( "❗️ Error signing files: \n \n %s \n " , err ) )
100- return 1
82+ // Notarize is an alternative to "Source", where you specify
83+ // a single .pkg or .zip that is ready for notarization and stapling
84+ if len ( cfg . Notarize ) > 0 {
85+ for _ , c := range cfg .Notarize {
86+ items = append ( items , & item {
87+ Path : c . Path ,
88+ BundleId : c . BundleId ,
89+ Staple : c . Staple ,
90+ } )
91+ }
10192 }
102- color .New (color .Bold , color .FgGreen ).Fprintf (os .Stdout , " Code signing successful\n " )
103-
104- // Create a zip
105- if cfg .Zip != nil {
106- color .New (color .Bold ).Fprintf (os .Stdout , "==> %s Creating Zip archive...\n " , iconPackage )
107- err = zip .Zip (context .Background (), & zip.Options {
108- Files : cfg .Source ,
109- OutputPath : cfg .Zip .OutputPath ,
110- })
111- if err != nil {
112- fmt .Fprintf (os .Stdout , color .RedString ("❗️ Error creating zip archive:\n \n %s\n " , err ))
93+
94+ if len (cfg .Source ) > 0 {
95+ if cfg .Sign == nil {
96+ color .New (color .Bold , color .FgRed ).Fprintf (os .Stdout ,
97+ "❗️ `sign` configuration required with `source` set\n " )
98+ color .New (color .FgRed ).Fprintf (os .Stdout ,
99+ "When you set the `source` configuration, you must also specify the\n " +
100+ "`sign` configuration to sign the input files.\n " )
101+ return 1
102+ }
103+ } else {
104+ if cfg .Zip != nil {
105+ color .New (color .Bold , color .FgRed ).Fprintf (os .Stdout ,
106+ "❗️ `zip` can only be set while `source` is also set\n " )
107+ color .New (color .FgRed ).Fprintf (os .Stdout ,
108+ "Zip packaging is only supported when `source` is specified. This is\n " +
109+ "because the `zip` option packages the source files. If there are no\n " +
110+ "source files specified, then there is nothing to package.\n " )
113111 return 1
114112 }
115- color .New (color .Bold , color .FgGreen ).Fprintf (os .Stdout , " Zip archive created with signed files\n " )
116113
117- // Queue to notarize
118- items = append (items , & item {Path : cfg .Zip .OutputPath })
114+ if cfg .Dmg != nil {
115+ color .New (color .Bold , color .FgRed ).Fprintf (os .Stdout ,
116+ "❗️ `dmg` can only be set while `source` is also set\n " )
117+ color .New (color .FgRed ).Fprintf (os .Stdout ,
118+ "Dmg packaging is only supported when `source` is specified. This is\n " +
119+ "because the `dmg` option packages the source files. If there are no\n " +
120+ "source files specified, then there is nothing to package.\n " )
121+ return 1
122+ }
119123 }
120124
121- // Create a dmg
122- if cfg .Dmg != nil {
123- // First create the dmg itself. This passes in the signed files.
124- color .New (color .Bold ).Fprintf (os .Stdout , "==> %s Creating dmg...\n " , iconPackage )
125- color .New ().Fprintf (os .Stdout , " This will open Finder windows momentarily.\n " )
126- err = dmg .Dmg (context .Background (), & dmg.Options {
127- Files : cfg .Source ,
128- OutputPath : cfg .Dmg .OutputPath ,
129- VolumeName : cfg .Dmg .VolumeName ,
130- Logger : logger .Named ("dmg" ),
131- })
132- if err != nil {
133- fmt .Fprintf (os .Stdout , color .RedString ("❗️ Error creating dmg:\n \n %s\n " , err ))
134- return 1
125+ // If we have no items to sign then its probably an error
126+ if len (cfg .Source ) == 0 && len (cfg .Notarize ) == 0 {
127+ color .New (color .Bold , color .FgRed ).Fprintf (os .Stdout , "❗️ No source files specified\n " )
128+ color .New (color .FgRed ).Fprintf (os .Stdout ,
129+ "Your configuration had an empty 'source' and empty 'notarize' values. This must be populated with\n " +
130+ "at least one file to sign, package, and notarize.\n " )
131+ return 1
132+ }
133+
134+ // If we're in source mode, then sign & package as configured
135+ if len (cfg .Source ) > 0 {
136+ if cfg .Sign != nil {
137+ // Perform codesigning
138+ color .New (color .Bold ).Fprintf (os .Stdout , "==> %s Signing files...\n " , iconSign )
139+ err = sign .Sign (context .Background (), & sign.Options {
140+ Files : cfg .Source ,
141+ Identity : cfg .Sign .ApplicationIdentity ,
142+ Logger : logger .Named ("sign" ),
143+ })
144+ if err != nil {
145+ fmt .Fprintf (os .Stdout , color .RedString ("❗️ Error signing files:\n \n %s\n " , err ))
146+ return 1
147+ }
148+ color .New (color .Bold , color .FgGreen ).Fprintf (os .Stdout , " Code signing successful\n " )
135149 }
136- color .New ().Fprintf (os .Stdout , " Dmg file created: %s\n " , cfg .Dmg .OutputPath )
137-
138- // Next we need to sign the actual DMG as well
139- color .New ().Fprintf (os .Stdout , " Signing dmg...\n " )
140- err = sign .Sign (context .Background (), & sign.Options {
141- Files : []string {cfg .Dmg .OutputPath },
142- Identity : cfg .Sign .ApplicationIdentity ,
143- Logger : logger .Named ("dmg" ),
144- })
145- if err != nil {
146- fmt .Fprintf (os .Stdout , color .RedString ("❗️ Error signing dmg:\n \n %s\n " , err ))
147- return 1
150+
151+ // Create a zip
152+ if cfg .Zip != nil {
153+ color .New (color .Bold ).Fprintf (os .Stdout , "==> %s Creating Zip archive...\n " , iconPackage )
154+ err = zip .Zip (context .Background (), & zip.Options {
155+ Files : cfg .Source ,
156+ OutputPath : cfg .Zip .OutputPath ,
157+ })
158+ if err != nil {
159+ fmt .Fprintf (os .Stdout , color .RedString ("❗️ Error creating zip archive:\n \n %s\n " , err ))
160+ return 1
161+ }
162+ color .New (color .Bold , color .FgGreen ).Fprintf (os .Stdout , " Zip archive created with signed files\n " )
163+
164+ // Queue to notarize
165+ items = append (items , & item {Path : cfg .Zip .OutputPath })
148166 }
149- color .New (color .Bold , color .FgGreen ).Fprintf (os .Stdout , " Dmg created and signed\n " )
150167
151- // Queue to notarize
152- items = append (items , & item {Path : cfg .Dmg .OutputPath , Staple : true })
168+ // Create a dmg
169+ if cfg .Dmg != nil && cfg .Sign != nil {
170+ // First create the dmg itself. This passes in the signed files.
171+ color .New (color .Bold ).Fprintf (os .Stdout , "==> %s Creating dmg...\n " , iconPackage )
172+ color .New ().Fprintf (os .Stdout , " This will open Finder windows momentarily.\n " )
173+ err = dmg .Dmg (context .Background (), & dmg.Options {
174+ Files : cfg .Source ,
175+ OutputPath : cfg .Dmg .OutputPath ,
176+ VolumeName : cfg .Dmg .VolumeName ,
177+ Logger : logger .Named ("dmg" ),
178+ })
179+ if err != nil {
180+ fmt .Fprintf (os .Stdout , color .RedString ("❗️ Error creating dmg:\n \n %s\n " , err ))
181+ return 1
182+ }
183+ color .New ().Fprintf (os .Stdout , " Dmg file created: %s\n " , cfg .Dmg .OutputPath )
184+
185+ // Next we need to sign the actual DMG as well
186+ color .New ().Fprintf (os .Stdout , " Signing dmg...\n " )
187+ err = sign .Sign (context .Background (), & sign.Options {
188+ Files : []string {cfg .Dmg .OutputPath },
189+ Identity : cfg .Sign .ApplicationIdentity ,
190+ Logger : logger .Named ("dmg" ),
191+ })
192+ if err != nil {
193+ fmt .Fprintf (os .Stdout , color .RedString ("❗️ Error signing dmg:\n \n %s\n " , err ))
194+ return 1
195+ }
196+ color .New (color .Bold , color .FgGreen ).Fprintf (os .Stdout , " Dmg created and signed\n " )
197+
198+ // Queue to notarize
199+ items = append (items , & item {Path : cfg .Dmg .OutputPath , Staple : true })
200+ }
153201 }
154202
155203 // If we have no items to notarize then its probably an error in the configuration.
156204 if len (items ) == 0 {
157205 color .New (color .Bold , color .FgYellow ).Fprintf (os .Stdout , "\n ⚠️ No items to notarize\n " )
158206 color .New (color .FgYellow ).Fprintf (os .Stdout ,
159- "You must specify a 'zip' or 'dmg ' section in your configuration to enable \n " +
160- "packaging and notarization. Without these sections, gon will only sign your \n " +
161- "input files.\n " )
207+ "You must specify a 'notarize' section or a 'source ' section plus a 'zip' or 'dmg' section " +
208+ "in your configuration to enable packaging and notarization. Without these sections, gon\n " +
209+ "will only sign your input files in 'source' .\n " )
162210 return 0
163211 }
164212
165213 // Notarize
166214 color .New (color .Bold ).Fprintf (os .Stdout , "==> %s Notarizing...\n " , iconNotarize )
167215 if len (items ) > 1 {
168- for _ , f := range items {
169- color .New ().Fprintf (os .Stdout , " Path: %s\n " , f .Path )
170- }
171216 color .New ().Fprintf (os .Stdout , " Files will be notarized concurrently to optimize queue wait\n " )
172217 }
218+ for _ , f := range items {
219+ color .New ().Fprintf (os .Stdout , " Path: %s\n " , f .Path )
220+ }
173221
174222 // Build our prefixes
175223 prefixes := statusPrefixList (items )
0 commit comments