Bound subprocess output teardown
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
@@ -9,7 +10,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"go.maximumdirect.net/releasekit/internal/candidate"
|
||||
"go.maximumdirect.net/releasekit/internal/git"
|
||||
"go.maximumdirect.net/releasekit/internal/gotool"
|
||||
"go.maximumdirect.net/releasekit/internal/process"
|
||||
"go.maximumdirect.net/releasekit/internal/releaseidentity"
|
||||
"go.maximumdirect.net/releasekit/internal/tempdir"
|
||||
"go.maximumdirect.net/releasekit/internal/versioncontract"
|
||||
@@ -227,17 +228,14 @@ func hashArtifact(artifact *Artifact) error {
|
||||
}
|
||||
|
||||
func checkVersion(ctx context.Context, binaryPath, binaryName, version string) error {
|
||||
command := exec.CommandContext(ctx, binaryPath, "version")
|
||||
output, err := command.CombinedOutput()
|
||||
var output bytes.Buffer
|
||||
err := process.Run(ctx, process.Invocation{Args: []string{binaryPath, "version"}, Stdout: &output, Stderr: &output})
|
||||
if err != nil {
|
||||
if ctx.Err() != nil {
|
||||
return fmt.Errorf("run native version check: %w", ctx.Err())
|
||||
}
|
||||
return fmt.Errorf("run native version check: %w: %s", err, strings.TrimSpace(string(output)))
|
||||
return fmt.Errorf("run native version check: %w: %s", err, strings.TrimSpace(output.String()))
|
||||
}
|
||||
want := binaryName + " " + version + "\n"
|
||||
if string(output) != want {
|
||||
return fmt.Errorf("native version output = %q, want %q", output, want)
|
||||
if output.String() != want {
|
||||
return fmt.Errorf("native version output = %q, want %q", output.String(), want)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user