From bbff34c2a12cc728f6b0a5f306e15226bb6a7199 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Mon, 19 Aug 2024 11:34:25 -0700 Subject: [PATCH 1/4] Use managed instead of smart env store --- internal/cmd/run_test.go | 8 +++---- internal/command/program_resolver.go | 2 +- internal/command/program_resolver_test.go | 24 +++++++++---------- internal/runner/client/client_test.go | 6 ++--- .../service_resolve_program_test.go | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/cmd/run_test.go b/internal/cmd/run_test.go index 43172970b..974240f9b 100644 --- a/internal/cmd/run_test.go +++ b/internal/cmd/run_test.go @@ -73,16 +73,16 @@ func TestPromptEnvVars(t *testing.T) { assert.NoError(t, err) expectedLines := `# -# VAR_NAME1 set in smart env store +# VAR_NAME1 set in managed env store # "export VAR_NAME1='Placeholder 1'" # -# VAR_NAME2 set in smart env store +# VAR_NAME2 set in managed env store # "export VAR_NAME2=\"Placeholder 2\"" # -# VAR_NAME3 set in smart env store +# VAR_NAME3 set in managed env store # "export VAR_NAME3=\"\"" # -# VAR_NAME4 set in smart env store +# VAR_NAME4 set in managed env store # "export VAR_NAME4=Message" diff --git a/internal/command/program_resolver.go b/internal/command/program_resolver.go index 13a20e597..84cc60e7c 100644 --- a/internal/command/program_resolver.go +++ b/internal/command/program_resolver.go @@ -356,7 +356,7 @@ func (r *ProgramResolver) modifyStmt(stmt *syntax.Stmt, decl *syntax.DeclClause) stmt.Comments = append(stmt.Comments, syntax.Comment{Text: "\n"}, - syntax.Comment{Text: fmt.Sprintf(" %s set in smart env store", decl.Args[0].Name.Value)}, + syntax.Comment{Text: fmt.Sprintf(" %s set in managed env store", decl.Args[0].Name.Value)}, syntax.Comment{Text: fmt.Sprintf(" %q", exportStmt.String())}, ) diff --git a/internal/command/program_resolver_test.go b/internal/command/program_resolver_test.go index b18e8502a..4b5c2e003 100644 --- a/internal/command/program_resolver_test.go +++ b/internal/command/program_resolver_test.go @@ -28,7 +28,7 @@ func TestProgramResolverResolve(t *testing.T) { }, }, }, - modifiedProgram: "#\n# TEST_NO_VALUE set in smart env store\n# \"export TEST_NO_VALUE\"\n\n", + modifiedProgram: "#\n# TEST_NO_VALUE set in managed env store\n# \"export TEST_NO_VALUE\"\n\n", }, { name: "empty value", @@ -42,7 +42,7 @@ func TestProgramResolverResolve(t *testing.T) { }, }, }, - modifiedProgram: "#\n# TEST_EMPTY_VALUE set in smart env store\n# \"export TEST_EMPTY_VALUE=\"\n\n", + modifiedProgram: "#\n# TEST_EMPTY_VALUE set in managed env store\n# \"export TEST_EMPTY_VALUE=\"\n\n", }, { name: "string value", @@ -57,7 +57,7 @@ func TestProgramResolverResolve(t *testing.T) { }, }, }, - modifiedProgram: "#\n# TEST_STRING_VALUE set in smart env store\n# \"export TEST_STRING_VALUE=value\"\n\n", + modifiedProgram: "#\n# TEST_STRING_VALUE set in managed env store\n# \"export TEST_STRING_VALUE=value\"\n\n", }, { name: "string value with equal sign", @@ -72,7 +72,7 @@ func TestProgramResolverResolve(t *testing.T) { }, }, }, - modifiedProgram: "#\n# TEST_STRING_VALUE_WITH_EQUAL_SIGN set in smart env store\n# \"export TEST_STRING_VALUE_WITH_EQUAL_SIGN=part1=part2\"\n\n", + modifiedProgram: "#\n# TEST_STRING_VALUE_WITH_EQUAL_SIGN set in managed env store\n# \"export TEST_STRING_VALUE_WITH_EQUAL_SIGN=part1=part2\"\n\n", }, { name: "string double quoted value empty", @@ -86,7 +86,7 @@ func TestProgramResolverResolve(t *testing.T) { }, }, }, - modifiedProgram: "#\n# TEST_STRING_DBL_QUOTED_VALUE_EMPTY set in smart env store\n# \"export TEST_STRING_DBL_QUOTED_VALUE_EMPTY=\\\"\\\"\"\n\n", + modifiedProgram: "#\n# TEST_STRING_DBL_QUOTED_VALUE_EMPTY set in managed env store\n# \"export TEST_STRING_DBL_QUOTED_VALUE_EMPTY=\\\"\\\"\"\n\n", }, { name: "string double quoted value", @@ -101,7 +101,7 @@ func TestProgramResolverResolve(t *testing.T) { }, }, }, - modifiedProgram: "#\n# TEST_STRING_DBL_QUOTED_VALUE set in smart env store\n# \"export TEST_STRING_DBL_QUOTED_VALUE=\\\"value\\\"\"\n\n", + modifiedProgram: "#\n# TEST_STRING_DBL_QUOTED_VALUE set in managed env store\n# \"export TEST_STRING_DBL_QUOTED_VALUE=\\\"value\\\"\"\n\n", }, { name: "string single quoted value empty", @@ -115,7 +115,7 @@ func TestProgramResolverResolve(t *testing.T) { }, }, }, - modifiedProgram: "#\n# TEST_STRING_SGL_QUOTED_VALUE_EMPTY set in smart env store\n# \"export TEST_STRING_SGL_QUOTED_VALUE_EMPTY=''\"\n\n", + modifiedProgram: "#\n# TEST_STRING_SGL_QUOTED_VALUE_EMPTY set in managed env store\n# \"export TEST_STRING_SGL_QUOTED_VALUE_EMPTY=''\"\n\n", }, { name: "string single quoted value", @@ -130,7 +130,7 @@ func TestProgramResolverResolve(t *testing.T) { }, }, }, - modifiedProgram: "#\n# TEST_STRING_SGL_QUOTED_VALUE set in smart env store\n# \"export TEST_STRING_SGL_QUOTED_VALUE='value'\"\n\n", + modifiedProgram: "#\n# TEST_STRING_SGL_QUOTED_VALUE set in managed env store\n# \"export TEST_STRING_SGL_QUOTED_VALUE='value'\"\n\n", }, { name: "parameter expression", @@ -217,7 +217,7 @@ func TestProgramResolverResolve_ProgramResolverModeAuto(t *testing.T) { }, result, ) - require.EqualValues(t, "#\n# MY_ENV set in smart env store\n# \"export MY_ENV=default\"\n\n", buf.String()) + require.EqualValues(t, "#\n# MY_ENV set in managed env store\n# \"export MY_ENV=default\"\n\n", buf.String()) } func TestProgramResolverResolve_ProgramResolverModePrompt(t *testing.T) { @@ -245,7 +245,7 @@ func TestProgramResolverResolve_ProgramResolverModePrompt(t *testing.T) { }, result, ) - require.EqualValues(t, "#\n# MY_ENV set in smart env store\n# \"export MY_ENV=message value\"\n\n", buf.String()) + require.EqualValues(t, "#\n# MY_ENV set in managed env store\n# \"export MY_ENV=message value\"\n\n", buf.String()) }) t.Run("Prompt with placeholder", func(t *testing.T) { @@ -272,7 +272,7 @@ func TestProgramResolverResolve_ProgramResolverModePrompt(t *testing.T) { }, result, ) - require.EqualValues(t, "#\n# MY_ENV set in smart env store\n# \"export MY_ENV=\\\"placeholder value\\\"\"\n\n", buf.String()) + require.EqualValues(t, "#\n# MY_ENV set in managed env store\n# \"export MY_ENV=\\\"placeholder value\\\"\"\n\n", buf.String()) }) } @@ -312,6 +312,6 @@ func TestProgramResolverResolve_SensitiveEnvKeys(t *testing.T) { }, result, ) - require.EqualValues(t, "#\n# MY_PASSWORD set in smart env store\n# \"export MY_PASSWORD=super-secret\"\n#\n# MY_SECRET set in smart env store\n# \"export MY_SECRET=also-secret\"\n#\n# MY_PLAIN set in smart env store\n# \"export MY_PLAIN=text\"\n\n", buf.String()) + require.EqualValues(t, "#\n# MY_PASSWORD set in managed env store\n# \"export MY_PASSWORD=super-secret\"\n#\n# MY_SECRET set in managed env store\n# \"export MY_SECRET=also-secret\"\n#\n# MY_PLAIN set in managed env store\n# \"export MY_PLAIN=text\"\n\n", buf.String()) }) } diff --git a/internal/runner/client/client_test.go b/internal/runner/client/client_test.go index 3b70cb9cd..9e4ef3d21 100644 --- a/internal/runner/client/client_test.go +++ b/internal/runner/client/client_test.go @@ -134,7 +134,7 @@ func TestResolveProgramLocal(t *testing.T) { }, }, ExpectedScript: `# -# VARIABLE set in smart env store +# VARIABLE set in managed env store # "export VARIABLE=Foo" `, @@ -150,7 +150,7 @@ func TestResolveProgramLocal(t *testing.T) { }, }, ExpectedScript: `# -# VARIABLE set in smart env store +# VARIABLE set in managed env store # "export VARIABLE=Foo" `, @@ -166,7 +166,7 @@ func TestResolveProgramLocal(t *testing.T) { }, }, ExpectedScript: `# -# VARIABLE set in smart env store +# VARIABLE set in managed env store # "export VARIABLE=Foo" `, diff --git a/internal/runnerv2service/service_resolve_program_test.go b/internal/runnerv2service/service_resolve_program_test.go index 07deabe98..4215524a9 100644 --- a/internal/runnerv2service/service_resolve_program_test.go +++ b/internal/runnerv2service/service_resolve_program_test.go @@ -127,7 +127,7 @@ func TestRunnerResolveProgram_CommandsWithNewLines(t *testing.T) { t, []string{ "#", - "# FILE_NAME set in smart env store", + "# FILE_NAME set in managed env store", "# \"export FILE_NAME=default.txt\"", "", "cat >\"$FILE_NAME\" < Date: Tue, 20 Aug 2024 14:39:56 -0700 Subject: [PATCH 2/4] Overhaul Dev Experience (#656) The idea is to bring the explainer per paragraph into the TUI. --- CONTRIBUTING.md | 83 ++++++++++++++++++++++++++++++--------------- RELEASE.md | 52 ---------------------------- internal/cmd/tui.go | 20 ++++++++--- 3 files changed, 70 insertions(+), 85 deletions(-) delete mode 100644 RELEASE.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5c74c3e40..61209d96b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,7 +31,7 @@ To request a new feature you should open an [issue](../../issues/new) and summar This is an outline of what the workflow for code contributions looks like - Check the list of open [issues](../../issues). Either assign an existing issue to yourself, or - create a new one that you would like work on and discuss your ideas and use cases. + create a new one that you would like work on and discuss your ideas and use cases. It is always best to discuss your plans beforehand, to ensure that your contribution is in line with our goals. @@ -86,9 +86,9 @@ Following is some documentation on the different build targets `runme` has, and #### CLI -CLI is built with: +Build the CLI: -```sh {"id":"01HF7BT3HEQBTBM9SSTFD1C6N4","interactive":"false"} +```sh {"id":"01HF7BT3HEQBTBM9SSTFD1C6N4","interactive":"false","name":"build"} make build ``` @@ -99,18 +99,13 @@ This builds the CLI binary for the current platform to an executable file "runme # outputs: "runme version 1.3.0-27-g3cca8a6-3cca8a6 (3cca8a6e7d34f401c1bdd99828a7fac5b1d8fac9) on 2023-07-31T16:49:57Z" ``` -To run the server in dev mode with predictable port and TLS credentials location: - -```sh {"background":"true","id":"01HJ9NZT45B03C9J6YJJJDB8PG","interactive":"true","name":"server-dev"} -go run . server --dev --address 127.0.0.1:9999 --tls /tmp/runme/tls 2>&1 -``` - #### WASM WASM is built with: -```sh {"id":"01HF7BT3HEQBTBM9SSTH3HC2DS","interactive":"false"} +```sh {"id":"01HF7BT3HEQBTBM9SSTH3HC2DS"} make wasm +ls -la examples/web/runme.wasm ``` This builds the wasm file to `examples/web/runme.wasm`. @@ -119,13 +114,13 @@ This builds the wasm file to `examples/web/runme.wasm`. To install tools like `gofumpt` and `revive` which are used for development (e.g. linting) run -```sh +```sh {"id":"01J5P9MKFZ4SRS1VE6J62HFKP0","name":"setup"} make install/dev ``` You will need the [pre-commit](https://pre-commit.com/) tool to run the pre-commit hooks. You can install it with: -```sh +```sh {"id":"01J5P9MKFZ4SRS1VE6J8XKD8ZM"} python3 -m pip install pre-commit ``` @@ -147,33 +142,59 @@ pre-commit run --files */** Tests are run with Go's default test runner wrapped in Makefile targets. So, for example, you can run all tests with: -```sh {"id":"01HF7BT3HEQBTBM9SSTS88ZSCF"} -make test +```sh {"id":"01HF7BT3HEQBTBM9SSTS88ZSCF","name":"test","terminalRows":"15"} +go clean -testcache +TAGS="test_with_docker" make test ``` Please notice that our tests include integration tests which depend on additional software like Python or node.js. If you don't want to install them or tests fail because of different versions, you can run all tests in a Docker container: -```sh +```sh {"id":"01J5P9MKFZ4SRS1VE6JBKG3EAK","terminalRows":"15"} make test-docker ``` +## Development + +To run the server in dev mode with predictable port and TLS credentials location: + +```sh {"background":"true","id":"01HJ9NZT45B03C9J6YJJJDB8PG","interactive":"true","name":"server-dev"} +go run . server --dev --address 127.0.0.1:9999 --tls /tmp/runme/tls 2>&1 +``` + +### Upgrading Minor Version Dependencies + +For upgrading dependencies that have minor version changes, as well as test dependencies, use the following command. This command fetches the latest minor or patch versions of the modules required for building the current module, including their dependencies: +Periodically dependencies need to be upgraded. For minor versions with test deps: + +```sh {"id":"01HF7BT3HEQBTBM9SSSG798S2D"} +$ go get -t -u ./... +``` + +### Upgrading Major Version Dependencies + +When you need to upgrade to major versions of your dependencies, it’s prudent to upgrade each dependency one at a time to manage potential breaking changes efficiently. The `gomajor` tool can assist you in listing and upgrading major version dependencies. To list all major version upgrades available for your project, use the following command: + +```sh {"id":"01HF7BT3HEQBTBM9SSSK6JMS58"} +$ gomajor list +``` + ### Coverage In order to generate a coverage report, run tests using -```sh {"name":"coverage-run"} +```sh {"id":"01J5P9MKFZ4SRS1VE6JCT00N4K"} make test-coverage ``` -And then: +And then, for the html coverage report, run: -```sh {"id":"01HJVHEVPX2AZJ86999P1MY5H0","name":"coverage-html"} +```sh {"id":"01HJVHEVPX2AZJ86999P1MY5H0"} make test/coverage/html ``` Output coverage profile information for each function: -```sh {"id":"01HJVHHNMZRNK0ZGA154A9AJCZ","name":"coverage-func"} +```sh {"id":"01HJVHHNMZRNK0ZGA154A9AJCZ"} make test/coverage/func ``` @@ -223,6 +244,20 @@ export RUNME_EXT_BASE="../vscode-runme" make proto/dev/reset ``` +### Publish Protobuf Definitions + +Firstly, set up your Buffer (Buf) token by exporting it as an environment variable. Replace `Your buf token` with your actual Buf token: + +```sh {"id":"01HF7BT3HEQBTBM9SSSNM5ZT19"} +export BUF_TOKEN=Your buf token +``` + +After setting the Buf token, proceed to publish the updated protobuf definitions. The `make proto/publish` command below will trigger the publishing process, ensuring your protobuf definitions are released and available for use: + +```sh {"id":"01HF7BT3HEQBTBM9SSSPD5B5WW","name":"proto-publish-buf"} +make proto/publish +``` + ### GraphQL GraphQL schema are generated as part of: @@ -249,7 +284,7 @@ make generate This project uses [gomock](https://github.com/golang/mock) to generate some mocks for some interfaces. You will need to install `gomock` in order for `go generate` to work. -## Releasing +## Release Kernel/CLI The releaser uses `goreleaser` to handle cross-compilation, as well as snapshotting etc. This is run with: @@ -262,11 +297,3 @@ The requisite tools can be installed with: ```sh {"id":"01HF7BT3HF9WY615MNGR8HJEKZ","interactive":"false"} make install/goreleaser ``` - -## Upgrading to go 1.22 - -After upgrading go to version 1.22, you'll need to make sure to reinstall dev packages, as some may be outdated: - -```sh {"id":"01HF7BT3HF9WY615MNGREVYKFG","name":"upgrade-go-1-22"} -make install/dev -``` diff --git a/RELEASE.md b/RELEASE.md deleted file mode 100644 index 8290d9b28..000000000 --- a/RELEASE.md +++ /dev/null @@ -1,52 +0,0 @@ ---- -runme: - id: 01HF7BT3HEQBTBM9SSSRB5RCB8 - version: v3 ---- - -# Release - -## Upgrading go mods - -Over time, it's essential to update your project dependencies for smoother and secure functioning. This section guides you through the process of upgrading Go module dependencies. - -### Upgrading Minor Version Dependencies - -For upgrading dependencies that have minor version changes, as well as test dependencies, use the following command. This command fetches the latest minor or patch versions of the modules required for building the current module, including their dependencies: -Periodically dependencies need to be upgraded. For minor versions with test deps: - -```sh {"id":"01HF7BT3HEQBTBM9SSSG798S2D"} -$ go get -t -u ./... - -``` - -### Upgrading Major Version Dependencies - -When you need to upgrade to major versions of your dependencies, it’s prudent to upgrade each dependency one at a time to manage potential breaking changes efficiently. The `gomajor` tool can assist you in listing and upgrading major version dependencies. To list all major version upgrades available for your project, use the following command: - -```sh {"id":"01HF7BT3HEQBTBM9SSSK6JMS58"} -$ gomajor list - -``` - -## Protos - -Protocol Buffers (Protos) are a language-agnostic binary serialization format. If you have made changes to your protobuf definitions and need to release these, follow the steps outlined below. - -### Set Buffer Token - -Firstly, set up your Buffer (Buf) token by exporting it as an environment variable. Replace `Your buf token` with your actual Buf token: - -```sh {"id":"01HF7BT3HEQBTBM9SSSNM5ZT19","name":"buf-token"} -export BUF_TOKEN=Your buf token - -``` - -### Publish Protobuf Definitions - -After setting the Buf token, proceed to publish the updated protobuf definitions. The `make proto/publish` command below will trigger the publishing process, ensuring your protobuf definitions are released and available for use: - -```sh {"id":"01HF7BT3HEQBTBM9SSSPD5B5WW","name":"release-buf"} -make proto/publish - -``` diff --git a/internal/cmd/tui.go b/internal/cmd/tui.go index 00c10af21..ed7baa0d5 100644 --- a/internal/cmd/tui.go +++ b/internal/cmd/tui.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "math" + "path/filepath" "strings" "github.com/atotto/clipboard" @@ -295,7 +296,7 @@ func (m tuiModel) Init() tea.Cmd { const ( tab = " " - defaultVisibleEntries = 5 + defaultVisibleEntries = 6 ) func (m tuiModel) View() string { @@ -319,21 +320,30 @@ func (m tuiModel) View() string { { name := block.Name() - if block.IsUnnamed() { name += " (unnamed)" } - filename := ansi.Color(getRelativePath(getCwd(), task.DocumentPath), "white+d") + relFilename := getRelativePath(getCwd(), task.DocumentPath) + filename := ansi.Color(relFilename, "white+d") if active { - name = ansi.Color(name, "white+b") + name = ansi.Color(name, "white+ub") + } + + intro := block.Intro() + words := strings.Split(intro, " ") + // todo(sebastian): this likely only works well for English + max := 9 - len(strings.Split(relFilename, fmt.Sprint(filepath.Separator))) + if len(words) > max { + intro = strings.Join(words[:max], " ") + "..." } identifier := fmt.Sprintf( - "%s %s", + "%s %s: %s", name, filename, + intro, ) line += identifier + "\n" From ed87cf38c0313941321f8640c349aedc65da0dc9 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Wed, 21 Aug 2024 11:43:06 -0700 Subject: [PATCH 3/4] Cosmetic change, omit colon if intro is empty --- internal/cmd/tui.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/cmd/tui.go b/internal/cmd/tui.go index ed7baa0d5..7cee885c4 100644 --- a/internal/cmd/tui.go +++ b/internal/cmd/tui.go @@ -339,8 +339,12 @@ func (m tuiModel) View() string { intro = strings.Join(words[:max], " ") + "..." } + if len(intro) > 0 { + intro = ": " + intro + } + identifier := fmt.Sprintf( - "%s %s: %s", + "%s %s%s", name, filename, intro, From 97faded044bb04c7463f154716b6fac236775176 Mon Sep 17 00:00:00 2001 From: Sebastian Tiedtke Date: Wed, 21 Aug 2024 11:46:52 -0700 Subject: [PATCH 4/4] Upgrade tools --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index e3eccd631..8dc4eb9cf 100644 --- a/Makefile +++ b/Makefile @@ -110,11 +110,11 @@ pre-commit: build wasm test lint .PHONY: install/dev install/dev: - go install github.com/mgechev/revive@v1.3.7 - go install github.com/securego/gosec/v2/cmd/gosec@v2.19.0 - go install honnef.co/go/tools/cmd/staticcheck@v0.4.6 - go install mvdan.cc/gofumpt@v0.6.0 - go install github.com/icholy/gomajor@v0.9.5 + go install github.com/mgechev/revive@v1.3.9 + go install github.com/securego/gosec/v2/cmd/gosec@v2.20.0 + go install honnef.co/go/tools/cmd/staticcheck@v0.5.1 + go install mvdan.cc/gofumpt@v0.7.0 + go install github.com/icholy/gomajor@v0.13.1 go install github.com/stateful/go-proto-gql/protoc-gen-gql@latest .PHONY: install/goreleaser