Skip to content

Commit d5c48de

Browse files
committed
update module, add release.sh
1 parent 46af52a commit d5c48de

4 files changed

Lines changed: 204 additions & 3 deletions

File tree

components/echo/echo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package echo
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/tiny-systems/module/module"
78
"github.com/tiny-systems/module/registry"
89
)
@@ -35,7 +36,7 @@ func (t *Component) GetInfo() module.ComponentInfo {
3536
}
3637
}
3738

38-
func (t *Component) Handle(ctx context.Context, handler module.Handler, port string, msg interface{}) error {
39+
func (t *Component) Handle(ctx context.Context, handler module.Handler, port string, msg interface{}) any {
3940
if in, ok := msg.(InMessage); ok {
4041
return handler(ctx, OutPort, in.Context)
4142
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/rs/zerolog v1.31.0
99
github.com/spf13/cobra v1.10.1
1010
github.com/spf13/viper v1.19.0
11-
github.com/tiny-systems/module v0.1.150
11+
github.com/tiny-systems/module v0.1.176
1212
)
1313

1414
require (
@@ -134,7 +134,7 @@ require (
134134
github.com/swaggest/jsonschema-go v0.3.70 // indirect
135135
github.com/swaggest/refl v1.3.0 // indirect
136136
github.com/tiny-systems/errorpanic v0.7.1 // indirect
137-
github.com/tiny-systems/platform-api v0.0.10 // indirect
137+
github.com/tiny-systems/platform-api v0.0.13 // indirect
138138
github.com/x448/float16 v0.8.4 // indirect
139139
github.com/xlab/treeprint v1.2.0 // indirect
140140
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
@@ -372,8 +372,11 @@ github.com/tiny-systems/errorpanic v0.7.1 h1:GgbimfhC2wnQ8012SGGxh743ryaJXSSD7bo
372372
github.com/tiny-systems/errorpanic v0.7.1/go.mod h1:AQobicdSB/J3RzN81pTG4dqgcULaEIrEOvNC8TpSgxw=
373373
github.com/tiny-systems/module v0.1.150 h1:pLR8RHd2MmFo9yYEpez1Nx5RfOySI4VkH4qmjWakz5A=
374374
github.com/tiny-systems/module v0.1.150/go.mod h1:l2jQ7Oge37uwpRMOqy0ew2L4gWVb2jCp/wtt/P7LZzo=
375+
github.com/tiny-systems/module v0.1.176 h1:8HL3N1U65mPuODReI9mgUd47jcoMfPh5VJITxEznmeM=
376+
github.com/tiny-systems/module v0.1.176/go.mod h1:2sB+KQxupNhalDZx94pwmthUE4vsQc9NW3fPBPT+3f0=
375377
github.com/tiny-systems/platform-api v0.0.10 h1:XFP0EgeDhjXtm7etBjBJrcih/z0BLXor3pcOjDuk1R8=
376378
github.com/tiny-systems/platform-api v0.0.10/go.mod h1:wZ5N4GR33bkFdryDGJuX2Oni9mtgTuXwdM/jHhLsAWU=
379+
github.com/tiny-systems/platform-api v0.0.13/go.mod h1:wZ5N4GR33bkFdryDGJuX2Oni9mtgTuXwdM/jHhLsAWU=
377380
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
378381
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
379382
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)