From 8c78e124ae9bef92e377e55a21a9f6d3e36d3ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=8BAndrzej=20Ressel?= Date: Sun, 31 Mar 2024 00:21:18 +0100 Subject: [PATCH] justfile runner (#92) --- docs/index.md | 7 +++- examples/simple/justfile | 8 ++++ justfile | 3 ++ pulumi-language-wasm/executors/executor.go | 5 +-- .../executors/executor_justfile_os.go | 33 ++++++++++++++++ .../executors/executor_unix_os.go | 38 ------------------- .../executors/executor_windows_os.go | 38 ------------------- scripts/README.md | 1 - scripts/docs.ps1 | 1 - scripts/docs.sh | 1 - 10 files changed, 52 insertions(+), 83 deletions(-) create mode 100644 examples/simple/justfile create mode 100644 pulumi-language-wasm/executors/executor_justfile_os.go delete mode 100644 pulumi-language-wasm/executors/executor_unix_os.go delete mode 100644 pulumi-language-wasm/executors/executor_windows_os.go delete mode 100644 scripts/README.md delete mode 100644 scripts/docs.ps1 delete mode 100644 scripts/docs.sh diff --git a/docs/index.md b/docs/index.md index 3d7219c52..4933b35e5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1 +1,6 @@ -# Getting started \ No newline at end of file +# Getting started + +## Requirements + +- [Rust](https://rustup.rs/) +- [just](https://github.com/casey/just) \ No newline at end of file diff --git a/examples/simple/justfile b/examples/simple/justfile new file mode 100644 index 000000000..2a3783092 --- /dev/null +++ b/examples/simple/justfile @@ -0,0 +1,8 @@ +set windows-shell := ["pwsh.exe", "-c"] + +build: + cargo run -p cargo-pulumi + +run: + just build + cargo run -p pulumi_wasm_runner -- run --wasm ../../target/wasm32-wasi/debug/composed.wasm diff --git a/justfile b/justfile index f66323507..9e80316fa 100644 --- a/justfile +++ b/justfile @@ -39,3 +39,6 @@ regenerate-providers: test: cargo test --all + +docs: + docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material \ No newline at end of file diff --git a/pulumi-language-wasm/executors/executor.go b/pulumi-language-wasm/executors/executor.go index a3384d7ca..5812d6c80 100644 --- a/pulumi-language-wasm/executors/executor.go +++ b/pulumi-language-wasm/executors/executor.go @@ -57,14 +57,13 @@ type wasmExecutorFactory interface { func NewWasmExecutor(opts WasmExecutorOptions) (*WasmExecutor, error) { e, err := combineWasmExecutorFactories( - &windows{}, - &unix{}, + &justfile{}, ).NewWasmExecutor(opts) if err != nil { return nil, err } if e == nil { - return nil, fmt.Errorf("failed to configure executor, tried: entrypoint.bat, entrypoint.sh") + return nil, fmt.Errorf("failed to configure executor, tried: justfile") } return e, nil } diff --git a/pulumi-language-wasm/executors/executor_justfile_os.go b/pulumi-language-wasm/executors/executor_justfile_os.go new file mode 100644 index 000000000..8e3ce5304 --- /dev/null +++ b/pulumi-language-wasm/executors/executor_justfile_os.go @@ -0,0 +1,33 @@ +// Copyright 2022, Pulumi Corporation. All rights reserved. + +package executors + +import ( + "github.com/andrzejressel/pulumi-wasm/pulumi-language-wasm/fsys" +) + +type justfile struct{} + +var _ wasmExecutorFactory = &justfile{} + +func (s justfile) NewWasmExecutor(opts WasmExecutorOptions) (*WasmExecutor, error) { + exists, err := fsys.FileExists(opts.WD, "justfile") + if err != nil { + return nil, err + } + if !exists { + return nil, nil + } + return s.newWasmCliExecutor() +} + +func (justfile) newWasmCliExecutor() (*WasmExecutor, error) { + return &WasmExecutor{ + Name: "just", + Cmd: "just", + BuildArgs: []string{"build"}, + RunArgs: []string{"run"}, + PluginArgs: []string{"plugin"}, + VersionArgs: []string{"version"}, + }, nil +} diff --git a/pulumi-language-wasm/executors/executor_unix_os.go b/pulumi-language-wasm/executors/executor_unix_os.go deleted file mode 100644 index 95431a31f..000000000 --- a/pulumi-language-wasm/executors/executor_unix_os.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, Pulumi Corporation. All rights reserved. - -package executors - -import ( - "github.com/andrzejressel/pulumi-wasm/pulumi-language-wasm/fsys" - "runtime" -) - -type unix struct{} - -var _ wasmExecutorFactory = &unix{} - -func (s unix) NewWasmExecutor(opts WasmExecutorOptions) (*WasmExecutor, error) { - if runtime.GOOS != "linux" && runtime.GOOS != "darwin" { - return nil, nil - } - probePaths := []string{opts.UseExecutor} - if opts.UseExecutor == "" { - probePaths = []string{"./entrypoint.sh"} - } - cmd, err := fsys.LookPath(opts.WD, probePaths...) - if err != nil { - return nil, err - } - return s.newWasmCliExecutor(cmd) -} - -func (unix) newWasmCliExecutor(script string) (*WasmExecutor, error) { - return &WasmExecutor{ - Name: script, - Cmd: "bash", - BuildArgs: []string{"-c", script, "build"}, - RunArgs: []string{"-c", script, "run"}, - PluginArgs: []string{"-c", script, "plugin"}, - VersionArgs: []string{"-c", script, "version"}, - }, nil -} diff --git a/pulumi-language-wasm/executors/executor_windows_os.go b/pulumi-language-wasm/executors/executor_windows_os.go deleted file mode 100644 index 20b97594c..000000000 --- a/pulumi-language-wasm/executors/executor_windows_os.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022, Pulumi Corporation. All rights reserved. - -package executors - -import ( - "github.com/andrzejressel/pulumi-wasm/pulumi-language-wasm/fsys" - "runtime" -) - -type windows struct{} - -var _ wasmExecutorFactory = &windows{} - -func (s windows) NewWasmExecutor(opts WasmExecutorOptions) (*WasmExecutor, error) { - if runtime.GOOS != "windows" { - return nil, nil - } - probePaths := []string{opts.UseExecutor} - if opts.UseExecutor == "" { - probePaths = []string{".\\entrypoint.ps1"} - } - cmd, err := fsys.LookPath(opts.WD, probePaths...) - if err != nil { - return nil, err - } - return s.newWasmCliExecutor(cmd) -} - -func (windows) newWasmCliExecutor(script string) (*WasmExecutor, error) { - return &WasmExecutor{ - Name: script, - Cmd: "powershell", - BuildArgs: []string{"-executionpolicy", "bypass", "-File", script, "build"}, - RunArgs: []string{"-executionpolicy", "bypass", "-File", script, "run"}, - PluginArgs: []string{"-File", script, "plugin"}, - VersionArgs: []string{"-File", script, "version"}, - }, nil -} diff --git a/scripts/README.md b/scripts/README.md deleted file mode 100644 index aee386a3d..000000000 --- a/scripts/README.md +++ /dev/null @@ -1 +0,0 @@ -These scripts must be run from root, not from `scripts` directory. \ No newline at end of file diff --git a/scripts/docs.ps1 b/scripts/docs.ps1 deleted file mode 100644 index 37c2c9330..000000000 --- a/scripts/docs.ps1 +++ /dev/null @@ -1 +0,0 @@ -docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material \ No newline at end of file diff --git a/scripts/docs.sh b/scripts/docs.sh deleted file mode 100644 index 37c2c9330..000000000 --- a/scripts/docs.sh +++ /dev/null @@ -1 +0,0 @@ -docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material \ No newline at end of file