Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rootDirectory to yaml #716

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Improvements-716.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
component: codegen
kind: Improvements
body: Add rootDirectory to codegen, runtime, and convert
time: 2025-02-18T23:42:18.755925+09:00
custom:
PR: "716"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
outputs:
rootDirectoryOutput: ${pulumi.rootDirectory}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: l1-builtin-project-root
runtime: yaml
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require (
github.com/hexops/autogold v1.3.0
github.com/iancoleman/strcase v0.2.0
github.com/pkg/errors v0.9.1
github.com/pulumi/pulumi/pkg/v3 v3.152.0
github.com/pulumi/pulumi/sdk/v3 v3.152.0
github.com/pulumi/pulumi/pkg/v3 v3.153.1
github.com/pulumi/pulumi/sdk/v3 v3.153.1
github.com/spf13/afero v1.9.5
github.com/stretchr/testify v1.10.0
github.com/zclconf/go-cty v1.13.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ github.com/pulumi/esc v0.10.0 h1:jzBKzkLVW0mePeanDRfqSQoCJ5yrkux0jIwAkUxpRKE=
github.com/pulumi/esc v0.10.0/go.mod h1:2Bfa+FWj/xl8CKqRTWbWgDX0SOD4opdQgvYSURTGK2c=
github.com/pulumi/inflector v0.1.1 h1:dvlxlWtXwOJTUUtcYDvwnl6Mpg33prhK+7mzeF+SobA=
github.com/pulumi/inflector v0.1.1/go.mod h1:HUFCjcPTz96YtTuUlwG3i3EZG4WlniBvR9bd+iJxCUY=
github.com/pulumi/pulumi/pkg/v3 v3.152.0 h1:SDhBD12bD5UoxwyLBHVBbfBC+iul1GoIgoHwtSfciI4=
github.com/pulumi/pulumi/pkg/v3 v3.152.0/go.mod h1:WzIlIXzgRvu7pD1bS/5/5Z9Zs4vdHRs5gyjE7GcaPbo=
github.com/pulumi/pulumi/sdk/v3 v3.152.0 h1:sPstmYhbf/ArkREjkPYRgFUf+iv1llskLY2/4aASdxc=
github.com/pulumi/pulumi/sdk/v3 v3.152.0/go.mod h1:+WC9aIDo8fMgd2g0jCHuZU2S/VYNLRAZ3QXt6YVgwaA=
github.com/pulumi/pulumi/pkg/v3 v3.153.1 h1:8P3ryrJP0TwGG5qA20jJxuXRRcepj+pxGjPjGZQlbPE=
github.com/pulumi/pulumi/pkg/v3 v3.153.1/go.mod h1:aO7FkJVEBP3l9DgSNSPT4/P6b/XG5QD2OqvizvRahrg=
github.com/pulumi/pulumi/sdk/v3 v3.153.1 h1:qlkttqvoPcuxbMZd1ZfwairuYAZ68izqRnCWmpA9p84=
github.com/pulumi/pulumi/sdk/v3 v3.153.1/go.mod h1:+WC9aIDo8fMgd2g0jCHuZU2S/VYNLRAZ3QXt6YVgwaA=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
Expand Down
2 changes: 2 additions & 0 deletions pkg/pulumiyaml/analyser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ func newTypeCache() *typeCache {
ast.ObjectProperty{Key: ast.String("project")},
ast.ObjectProperty{Key: ast.String("stack")},
ast.ObjectProperty{Key: ast.String("organization")},
ast.ObjectProperty{Key: ast.String("rootDirectory")},
)
return &typeCache{
exprs: map[ast.Expr]schema.Type{
Expand All @@ -1187,6 +1188,7 @@ func newTypeCache() *typeCache {
{Name: "project", Type: schema.StringType},
{Name: "stack", Type: schema.StringType},
{Name: "organization", Type: schema.StringType},
{Name: "rootDirectory", Type: schema.StringType},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/pulumiyaml/codegen/gen_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func (g *generator) function(f *model.FunctionCallExpression) syn.Node {
return rng
}
switch f.Name {
case "stack", "project", "organization":
case "stack", "project", "organization", "rootDirectory":
return syn.String(fmt.Sprintf("${pulumi.%s}", f.Name))
case pcl.Invoke:
return g.MustInvoke(f, "")
Expand Down
18 changes: 12 additions & 6 deletions pkg/pulumiyaml/codegen/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func (imp *importer) pulumiPropertyAccess(node ast.Expr, accessors []ast.Propert
Name: "organization",
Signature: simple,
}, true, nil
case "rootDirectory":
return &model.FunctionCallExpression{
Name: "rootDirectory",
Signature: simple,
}, true, nil
default:
return nil, true, wrapDiag("Unknown property of the `pulumi` variable: '%s'", prop.Name)
}
Expand Down Expand Up @@ -963,6 +968,7 @@ func (imp *importer) assignNames() {
// PCL has only one namspace with respect to binding, so we can't use any of
// these as names.
assigned := codegen.NewStringSet(
"cwd",
"element",
"entries",
"fileArchive",
Expand All @@ -974,18 +980,18 @@ func (imp *importer) assignNames() {
"join",
"length",
"lookup",
"organization",
"project",
"range",
"readFile",
"readDir",
"readFile",
"rootDirectory",
"secret",
"sha1",
"split",
"stack",
"toBase64",
"toJSON",
"sha1",
"stack",
"project",
"cwd",
"organization",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have preferred to have these re-sorted separately, but I went through all of these and only rootDirectory was added 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sorry it was so small I wanted to just do it and sneak it in <_<

)

assign := func(name, suffix string) *model.Variable {
Expand Down
12 changes: 7 additions & 5 deletions pkg/pulumiyaml/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,17 +918,19 @@ func (r *Runner) ensureSetup(ctx *pulumi.Context) {
return
}

var project, stack, organization string
var project, stack, organization, rootDirectory string
if ctx != nil {
project = ctx.Project()
stack = ctx.Stack()
organization = ctx.Organization()
rootDirectory = ctx.RootDirectory()
}
r.variables[PulumiVarName] = map[string]interface{}{
"cwd": cwd,
"project": project,
"stack": stack,
"organization": organization,
"cwd": cwd,
"organization": organization,
"project": project,
"rootDirectory": rootDirectory,
"stack": stack,
}
r.cwd = cwd
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (host *yamlLanguageHost) Run(ctx context.Context, req *pulumirpc.RunRequest
fmt.Sprintf(`PULUMI_ORGANIZATION=%s`, req.GetOrganization()),
fmt.Sprintf(`PULUMI_PROJECT=%s`, req.GetProject()),
fmt.Sprintf(`PULUMI_CONFIG=%s`, jsonConfigValue),
fmt.Sprintf(`PULUMI_ROOT_DIRECTORY=%s`, req.Info.RootDirectory),
}

projPath, err := workspace.DetectProjectPathFrom(req.Info.RootDirectory)
Expand Down Expand Up @@ -233,6 +234,7 @@ func (host *yamlLanguageHost) Run(ctx context.Context, req *pulumirpc.RunRequest
// This encapsulates a fair bit of the boilerplate otherwise needed to do RPCs, etc.
pctx, err := pulumi.NewContext(ctx, pulumi.RunInfo{
Project: req.GetProject(),
RootDirectory: req.Info.RootDirectory,
Stack: req.GetStack(),
Config: req.GetConfig(),
ConfigSecretKeys: req.GetConfigSecretKeys(),
Expand Down
Loading