8
8
"path/filepath"
9
9
"regexp"
10
10
"strings"
11
+ "time"
11
12
12
13
"github.com/pkg/errors"
13
14
"gopkg.in/ini.v1"
@@ -18,7 +19,7 @@ func init() {
18
19
}
19
20
20
21
// VERSION is the current gomason version
21
- const VERSION = "2.12.0 "
22
+ const VERSION = "2.12.1 "
22
23
23
24
// METADATA_FILENAME The default gomason metadata file name
24
25
const METADATA_FILENAME = "metadata.json"
@@ -181,7 +182,7 @@ func (g *Gomason) HandleArtifacts(meta Metadata, gopath string, cwd string, sign
181
182
return err
182
183
}
183
184
184
- targetSuffix := fmt .Sprintf (".+_%s_%s" , osname , archname )
185
+ targetSuffix := fmt .Sprintf (".+_%s_%s$ " , osname , archname )
185
186
targetRegex := regexp .MustCompile (targetSuffix )
186
187
187
188
for _ , file := range files {
@@ -190,15 +191,16 @@ func (g *Gomason) HandleArtifacts(meta Metadata, gopath string, cwd string, sign
190
191
if matched {
191
192
filename := fmt .Sprintf ("%s/%s" , workdir , file .Name ())
192
193
193
- logrus .Debugf ("\t Handling %s\n " , filename )
194
+ logrus .Debugf ("Handling %s" , filename )
194
195
195
196
if _ , err := os .Stat (filename ); os .IsNotExist (err ) {
196
- err = errors .Wrapf (err , "failed to build binary: %s\n " , filename )
197
+ err = errors .Wrapf (err , "failed building binary: %s\n " , filename )
197
198
return err
198
199
}
199
200
200
201
// sign 'em if we're signing
201
202
if sign {
203
+ logrus .Debugf ("Signing %s" , filename )
202
204
err = g .SignBinary (meta , filename )
203
205
if err != nil {
204
206
err = errors .Wrapf (err , "failed to sign binary %s" , filename )
@@ -208,15 +210,17 @@ func (g *Gomason) HandleArtifacts(meta Metadata, gopath string, cwd string, sign
208
210
209
211
// publish and return if we're publishing
210
212
if publish {
213
+ logrus .Debugf ("Publishing %s" , filename )
211
214
err = g .PublishFile (meta , filename )
212
215
if err != nil {
213
216
err = errors .Wrap (err , "failed to publish binary" )
214
217
return err
215
218
}
216
219
}
217
220
221
+ // Collect up the stuff we built, and dump 'em into the cwd where we called gomason
218
222
if collect {
219
- // if we're not publishing, collect up the stuff we built, and dump 'em into the cwd where we called gomason
223
+ logrus . Debugf ( "Collecting %s" , filename )
220
224
err := CollectFileAndSignature (cwd , filename )
221
225
if err != nil {
222
226
err = errors .Wrap (err , "failed to collect binaries" )
@@ -234,7 +238,7 @@ func (g *Gomason) HandleArtifacts(meta Metadata, gopath string, cwd string, sign
234
238
// HandleExtras loops over the expected files built by Build() and optionally signs them and publishes them along with their signatures (if signing).
235
239
//
236
240
// If not publishing, the binaries (and their optional signatures) are collected and dumped into the directory where gomason was called. (Typically the root of a go project).
237
- func (g * Gomason ) HandleExtras (meta Metadata , gopath string , cwd string , sign bool , publish bool ) (err error ) {
241
+ func (g * Gomason ) HandleExtras (meta Metadata , gopath string , cwd string , sign bool , publish bool , collect bool ) (err error ) {
238
242
239
243
// loop through the built things for each type of build target
240
244
for _ , extra := range meta .BuildInfo .Extras {
@@ -250,6 +254,7 @@ func (g *Gomason) HandleExtras(meta Metadata, gopath string, cwd string, sign bo
250
254
251
255
// sign 'em if we're signing
252
256
if sign {
257
+ logrus .Debugf ("Signing %s" , filename )
253
258
err = g .SignBinary (meta , filename )
254
259
if err != nil {
255
260
err = errors .Wrapf (err , "failed to sign extra artifact %s" , filename )
@@ -259,14 +264,18 @@ func (g *Gomason) HandleExtras(meta Metadata, gopath string, cwd string, sign bo
259
264
260
265
// publish and return if we're publishing
261
266
if publish {
267
+ logrus .Debugf ("Publishing %s" , filename )
262
268
err = g .PublishFile (meta , filename )
263
269
if err != nil {
264
270
err = errors .Wrapf (err , "failed to publish extra artifact %s" , filename )
265
271
return err
266
272
}
267
273
268
- } else {
269
- // if we're not publishing, collect up the stuff we built, and dump 'em into the cwd where we called gomason
274
+ }
275
+
276
+ if collect {
277
+ // Collect up the stuff we built, and dump 'em into the cwd where we called gomason
278
+ logrus .Debugf ("Collecting %s" , filename )
270
279
err := CollectFileAndSignature (cwd , filename )
271
280
if err != nil {
272
281
err = errors .Wrapf (err , "failed to collect binary %s" , filename )
@@ -278,16 +287,30 @@ func (g *Gomason) HandleExtras(meta Metadata, gopath string, cwd string, sign bo
278
287
return err
279
288
}
280
289
290
+ func DebugPrint (filename , tag string ) {
291
+ ts := time .Now ().UnixNano ()
292
+ cwd , _ := os .Getwd ()
293
+ logrus .Debugf ("%s Current working directory: %s\n " , tag , cwd )
294
+
295
+ _ , err := os .Stat (filename )
296
+ if err != nil {
297
+ logrus .Debugf ("%s File %s missing at %v" , tag , filename , ts )
298
+ } else {
299
+ logrus .Debugf ("%s File %s exists at %v" , tag , filename , ts )
300
+ }
301
+ }
302
+
281
303
// CollectFileAndSignature grabs a file and the signature if it exists and copies it from the temp workspace into the CWD where gomason was called. Does nothing at all if the file is currently in cwd.
282
304
func CollectFileAndSignature (cwd string , filename string ) (err error ) {
283
- fmt . Printf ( "[DEBUG] Collecting Binaries and Signatures (if signing) \n " )
305
+ logrus . Debugf ( " Collecting Files and Signatures" )
284
306
285
307
binaryDestinationPath := fmt .Sprintf ("%s/%s" , cwd , filepath .Base (filename ))
286
308
287
309
if binaryDestinationPath != filename {
288
310
fileInfo , err := os .Stat (filename )
289
311
if err != nil {
290
312
err = errors .Wrapf (err , "failed statting file %s" , filename )
313
+ return err
291
314
}
292
315
293
316
contents , err := os .ReadFile (filename )
@@ -312,21 +335,26 @@ func CollectFileAndSignature(cwd string, filename string) (err error) {
312
335
if _ , err := os .Stat (sigName ); ! os .IsNotExist (err ) {
313
336
signatureDestinationPath := fmt .Sprintf ("%s/%s" , cwd , sigName )
314
337
if signatureDestinationPath != sigName {
315
- contents , err := os .ReadFile (filename )
338
+ fileInfo , err := os .Stat (sigName )
339
+ if err != nil {
340
+ err = errors .Wrapf (err , "failed statting file %s" , sigName )
341
+ return err
342
+ }
343
+ contents , err := os .ReadFile (sigName )
316
344
if err != nil {
317
- err = errors .Wrapf (err , "failed reading file %q" , filename )
345
+ err = errors .Wrapf (err , "failed reading file %q" , sigName )
318
346
return err
319
347
}
320
348
321
- err = os .WriteFile (signatureDestinationPath , contents , 0644 )
349
+ err = os .WriteFile (signatureDestinationPath , contents , fileInfo . Mode () )
322
350
if err != nil {
323
351
err = errors .Wrapf (err , "failed writing file %s" , signatureDestinationPath )
324
352
return err
325
353
}
326
354
327
- err = os .Remove (filename )
355
+ err = os .Remove (sigName )
328
356
if err != nil {
329
- err = errors .Wrapf (err , "failed removing file %s" , filename )
357
+ err = errors .Wrapf (err , "failed removing file %s" , sigName )
330
358
return err
331
359
}
332
360
}
0 commit comments