Skip to content

Commit

Permalink
build(mage): 🐛 only do renaming for deb package
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Jun 28, 2024
1 parent fa647fc commit 7ecf248
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion build/magefiles/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (Build) Fast() error {
return buildProject()
}

// CI runs build steps required for building in a CI environment (i.e., GitHub).
func (b Build) CI() error {
if !isCI() {
return ErrNotCI
Expand All @@ -53,30 +54,38 @@ func (b Build) CI() error {
return nil
}

// buildProject is the shared method that all exported build targets use. It
// runs the bare minimum steps to build a binary of the agent.
//
//nolint:mnd
func buildProject() error {
// Remove any existing dist directory.
if err := os.RemoveAll(distPath); err != nil {
return fmt.Errorf("could not clean dist directory: %w", err)
}

// Recreate an empty dist directory for this build.
if err := os.Mkdir(distPath, 0o755); err != nil {
return fmt.Errorf("could not create dist directory: %w", err)
}

// Set-up the build environment.
envMap, err := generateEnv()
if err != nil {
return errors.Join(ErrBuildFailed, err)
}

// Set-up appropriate build flags.
ldflags, err := getFlags()
if err != nil {
return errors.Join(ErrBuildFailed, err)
}

// Set an appropriate output file based on the arch to build for.
outputFile := filepath.Join(distPath, "/go-hass-agent-"+envMap["PLATFORMPAIR"])

slog.Info("Running go build...", "output", outputFile, "ldflags", ldflags)

// Run the build.
if err := sh.RunWithV(envMap, "go", "build", "-ldflags="+ldflags, "-o", outputFile); err != nil {
return fmt.Errorf("failed to build project: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions build/magefiles/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func generateEnv() (map[string]string, error) {
return envMap, nil
}

// parseBuildPlatform reads the BUILDPLATFORM environment variable, which should
// always be set, and extracts the value into appropriate GOOS, GOARCH and GOARM
// (if applicable) variables.
//
//nolint:mnd
func parseBuildPlatform() (operatingsystem, architecture, version string) {
var buildPlatform string
Expand Down
2 changes: 1 addition & 1 deletion build/magefiles/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (Package) Nfpm() error {

// nfpm creates the same package name for armv6 and armv7 deb packages,
// so we need to rename them.
if envMap["GOARCH"] == "arm" {
if envMap["GOARCH"] == "arm" && pkgformat == "deb" {
debPkgs, err := filepath.Glob(distPath + "/pkg/*.deb")
if err != nil {
return fmt.Errorf("could not find arm deb package: %w", err)
Expand Down

0 comments on commit 7ecf248

Please sign in to comment.