Skip to content

Commit

Permalink
Fix the version stamp set during build (#124)
Browse files Browse the repository at this point in the history
The ldflags passed to the build expect to be the root package for the
repository, and should contain the pkg directory with the version
variables so that the build can set them.

The package passed was to the plugin entry point (./cmd/kubernetes)
which caused the version stamp to be empty.

Signed-off-by: Carolyn Van Slyck <[email protected]>
  • Loading branch information
carolynvs authored May 27, 2022
2 parents b0ddade + 25fcb21 commit 82b1adb
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
package main

import (
"encoding/json"
"fmt"

"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -61,13 +62,15 @@ const (
// Docker registry for porter client container
porterRegistry = "ghcr.io/getporter"
porterConfigFile = "./tests/integration/operator/testdata/operator_porter_config.yaml"

// The root package name of the plugin repository
pluginPkg = "get.porter.sh/plugin/kubernetes"
)

// Dirs to watch recursively for build target
var (
srcDirs = []string{"cmd/", "pkg/", "go.mod", "magefile.go"}
binDir = "bin/plugins/kubernetes/"
pluginPkg = fmt.Sprintf("./cmd/%s", pluginName)
supportedClientGOOS = []string{"linux", "darwin", "windows"}
// number of nodes for ginkgo parallel test execution (1=sequential)
ginkgoNodes = "1"
Expand Down Expand Up @@ -165,6 +168,25 @@ func XBuildAll() {
}

releases.PreparePluginForPublish(pluginName)
verifyVersionStamp()
}

// verifyVersionStamp checks that the version was set on the cross-compiled binaries
func verifyVersionStamp() {
// When this test fails, pluginPkg is set incorrectly or not passed to the releases functions properly
pluginBinaryPath := filepath.Join(binDir, fmt.Sprintf("dev/kubernetes-%s-amd64", runtime.GOOS))
versionOutput, _ := must.OutputV(pluginBinaryPath, "version", "-o=json")

var raw map[string]interface{}
if err := json.Unmarshal([]byte(versionOutput), &raw); err != nil {
mgx.Must(fmt.Errorf("error parsing the version command output as json: %w", err))
}

meta := releases.LoadMetadata()
gotVersion := raw["version"].(string)
if gotVersion != meta.Version {
mgx.Must(fmt.Errorf("the version was not set correctly on the kubernetes plugin binary %s: expected %q got %q", pluginBinaryPath, meta.Version, gotVersion))
}
}

// Run local integration tests against the test cluster.
Expand Down

0 comments on commit 82b1adb

Please sign in to comment.