Skip to content

Commit

Permalink
added multiple binary publish support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nik Ogura committed Jun 22, 2018
1 parent 942d6d1 commit 7527121
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.0",
"version": "2.0.2",
"package": "github.com/nikogura/gomason",
"description": "A tool for testing, building, signing, and publishing your project from a clean workspace.",
"repository": "http://localhost:8081/artifactory/generic-local",
Expand Down
4 changes: 2 additions & 2 deletions pkg/gomason/building.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func BuildExtras(meta Metadata, workdir string, verbose bool) (err error) {
executable := extra.Executable

if verbose {
fmt.Printf("Reading template from %s", templateName)
fmt.Printf("Writing to %s", outputFileName)
fmt.Printf("Reading template from %s\n", templateName)
fmt.Printf("Writing to %s\n", outputFileName)
}

var mode os.FileMode
Expand Down
76 changes: 46 additions & 30 deletions pkg/gomason/gomason.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"fmt"
"github.com/pkg/errors"
"gopkg.in/ini.v1"
"io/ioutil"
"log"
"os"
"os/user"
"path/filepath"
"regexp"
"strings"
)

Expand Down Expand Up @@ -86,9 +88,6 @@ type UserSignInfo struct {
//
// 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).
func PublishBuildTargets(meta Metadata, gopath string, cwd string, sign bool, publish bool, collect bool, verbose bool) (err error) {
parts := strings.Split(meta.Package, "/")
binaryPrefix := parts[len(parts)-1]

// loop through the built things for each type of build target
for _, arch := range meta.BuildInfo.Targets {
if verbose {
Expand All @@ -100,40 +99,57 @@ func PublishBuildTargets(meta Metadata, gopath string, cwd string, sign bool, pu
archname := archparts[1] // amd64 generally

workdir := fmt.Sprintf("%s/src/%s", gopath, meta.Package)
filename := fmt.Sprintf("%s/%s_%s_%s", workdir, binaryPrefix, osname, archname)

if _, err := os.Stat(filename); os.IsNotExist(err) {
err = fmt.Errorf("failed to build binary: %s\n", filename)
files, err := ioutil.ReadDir(workdir)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("failed to read dir %s", workdir))
return err
}

// sign 'em if we're signing
if sign {
err = SignBinary(meta, filename, verbose)
if err != nil {
err = errors.Wrap(err, "failed to sign binary")
return err
}
}

// publish and return if we're publishing
if publish {
err = PublishFile(meta, filename, verbose)
if err != nil {
err = errors.Wrap(err, "failed to publish binary")
return err
targetSuffix := fmt.Sprintf(".+_%s_%s", osname, archname)
targetRegex := regexp.MustCompile(targetSuffix)

for _, file := range files {
matched := targetRegex.MatchString(file.Name())

if matched {
filename := fmt.Sprintf("%s/%s", workdir, file.Name())

if _, err := os.Stat(filename); os.IsNotExist(err) {
err = fmt.Errorf("failed to build binary: %s\n", filename)
return err
}

// sign 'em if we're signing
if sign {
err = SignBinary(meta, filename, verbose)
if err != nil {
err = errors.Wrap(err, "failed to sign binary")
return err
}
}

// publish and return if we're publishing
if publish {
err = PublishFile(meta, filename, verbose)
if err != nil {
err = errors.Wrap(err, "failed to publish binary")
return err
}

}

if collect {
// if we're not publishing, collect up the stuff we built, and dump 'em into the cwd where we called gomason
err := CollectFileAndSignature(cwd, filename, verbose)
if err != nil {
err = errors.Wrap(err, "failed to collect binaries")
return err
}
}
}

}

if collect {
// if we're not publishing, collect up the stuff we built, and dump 'em into the cwd where we called gomason
err := CollectFileAndSignature(cwd, filename, verbose)
if err != nil {
err = errors.Wrap(err, "failed to collect binaries")
return err
}
}
}

return err
Expand Down

0 comments on commit 7527121

Please sign in to comment.