Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #244 from gobuffalo/task-runtime-buildinfo
Browse files Browse the repository at this point in the history
improvement: using go built in build-info.
  • Loading branch information
paganotoni authored Nov 20, 2022
2 parents a4e312f + 5e6d6d7 commit 83b1484
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/standard-go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ on:
jobs:
call-standard-test:
name: Test
uses: gobuffalo/.github/.github/workflows/go-test.yml@v1
uses: gobuffalo/.github/.github/workflows/go-test.yml@v1.6
secrets: inherit
Binary file removed buffalo
Binary file not shown.
50 changes: 7 additions & 43 deletions internal/cmd/build/build.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package build

import (
"bytes"
"context"
"log"
"os"
"os/exec"
"os/signal"
"strings"
"runtime/debug"
"time"

"github.com/gobuffalo/cli/internal/genny/build"
Expand Down Expand Up @@ -95,48 +93,14 @@ func buildVersion(version string) string {
return version
}

ctx := context.Background()
run := genny.WetRunner(ctx)
if buildOptions.DryRun {
run = genny.DryRunner(ctx)
}

_, err := exec.LookPath(vcs)
if err != nil {
run.Logger.Warnf("could not find %s; defaulting to version %s", vcs, version)
return vcs
}
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key != "vcs.revision" {
continue
}

var cmd *exec.Cmd
switch vcs {
case "git":
// If .git folder does not exist return default version
if stat, err := os.Stat(".git"); err != nil || !stat.IsDir() {
run.Logger.Warnf("could not find .git folder; defaulting to version %s", version)
return version
return setting.Value
}

cmd = exec.Command("git", "rev-parse", "--short", "HEAD")
case "bzr":
cmd = exec.Command("bzr", "revno")
default:
run.Logger.Warnf("could not find %s; defaulting to version %s", vcs, version)
return vcs
}

out := &bytes.Buffer{}
cmd.Stdout = out
run.WithRun(func(r *genny.Runner) error {
return r.Exec(cmd)
})

if err := run.Run(); err != nil {
run.Logger.Error(err)
return version
}

if out.String() != "" {
return strings.TrimSpace(out.String())
}

return version
Expand Down

0 comments on commit 83b1484

Please sign in to comment.