Skip to content

Commit

Permalink
Fix the language plugin to return a version (#390)
Browse files Browse the repository at this point in the history
This change fixes `pulumi about` to show the real version instead of
`unknown` for the dotnet language plugin.

The fix updates
[`GetPluginInfo`](https://github.com/pulumi/pulumi-dotnet/blob/e105d3278fea40be1f3008e36642756b0085e981/pulumi-language-dotnet/main.go#L805-L809)
to return the `Version` from the right `version` Go package—the
one that's actually being set during build via `ldflags`
(`"github.com/pulumi/pulumi-dotnet/pulumi-language-dotnet/version"`
instead of `"github.com/pulumi/pulumi/sdk/v3/go/common/version"`, which
looks to be a hold over from when this code lived in the pulumi/pulumi
repo).

Fixes #389
  • Loading branch information
justinvp authored Dec 6, 2024
1 parent 336fc35 commit 06e4e8d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/bug-fixes-390.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
component: runtime
kind: bug-fixes
body: Fix the language plugin to return a version
time: 2024-11-15T00:09:55.349041-08:00
custom:
PR: "390"
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
GO := go

# Try to get the dev version using changie, otherwise fall back
FALLBACK_DEV_VERSION := 3.0.0-dev.0
DEV_VERSION := $(shell if command -v changie > /dev/null; then changie next patch -p dev.0; else echo "$(FALLBACK_DEV_VERSION)"; fi)

install::
cd pulumi-language-dotnet && ${GO} install ./...
cd pulumi-language-dotnet && ${GO} install \
-ldflags "-X github.com/pulumi/pulumi-dotnet/pulumi-language-dotnet/version.Version=$(DEV_VERSION)" ./...

build::
cd pulumi-language-dotnet && ${GO} build .
cd pulumi-language-dotnet && ${GO} build \
-ldflags "-X github.com/pulumi/pulumi-dotnet/pulumi-language-dotnet/version.Version=$(DEV_VERSION)" .

test_integration:: build
cd integration_tests && gotestsum -- --parallel 1 --timeout 30m ./...
Expand Down
20 changes: 18 additions & 2 deletions build/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ let integrationTests = Path.Combine(repositoryRoot, "integration_tests")
let pulumiLanguageDotnet = Path.Combine(repositoryRoot, "pulumi-language-dotnet")


let getDevVersion() =
try
Cli.Wrap("changie")
.WithArguments("next patch -p dev.0")
.WithValidation(CommandResultValidation.ZeroExitCode)
.ExecuteBufferedAsync()
.GetAwaiter()
.GetResult()
.StandardOutput
.Trim()
with
| _ ->
"3.0.0-dev.0"

/// Runs `dotnet clean` command against the solution file,
/// then proceeds to delete the `bin` and `obj` directory of each project in the solution
let cleanSdk() =
Expand Down Expand Up @@ -131,8 +145,10 @@ let cleanLanguagePlugin() =

let buildLanguagePlugin() =
cleanLanguagePlugin()
printfn "Building pulumi-language-dotnet Plugin"
if Shell.Exec("go", "build", pulumiLanguageDotnet) <> 0
let devVersion = getDevVersion()
printfn $"Building pulumi-language-dotnet Plugin {devVersion}"
let ldflags = $"-ldflags \"-X github.com/pulumi/pulumi-dotnet/pulumi-language-dotnet/version.Version={devVersion}\""
if Shell.Exec("go", $"build {ldflags}", pulumiLanguageDotnet) <> 0
then failwith "Building pulumi-language-dotnet failed"
let output = Path.Combine(pulumiLanguageDotnet, "pulumi-language-dotnet")
printfn $"Built binary {output}"
Expand Down
21 changes: 13 additions & 8 deletions integration_tests/integration_dotnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,19 @@ func TestGetResourceDotnet(t *testing.T) {
func TestAboutDotnet(t *testing.T) {
t.Parallel()

languagePluginPath, err := filepath.Abs("../pulumi-language-dotnet")
require.NoError(t, err)

e := ptesting.NewEnvironment(t)
defer func() {
if !t.Failed() {
e.DeleteEnvironmentFallible()
}
}()
defer e.DeleteIfNotFailed()
e.ImportDirectory("about")

e.Env = append(e.Env, getProviderPath(languagePluginPath))
e.RunCommand("pulumi", "login", "--cloud-url", e.LocalURL())
_, stderr := e.RunCommand("pulumi", "about")
stdout, stderr := e.RunCommand("pulumi", "about")
// There should be no "unknown" plugin versions.
assert.NotContains(t, stdout, "unknown")
assert.NotContains(t, stderr, "unknown")
// This one doesn't have a current stack. Assert that we caught it.
assert.Contains(t, stderr, "No current stack")
}
Expand Down Expand Up @@ -624,6 +627,9 @@ func readUpdateEventLog(logfile string) ([]apitype.EngineEvent, error) {
func TestDebuggerAttachDotnet(t *testing.T) {
t.Parallel()

languagePluginPath, err := filepath.Abs("../pulumi-language-dotnet")
require.NoError(t, err)

e := ptesting.NewEnvironment(t)
defer e.DeleteIfNotFailed()
e.ImportDirectory("printf")
Expand All @@ -636,7 +642,7 @@ func TestDebuggerAttachDotnet(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
e.Env = append(e.Env, "PULUMI_DEBUG_COMMANDS=true")
e.Env = append(e.Env, "PULUMI_DEBUG_COMMANDS=true", getProviderPath(languagePluginPath))
e.RunCommand("pulumi", "stack", "init", "debugger-test")
e.RunCommand("pulumi", "stack", "select", "debugger-test")
e.RunCommand("pulumi", "preview", "--attach-debugger",
Expand Down Expand Up @@ -690,5 +696,4 @@ func TestParameterized(t *testing.T) {
return nil
},
})

}
2 changes: 1 addition & 1 deletion pulumi-language-dotnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import (
"github.com/blang/semver"
pbempty "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"github.com/pulumi/pulumi-dotnet/pulumi-language-dotnet/version"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/executable"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/logging"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/rpcutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/version"
pulumirpc "github.com/pulumi/pulumi/sdk/v3/proto/go"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand Down

0 comments on commit 06e4e8d

Please sign in to comment.