From a9c37d58f973f2b5d64d1457a8bed09495eabc1c Mon Sep 17 00:00:00 2001 From: rapha Date: Tue, 12 Mar 2024 15:05:59 +0100 Subject: [PATCH] feat(kystrap): update release please config when creating new runtimes --- release-please-config.json | 32 +++++----- tools/kystrap/bootstrap/bootstrap.go | 60 +++++++++++++++++++ tools/kystrap/cmd/create.go | 8 ++- tools/kystrap/kystrap.sh | 29 +++++---- tools/kystrap/templates/go/CHANGELOG.md | 8 --- tools/kystrap/templates/python/CHANGELOG.md | 8 --- .../kystrap/templates/typescript/CHANGELOG.md | 9 --- 7 files changed, 99 insertions(+), 55 deletions(-) delete mode 100644 tools/kystrap/templates/go/CHANGELOG.md delete mode 100644 tools/kystrap/templates/python/CHANGELOG.md delete mode 100644 tools/kystrap/templates/typescript/CHANGELOG.md diff --git a/release-please-config.json b/release-please-config.json index 7113cf7e..77311094 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -1,42 +1,42 @@ { "include-component-in-tag": true, - "tag-separator": "@", "include-v-in-tag": false, "packages": { "common/goutils": { - "release-type": "go", - "package-name": "common/goutils" + "package-name": "common/goutils", + "release-type": "go" }, "protocol/core": { - "release-type": "node", + "initial-version": "1.1.5", "package-name": "protocol/core", - "initial-version": "1.1.5" + "release-type": "node" }, "runtime/tendermint": { - "release-type": "node", + "initial-version": "1.1.5", "package-name": "runtime/tendermint", - "initial-version": "1.1.5" + "release-type": "node" }, "runtime/tendermint-bsync": { - "release-type": "node", + "initial-version": "1.1.5", "package-name": "runtime/tendermint-bsync", - "initial-version": "1.1.5" + "release-type": "node" }, "runtime/tendermint-ssync": { - "release-type": "node", + "initial-version": "1.1.5", "package-name": "runtime/tendermint-ssync", - "initial-version": "1.1.5" + "release-type": "node" }, "tools/kysor": { - "release-type": "go", - "package-name": "tools/kysor", "initial-version": "1.3.1", + "package-name": "tools/kysor", + "release-type": "go", "separate-pull-requests": true, "skip-github-release": true }, "tools/kystrap": { - "release-type": "go", - "package-name": "tools/kystrap" + "package-name": "tools/kystrap", + "release-type": "go" } - } + }, + "tag-separator": "@" } \ No newline at end of file diff --git a/tools/kystrap/bootstrap/bootstrap.go b/tools/kystrap/bootstrap/bootstrap.go index fe0b9eb1..e6ab338e 100644 --- a/tools/kystrap/bootstrap/bootstrap.go +++ b/tools/kystrap/bootstrap/bootstrap.go @@ -1,6 +1,7 @@ package bootstrap import ( + "encoding/json" "errors" "fmt" "os" @@ -124,3 +125,62 @@ func CreateRuntime(outputDir string, language types.Language, name string) error return createFile(path, newPath, data, fileInfo) }) } + +func UpdateReleasePleaseConfig(language types.Language, name string) error { + configPath := "release-please-config.json" + + // Read the config file + data, err := os.ReadFile(configPath) + if err != nil { + return err + } + + // Parse the JSON content into a map + var config map[string]interface{} + err = json.Unmarshal(data, &config) + if err != nil { + return err + } + + releaseType := "" + switch language.StringValue() { + case "go": + releaseType = "go" + case "typescript": + releaseType = "node" + case "python": + releaseType = "python" + default: + return fmt.Errorf("unsupported language: %s", language.StringValue()) + } + + // Create a new package + packageName := "runtime/" + name + newPackage := map[string]interface{}{ + "release-type": releaseType, + "package-name": packageName, + } + + // Get the packages map from the config + packages, ok := config["packages"].(map[string]interface{}) + if !ok { + return fmt.Errorf("failed to parse packages") + } + + // Add the new package to the packages map + packages[packageName] = newPackage + + // Convert the updated Config back to JSON + updatedData, err := json.MarshalIndent(config, "", " ") + if err != nil { + return err + } + + // Write the updated JSON back to the config file + err = os.WriteFile(configPath, updatedData, 0644) + if err != nil { + return err + } + + return nil +} diff --git a/tools/kystrap/cmd/create.go b/tools/kystrap/cmd/create.go index 083ad28f..c4291b8f 100644 --- a/tools/kystrap/cmd/create.go +++ b/tools/kystrap/cmd/create.go @@ -55,7 +55,7 @@ var ( Name: "output", Short: "o", Usage: "Output directory for your runtime", - DefaultValue: "out", + DefaultValue: "runtime", } ) @@ -103,6 +103,12 @@ func CmdCreateRuntime() *cobra.Command { if err != nil { return err } + + err = bootstrap.UpdateReleasePleaseConfig(language, name) + if err != nil { + return err + } + fmt.Printf("✅ Successfully created runtime in `%s`\n", name) return nil }, diff --git a/tools/kystrap/kystrap.sh b/tools/kystrap/kystrap.sh index d0b6883c..0ff7ebdc 100755 --- a/tools/kystrap/kystrap.sh +++ b/tools/kystrap/kystrap.sh @@ -2,6 +2,7 @@ # Set RUNTIME_DIR RUNTIME_DIR=${PWD}/runtime +RELEASE_PLEASE_CONFIG=${PWD}/release-please-config.json # Go up until the root of the project (max 2 levels) for _ in $(seq 1 2); do @@ -58,19 +59,21 @@ fi # Run docker image if [ "$NON_INTERACTIVE" = true ]; then docker run \ - --rm `# Remove container after run` \ - --user "$(id -u):$(id -g)" `# Run as current user` \ - --net="host" `# Use host network` \ - --add-host=host.docker.internal:host-gateway `# Add host.docker.internal to /etc/hosts` \ - -v "$RUNTIME_DIR":/app/out `# Mount runtime folder` \ - kystrap $(echo "$@") # Pass all arguments to kystrap + --rm `# Remove container after run` \ + --user "$(id -u):$(id -g)" `# Run as current user` \ + --net="host" `# Use host network` \ + --add-host=host.docker.internal:host-gateway `# Add host.docker.internal to /etc/hosts` \ + -v "$RUNTIME_DIR":/app/runtime `# Mount runtime folder` \ + -v "$RELEASE_PLEASE_CONFIG":/app/release-please-config.json `# Mount release-please config` \ + kystrap $(echo "$@") # Pass all arguments to kystrap else docker run \ - -it `# Run in interactive mode` \ - --rm `# Remove container after run` \ - --user "$(id -u):$(id -g)" `# Run as current user` \ - --net="host" `# Use host network` \ - --add-host=host.docker.internal:host-gateway `# Add host.docker.internal to /etc/hosts` \ - -v "$RUNTIME_DIR":/app/out `# Mount runtime folder` \ - kystrap $(echo "$@") # Pass all arguments to kystrap + -it `# Run in interactive mode` \ + --rm `# Remove container after run` \ + --user "$(id -u):$(id -g)" `# Run as current user` \ + --net="host" `# Use host network` \ + --add-host=host.docker.internal:host-gateway `# Add host.docker.internal to /etc/hosts` \ + -v "$RUNTIME_DIR":/app/runtime `# Mount runtime folder` \ + -v "$RELEASE_PLEASE_CONFIG":/app/release-please-config.json `# Mount release-please config` \ + kystrap $(echo "$@") # Pass all arguments to kystrap fi \ No newline at end of file diff --git a/tools/kystrap/templates/go/CHANGELOG.md b/tools/kystrap/templates/go/CHANGELOG.md deleted file mode 100644 index a61cd2b0..00000000 --- a/tools/kystrap/templates/go/CHANGELOG.md +++ /dev/null @@ -1,8 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.0.1] - -**Note:** TODO UPDATE BEFORE MERGING diff --git a/tools/kystrap/templates/python/CHANGELOG.md b/tools/kystrap/templates/python/CHANGELOG.md deleted file mode 100644 index a61cd2b0..00000000 --- a/tools/kystrap/templates/python/CHANGELOG.md +++ /dev/null @@ -1,8 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.0.1] - -**Note:** TODO UPDATE BEFORE MERGING diff --git a/tools/kystrap/templates/typescript/CHANGELOG.md b/tools/kystrap/templates/typescript/CHANGELOG.md deleted file mode 100644 index f2fca9e4..00000000 --- a/tools/kystrap/templates/typescript/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [{{ .version }}] () () - -[//]: # (TODO: Update this section before merging) -**Note:** TODO UPDATE BEFORE MERGING