Skip to content

Commit

Permalink
feat(kystrap): update release please config when creating new runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
shifty11 committed Mar 12, 2024
1 parent 71e1270 commit a9c37d5
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 55 deletions.
32 changes: 16 additions & 16 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -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": "@"
}
60 changes: 60 additions & 0 deletions tools/kystrap/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bootstrap

import (
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -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
}
8 changes: 7 additions & 1 deletion tools/kystrap/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (
Name: "output",
Short: "o",
Usage: "Output directory for your runtime",
DefaultValue: "out",
DefaultValue: "runtime",
}
)

Expand Down Expand Up @@ -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
},
Expand Down
29 changes: 16 additions & 13 deletions tools/kystrap/kystrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 0 additions & 8 deletions tools/kystrap/templates/go/CHANGELOG.md

This file was deleted.

8 changes: 0 additions & 8 deletions tools/kystrap/templates/python/CHANGELOG.md

This file was deleted.

9 changes: 0 additions & 9 deletions tools/kystrap/templates/typescript/CHANGELOG.md

This file was deleted.

0 comments on commit a9c37d5

Please sign in to comment.