From 3103d7d2b25a15ff51d62927187815f2de716ee6 Mon Sep 17 00:00:00 2001 From: Herman Schaaf Date: Mon, 25 Sep 2023 09:47:51 +0100 Subject: [PATCH 1/2] Set GOOS and GOARCH --- serve/package.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serve/package.go b/serve/package.go index e5b719eade..0f41a6c5ea 100644 --- a/serve/package.go +++ b/serve/package.go @@ -113,6 +113,8 @@ func (s *PluginServe) build(pluginDirectory, goos, goarch, distPath, pluginVersi cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Env = os.Environ() + cmd.Env = append(cmd.Env, fmt.Sprintf("GOOS=%s", goos)) + cmd.Env = append(cmd.Env, fmt.Sprintf("GOARCH=%s", goarch)) if err := cmd.Run(); err != nil { return nil, fmt.Errorf("failed to build plugin with `go %v`: %w", args, err) } From 9477bcfce7f38821750720644519fbca5f8b6b76 Mon Sep 17 00:00:00 2001 From: Herman Schaaf Date: Mon, 25 Sep 2023 10:08:50 +0100 Subject: [PATCH 2/2] Test --- serve/package.go | 1 + serve/package_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/serve/package.go b/serve/package.go index 0f41a6c5ea..fca95125f2 100644 --- a/serve/package.go +++ b/serve/package.go @@ -115,6 +115,7 @@ func (s *PluginServe) build(pluginDirectory, goos, goarch, distPath, pluginVersi cmd.Env = os.Environ() cmd.Env = append(cmd.Env, fmt.Sprintf("GOOS=%s", goos)) cmd.Env = append(cmd.Env, fmt.Sprintf("GOARCH=%s", goarch)) + cmd.Env = append(cmd.Env, fmt.Sprintf("CGO_ENABLED=%v", getEnvOrDefault("CGO_ENABLED", "0"))) // default to CGO_ENABLED=0 if err := cmd.Run(); err != nil { return nil, fmt.Errorf("failed to build plugin with `go %v`: %w", args, err) } diff --git a/serve/package_test.go b/serve/package_test.go index 2e3bcc9721..db3579fd0f 100644 --- a/serve/package_test.go +++ b/serve/package_test.go @@ -50,6 +50,7 @@ with multiple lines and **markdown**` } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + t.Setenv("CGO_ENABLED", "0") // disable CGO to ensure we environmental differences don't interfere with the test srv := Plugin(p) cmd := srv.newCmdPluginRoot() distDir := t.TempDir() @@ -74,6 +75,12 @@ with multiple lines and **markdown**` if diff := cmp.Diff(expect, fileNames(files)); diff != "" { t.Fatalf("unexpected files in dist directory (-want +got):\n%s", diff) } + // expect SHA-256 for the zip files to differ + sha1 := sha256sum(filepath.Join(distDir, "plugin-testPlugin-v1.2.3-linux-amd64.zip")) + sha2 := sha256sum(filepath.Join(distDir, "plugin-testPlugin-v1.2.3-windows-amd64.zip")) + if sha1 == sha2 { + t.Fatalf("expected SHA-256 for linux and windows zip files to differ, but they are the same: %s", sha1) + } expectPackage := PackageJSON{ SchemaVersion: 1, @@ -135,6 +142,7 @@ with multiple lines and **markdown**` } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { + t.Setenv("CGO_ENABLED", "0") // disable CGO to ensure we environmental differences don't interfere with the test srv := Plugin(p) cmd := srv.newCmdPluginRoot() distDir := t.TempDir() @@ -158,6 +166,12 @@ with multiple lines and **markdown**` if diff := cmp.Diff(expect, fileNames(files)); diff != "" { t.Fatalf("unexpected files in dist directory (-want +got):\n%s", diff) } + // expect SHA-256 for the zip files to differ + sha1 := sha256sum(filepath.Join(distDir, "plugin-testPlugin-v1.2.3-windows-amd64.zip")) + sha2 := sha256sum(filepath.Join(distDir, "plugin-testPlugin-v1.2.3-darwin-amd64.zip")) + if sha1 == sha2 { + t.Fatalf("expected SHA-256 for windows and darwin zip files to differ, but they are the same: %s", sha1) + } expectPackage := PackageJSON{ SchemaVersion: 1,