Skip to content

Commit dabc79c

Browse files
committed
update module, add release.sh
1 parent cb4bdfb commit dabc79c

5 files changed

Lines changed: 214 additions & 12 deletions

File tree

components/eval/eval.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/grafana/sobek"
88
"github.com/tiny-systems/js-module/lib"
99
"github.com/tiny-systems/js-module/modules"
10+
"github.com/tiny-systems/module/api/v1alpha1"
1011
"github.com/tiny-systems/module/module"
1112
"github.com/tiny-systems/module/registry"
1213
"testing/fstest"
@@ -96,7 +97,7 @@ func (h *Component) GetInfo() module.ComponentInfo {
9697
func (h *Component) Handle(ctx context.Context, handler module.Handler, port string, msg interface{}) any {
9798

9899
switch port {
99-
case module.SettingsPort:
100+
case v1alpha1.SettingsPort:
100101
// compile template
101102
in, ok := msg.(Settings)
102103
if !ok {
@@ -228,7 +229,7 @@ func (h *Component) Ports() []module.Port {
228229
Configuration: Response{},
229230
},
230231
{
231-
Name: module.SettingsPort,
232+
Name: v1alpha1.SettingsPort,
232233
Label: "Settings",
233234
Configuration: h.settings,
234235
},

components/eval/eval_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package eval
33
import (
44
"context"
55
"fmt"
6+
"github.com/tiny-systems/module/api/v1alpha1"
67
"github.com/tiny-systems/module/module"
78
"testing"
89
)
@@ -23,7 +24,7 @@ func TestComponent_Handle(t *testing.T) {
2324

2425
args: []args{
2526
{
26-
port: module.SettingsPort,
27+
port: v1alpha1.SettingsPort,
2728
wantErr: true,
2829
msg: Settings{
2930
Script: Script{
@@ -38,7 +39,7 @@ func TestComponent_Handle(t *testing.T) {
3839

3940
args: []args{
4041
{
41-
port: module.SettingsPort,
42+
port: v1alpha1.SettingsPort,
4243
wantErr: true,
4344
msg: Settings{
4445
Script: Script{
@@ -52,7 +53,7 @@ func TestComponent_Handle(t *testing.T) {
5253
name: "success match result string",
5354
args: []args{
5455
{
55-
port: module.SettingsPort,
56+
port: v1alpha1.SettingsPort,
5657
msg: Settings{
5758
Script: Script{
5859
Content: `export default function () { return "result";}`,
@@ -82,7 +83,7 @@ func TestComponent_Handle(t *testing.T) {
8283
name: "success match result check type int",
8384
args: []args{
8485
{
85-
port: module.SettingsPort,
86+
port: v1alpha1.SettingsPort,
8687
msg: Settings{
8788
Script: Script{
8889
Content: `export default function () { return 34;}`,
@@ -114,7 +115,7 @@ func TestComponent_Handle(t *testing.T) {
114115
name: "success match response use request",
115116
args: []args{
116117
{
117-
port: module.SettingsPort,
118+
port: v1alpha1.SettingsPort,
118119
msg: Settings{
119120
Script: Script{
120121
Content: `export default function (i) { return i + " world";}`,
@@ -147,7 +148,7 @@ func TestComponent_Handle(t *testing.T) {
147148
name: "success use promises",
148149
args: []args{
149150
{
150-
port: module.SettingsPort,
151+
port: v1alpha1.SettingsPort,
151152
msg: Settings{
152153
Script: Script{
153154
Content: `export default async function (i) { return await new Promise((resolve, reject) => {resolve("done")})}`,
@@ -179,7 +180,7 @@ func TestComponent_Handle(t *testing.T) {
179180
name: "reject should trigger error",
180181
args: []args{
181182
{
182-
port: module.SettingsPort,
183+
port: v1alpha1.SettingsPort,
183184
msg: Settings{
184185
Script: Script{
185186
Content: `export default async function (i) { return await new Promise((resolve, reject) => {reject("error")})}`,
@@ -200,7 +201,7 @@ func TestComponent_Handle(t *testing.T) {
200201
name: "success promise of promise",
201202
args: []args{
202203
{
203-
port: module.SettingsPort,
204+
port: v1alpha1.SettingsPort,
204205
msg: Settings{
205206
Script: Script{
206207
Content: `export default async function (i) { return await new Promise((resolve, reject) => {resolve(new Promise((resolve, reject) => {resolve("done")}))})}`,

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/rs/zerolog v1.34.0
1111
github.com/spf13/cobra v1.10.1
1212
github.com/spf13/viper v1.20.1
13-
github.com/tiny-systems/module v0.1.150
13+
github.com/tiny-systems/module v0.1.176
1414
)
1515

1616
require (
@@ -135,7 +135,7 @@ require (
135135
github.com/swaggest/jsonschema-go v0.3.70 // indirect
136136
github.com/swaggest/refl v1.3.0 // indirect
137137
github.com/tiny-systems/errorpanic v0.7.1 // indirect
138-
github.com/tiny-systems/platform-api v0.0.10 // indirect
138+
github.com/tiny-systems/platform-api v0.0.13 // indirect
139139
github.com/x448/float16 v0.8.4 // indirect
140140
github.com/xlab/treeprint v1.2.0 // indirect
141141
go.opentelemetry.io/auto/sdk v1.1.0 // indirect

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,11 @@ github.com/tiny-systems/errorpanic v0.7.1 h1:GgbimfhC2wnQ8012SGGxh743ryaJXSSD7bo
364364
github.com/tiny-systems/errorpanic v0.7.1/go.mod h1:AQobicdSB/J3RzN81pTG4dqgcULaEIrEOvNC8TpSgxw=
365365
github.com/tiny-systems/module v0.1.150 h1:pLR8RHd2MmFo9yYEpez1Nx5RfOySI4VkH4qmjWakz5A=
366366
github.com/tiny-systems/module v0.1.150/go.mod h1:l2jQ7Oge37uwpRMOqy0ew2L4gWVb2jCp/wtt/P7LZzo=
367+
github.com/tiny-systems/module v0.1.176 h1:8HL3N1U65mPuODReI9mgUd47jcoMfPh5VJITxEznmeM=
368+
github.com/tiny-systems/module v0.1.176/go.mod h1:2sB+KQxupNhalDZx94pwmthUE4vsQc9NW3fPBPT+3f0=
367369
github.com/tiny-systems/platform-api v0.0.10 h1:XFP0EgeDhjXtm7etBjBJrcih/z0BLXor3pcOjDuk1R8=
368370
github.com/tiny-systems/platform-api v0.0.10/go.mod h1:wZ5N4GR33bkFdryDGJuX2Oni9mtgTuXwdM/jHhLsAWU=
371+
github.com/tiny-systems/platform-api v0.0.13/go.mod h1:wZ5N4GR33bkFdryDGJuX2Oni9mtgTuXwdM/jHhLsAWU=
369372
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
370373
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
371374
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=

release.sh

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Colors for output
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[1;33m'
8+
NC='\033[0m' # No Color
9+
10+
# Function to print colored output
11+
info() {
12+
echo -e "${GREEN}[INFO]${NC} $1"
13+
}
14+
15+
warn() {
16+
echo -e "${YELLOW}[WARN]${NC} $1"
17+
}
18+
19+
error() {
20+
echo -e "${RED}[ERROR]${NC} $1"
21+
exit 1
22+
}
23+
24+
# Function to get the latest git tag
25+
get_latest_tag() {
26+
git fetch --tags 2>/dev/null || true
27+
git tag -l "v*" | sort -V | tail -1
28+
}
29+
30+
# Function to bump version
31+
bump_version() {
32+
local version=$1
33+
local bump_type=$2
34+
35+
# Remove 'v' prefix if present
36+
version=${version#v}
37+
38+
# Split version into components
39+
IFS='.' read -r major minor patch <<< "$version"
40+
41+
case $bump_type in
42+
major)
43+
major=$((major + 1))
44+
minor=0
45+
patch=0
46+
;;
47+
minor)
48+
minor=$((minor + 1))
49+
patch=0
50+
;;
51+
patch)
52+
patch=$((patch + 1))
53+
;;
54+
*)
55+
error "Invalid bump type: $bump_type. Use: major, minor, or patch"
56+
;;
57+
esac
58+
59+
echo "v${major}.${minor}.${patch}"
60+
}
61+
62+
# Function to update SDK to latest version
63+
update_sdk() {
64+
info "Updating github.com/tiny-systems/module to latest version..."
65+
66+
# Get the latest version
67+
go get github.com/tiny-systems/module@latest
68+
69+
# Tidy up
70+
info "Running go mod tidy..."
71+
go mod tidy
72+
73+
# Show the updated version
74+
NEW_VERSION=$(go list -m github.com/tiny-systems/module | awk '{print $2}')
75+
info "SDK updated to: $NEW_VERSION"
76+
77+
# Check if go.mod was modified
78+
if [[ -n $(git status -s go.mod go.sum 2>/dev/null) ]]; then
79+
info "go.mod and/or go.sum have been modified"
80+
read -p "Commit the changes? (Y/n) " -n 1 -r
81+
echo
82+
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
83+
git add go.mod go.sum
84+
git commit -m "update SDK to $NEW_VERSION"
85+
info "Changes committed"
86+
else
87+
warn "Don't forget to commit the changes!"
88+
fi
89+
else
90+
info "No changes to commit (SDK already at latest version)"
91+
fi
92+
}
93+
94+
# Main script
95+
main() {
96+
# Handle 'update' command
97+
if [[ "${1:-}" == "update" ]]; then
98+
update_sdk
99+
exit 0
100+
fi
101+
# Check if git repo
102+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
103+
error "Not a git repository"
104+
fi
105+
106+
# Check for uncommitted changes
107+
if [[ -n $(git status -s) ]]; then
108+
warn "You have uncommitted changes:"
109+
git status -s
110+
read -p "Continue anyway? (Y/n) " -n 1 -r
111+
echo
112+
if [[ $REPLY =~ ^[Nn]$ ]]; then
113+
exit 1
114+
fi
115+
fi
116+
117+
# Get bump type from argument or prompt
118+
BUMP_TYPE=${1:-}
119+
if [[ -z "$BUMP_TYPE" ]]; then
120+
echo "Select version bump type:"
121+
echo " 1) patch (0.1.x -> 0.1.x+1)"
122+
echo " 2) minor (0.x.0 -> 0.x+1.0)"
123+
echo " 3) major (x.0.0 -> x+1.0.0)"
124+
read -p "Enter choice [1-3]: " -n 1 -r choice
125+
echo
126+
case $choice in
127+
1) BUMP_TYPE="patch" ;;
128+
2) BUMP_TYPE="minor" ;;
129+
3) BUMP_TYPE="major" ;;
130+
*) error "Invalid choice" ;;
131+
esac
132+
fi
133+
134+
# Get current version
135+
CURRENT_TAG=$(get_latest_tag)
136+
if [[ -z "$CURRENT_TAG" ]]; then
137+
warn "No existing tags found, starting from v0.0.0"
138+
CURRENT_TAG="v0.0.0"
139+
fi
140+
141+
info "Current version: $CURRENT_TAG"
142+
143+
# Calculate new version
144+
NEW_TAG=$(bump_version "$CURRENT_TAG" "$BUMP_TYPE")
145+
info "New version: $NEW_TAG"
146+
147+
# Ask for commit message
148+
read -p "Commit message (default: 'release $NEW_TAG'): " COMMIT_MSG
149+
COMMIT_MSG=${COMMIT_MSG:-"release $NEW_TAG"}
150+
151+
# Commit any staged changes
152+
if [[ -n $(git diff --cached --name-only) ]]; then
153+
info "Committing changes..."
154+
git commit -m "$COMMIT_MSG"
155+
fi
156+
157+
# Create tag locally first
158+
info "Creating tag $NEW_TAG..."
159+
git tag -a "$NEW_TAG" -m "$COMMIT_MSG"
160+
161+
# Check if there are unpushed commits
162+
PUSH_COMMITS=false
163+
if [[ -n $(git log origin/$(git rev-parse --abbrev-ref HEAD)..HEAD 2>/dev/null) ]]; then
164+
read -p "Push commits to remote? (Y/n) " -n 1 -r
165+
echo
166+
if [[ $REPLY =~ ^[Nn]$ ]]; then
167+
warn "Commits not pushed. Tag will not be pushed either (would point to non-existent commit)."
168+
info "✓ Tag $NEW_TAG created locally (not pushed)"
169+
warn "To push later: git push && git push origin $NEW_TAG"
170+
return
171+
else
172+
info "Pushing commits to remote..."
173+
git push
174+
PUSH_COMMITS=true
175+
fi
176+
fi
177+
178+
# Now ask about pushing the tag
179+
read -p "Push tag to remote? (Y/n) " -n 1 -r
180+
echo
181+
if [[ $REPLY =~ ^[Nn]$ ]]; then
182+
info "✓ Tag $NEW_TAG created locally (not pushed)"
183+
warn "Remember to push with: git push origin $NEW_TAG"
184+
else
185+
info "Pushing tag to remote..."
186+
git push origin "$NEW_TAG"
187+
188+
info "✓ Release $NEW_TAG created and pushed successfully!"
189+
echo ""
190+
info "Tag: $NEW_TAG"
191+
info "You can create a GitHub release at:"
192+
echo " https://github.com/$(git remote get-url origin | sed 's/.*github.com[:/]\(.*\)\.git/\1/')/releases/new?tag=$NEW_TAG"
193+
fi
194+
}
195+
196+
# Run main function
197+
main "$@"

0 commit comments

Comments
 (0)