Skip to content

Commit 3a32157

Browse files
authored
chore: add versioning mechanism (#4)
1 parent 2e1340c commit 3a32157

10 files changed

Lines changed: 185 additions & 101 deletions

File tree

.github/workflows/development.yml

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ permissions:
1313
pull-requests: write
1414

1515
jobs:
16-
test:
17-
name: "Unit Tests"
16+
check:
17+
name: "All Checks"
1818
runs-on: ubuntu-latest
1919
timeout-minutes: 10
2020
steps:
@@ -30,48 +30,5 @@ jobs:
3030
- name: "📦 Download dependencies"
3131
run: go mod download
3232

33-
- name: "🔍 Run tests with coverage"
34-
run: make test-cover
35-
36-
lint:
37-
name: "Lint Code"
38-
runs-on: ubuntu-latest
39-
timeout-minutes: 10
40-
steps:
41-
- name: "☁️ Checkout repository"
42-
uses: actions/checkout@v4
43-
44-
- name: "🔧 Setup Go"
45-
uses: actions/setup-go@v5
46-
with:
47-
go-version: '1.25'
48-
cache: true
49-
50-
- name: "📦 Download dependencies"
51-
run: go mod download
52-
53-
- name: "🔍 Check code formatting"
54-
run: make fmt-check
55-
56-
- name: "🔍 Run linter"
57-
run: make lint
58-
59-
build:
60-
name: "Build Check"
61-
runs-on: ubuntu-latest
62-
timeout-minutes: 10
63-
steps:
64-
- name: "☁️ Checkout repository"
65-
uses: actions/checkout@v4
66-
67-
- name: "🔧 Setup Go"
68-
uses: actions/setup-go@v5
69-
with:
70-
go-version: '1.25'
71-
cache: true
72-
73-
- name: "📦 Download dependencies"
74-
run: go mod download
75-
76-
- name: "🔨 Build all packages"
77-
run: make build
33+
- name: "🔍 Run all checks"
34+
run: make check

.github/workflows/release.yml

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,54 @@ jobs:
1818
with:
1919
fetch-depth: 0
2020

21-
- name: "🔍 Extract version from branch name"
22-
id: extract-version
23-
run: ./scripts/extract-version.sh "${{ github.event.pull_request.head.ref }}"
21+
- name: "🔍 Check if version changed"
22+
id: version-check
23+
run: |
24+
if [ ! -f .versionrc ]; then
25+
echo "version_changed=false" >> $GITHUB_OUTPUT
26+
echo "❌ .versionrc file not found"
27+
exit 0
28+
fi
29+
30+
VERSION=$(cat .versionrc | tr -d '[:space:]')
31+
echo "current_version=$VERSION" >> $GITHUB_OUTPUT
32+
33+
# Check if this version tag already exists
34+
if git tag | grep -q "^v$VERSION$"; then
35+
echo "version_changed=false" >> $GITHUB_OUTPUT
36+
echo "❌ Version v$VERSION already exists"
37+
else
38+
echo "version_changed=true" >> $GITHUB_OUTPUT
39+
echo "✅ New version detected: v$VERSION"
40+
fi
2441
2542
- name: "🔧 Setup Go"
26-
if: steps.extract-version.outputs.should_release == 'true'
43+
if: steps.version-check.outputs.version_changed == 'true'
2744
uses: actions/setup-go@v5
2845
with:
2946
go-version: '1.25'
3047
cache: true
3148

3249
- name: "📦 Download dependencies"
33-
if: steps.extract-version.outputs.should_release == 'true'
50+
if: steps.version-check.outputs.version_changed == 'true'
3451
run: go mod download
3552

3653
- name: "🔍 Run tests before release"
37-
if: steps.extract-version.outputs.should_release == 'true'
54+
if: steps.version-check.outputs.version_changed == 'true'
3855
run: make test-cover
3956

4057
- name: "🏷️ Create and push tag"
41-
if: steps.extract-version.outputs.should_release == 'true'
58+
if: steps.version-check.outputs.version_changed == 'true'
4259
run: |
43-
VERSION="${{ steps.extract-version.outputs.version }}"
60+
VERSION="v${{ steps.version-check.outputs.current_version }}"
4461
git config user.name "github-actions[bot]"
4562
git config user.email "github-actions[bot]@users.noreply.github.com"
4663
git tag -a "$VERSION" -m "Release $VERSION"
4764
git push origin "$VERSION"
4865
echo "Created and pushed tag: $VERSION"
4966
5067
- name: "🚀 Run GoReleaser"
51-
if: steps.extract-version.outputs.should_release == 'true'
68+
if: steps.version-check.outputs.version_changed == 'true'
5269
uses: goreleaser/goreleaser-action@v6
5370
with:
5471
distribution: goreleaser

.versionrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

CONTRIBUTING.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,60 @@ and `go vet` for static analysis. Follow standard Go conventions:
231231
By contributing your code to the `Tap30/*` GitHub repositories, you agree to
232232
license your contribution under the
233233
[MIT license](https://github.com/Tap30/ripple-go/blob/main/LICENSE).
234+
## Release Process
235+
236+
### Versioning
237+
238+
This project uses a `.versionrc` file to manage versions. The version format follows [Semantic Versioning](https://semver.org/).
239+
240+
#### Making a Release
241+
242+
1. **Create a new branch** for the version update:
243+
```bash
244+
git checkout -b release/1.2.3
245+
```
246+
247+
2. **Update the version** in `.versionrc`:
248+
```bash
249+
echo "1.2.3" > .versionrc
250+
```
251+
252+
3. **Sync the version** to Go code:
253+
```bash
254+
make version-sync
255+
```
256+
257+
4. **Verify version consistency**:
258+
```bash
259+
make version-check
260+
```
261+
262+
5. **Commit and push** the changes:
263+
```bash
264+
git add .versionrc version.go
265+
git commit -m "chore: bump version to 1.2.3"
266+
git push origin release/1.2.3
267+
```
268+
269+
6. **Create a Pull Request** to main branch
270+
271+
7. **Merge the PR**: GitHub Actions will automatically create a release tag and GitHub release when the PR is merged to main (only if `.versionrc` contains a new version).
272+
273+
#### Version Guidelines
274+
275+
- **Patch** (x.x.X): Bug fixes, documentation updates
276+
- **Minor** (x.X.x): New features, backward compatible changes
277+
- **Major** (X.x.x): Breaking changes, API changes
278+
279+
#### Development Commands
280+
281+
```bash
282+
# Sync version from .versionrc to version.go
283+
make version-sync
284+
285+
# Check if versions are consistent
286+
make version-check
287+
288+
# Test release configuration
289+
make release-test
290+
```

Makefile

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,28 @@ build:
3434
$(GO) build ./...
3535

3636
# CI checks (same as GitHub Actions)
37-
check: fmt-check lint test build
37+
check: fmt-check lint test build version-check
3838
@echo "All checks passed!"
3939

4040
# Release management
41+
version-sync:
42+
@echo "Syncing version between .versionrc and version.go..."
43+
./scripts/sync-version.sh
44+
45+
version-check:
46+
@echo "Checking version consistency..."
47+
@VERSION_RC=$$(cat .versionrc | tr -d '[:space:]'); \
48+
VERSION_GO=$$(grep 'const Version' version.go | sed 's/.*"\(.*\)".*/\1/'); \
49+
if [ "$$VERSION_RC" != "$$VERSION_GO" ]; then \
50+
echo "❌ Version mismatch:"; \
51+
echo " .versionrc: $$VERSION_RC"; \
52+
echo " version.go: $$VERSION_GO"; \
53+
echo "Run 'make version-sync' to fix"; \
54+
exit 1; \
55+
else \
56+
echo "✅ Version consistent: $$VERSION_RC"; \
57+
fi
58+
4159
release-test:
4260
@echo "Testing release configuration..."
4361
goreleaser check
@@ -76,10 +94,14 @@ help:
7694
@echo "Building:"
7795
@echo " make build - Build all packages"
7896
@echo ""
97+
@echo "Release Management:"
98+
@echo " make version-sync - Sync version from .versionrc to version.go"
99+
@echo " make version-check - Check version consistency"
100+
@echo " make release-test - Test release configuration"
101+
@echo " make release - Create actual release"
102+
@echo ""
79103
@echo "CI/CD:"
80-
@echo " make check - Run all CI checks (fmt, lint, test, build)"
81-
@echo " make release-test - Test release configuration"
82-
@echo " make release - Create actual release"
104+
@echo " make check - Run all CI checks (fmt, lint, test, build, version)"
83105
@echo ""
84106
@echo "Development:"
85107
@echo " make dev-deps - Install development dependencies"

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ for browsers.
3232
## Installation
3333

3434
```bash
35-
go get github.com/Tap30/ripple-go
35+
go get github.com/Tap30/ripple-go@latest
36+
```
37+
38+
Or install a specific version:
39+
40+
```bash
41+
go get github.com/Tap30/ripple-go@v0.0.1
3642
```
3743

3844
## Quick Start

scripts/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Scripts
2+
3+
## sync-version.sh
4+
5+
Synchronizes the version from `.versionrc` to `version.go`.
6+
7+
**Usage:**
8+
```bash
9+
./scripts/sync-version.sh
10+
```
11+
12+
**What it does:**
13+
1. Reads version from `.versionrc`
14+
2. Validates semantic version format (x.x.x or x.x.x-suffix)
15+
3. Updates `version.go` with the new version constant
16+
4. Reports the changes
17+
18+
**Makefile integration:**
19+
```bash
20+
make version-sync # Run the sync script
21+
make version-check # Verify versions are consistent
22+
```

scripts/extract-version.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

scripts/sync-version.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Sync version between .versionrc and version.go
4+
# Usage: ./scripts/sync-version.sh
5+
6+
set -e
7+
8+
if [ ! -f .versionrc ]; then
9+
echo "❌ .versionrc file not found"
10+
exit 1
11+
fi
12+
13+
VERSION=$(cat .versionrc | tr -d '[:space:]')
14+
15+
if [ -z "$VERSION" ]; then
16+
echo "❌ Version is empty in .versionrc"
17+
exit 1
18+
fi
19+
20+
# Validate semantic version format
21+
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
22+
echo "❌ Invalid version format: $VERSION"
23+
echo "Expected format: x.x.x or x.x.x-suffix"
24+
exit 1
25+
fi
26+
27+
# Update version.go
28+
cat > version.go << EOF
29+
package ripple
30+
31+
// Version represents the current version of the Ripple Go SDK
32+
const Version = "$VERSION"
33+
EOF
34+
35+
echo "✅ Version synced: $VERSION"
36+
echo "Updated files:"
37+
echo " - .versionrc: $VERSION"
38+
echo " - version.go: const Version = \"$VERSION\""

version.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package ripple
2+
3+
// Version represents the current version of the Ripple Go SDK
4+
const Version = "0.0.1"

0 commit comments

Comments
 (0)