Skip to content

Commit 3808d05

Browse files
committed
Add make bump and make sync-api-version for release automation
- scripts/bump-version.sh: updates all 8 SDK version locations + lockfile - scripts/sync-api-version.sh: reads openapi.json info.version, updates API_VERSION constants in all 5 SDKs - Both scripts use portable sed (temp file, no -i flag) for Linux compat - make sync-api-version hooked into smithy-build for automatic sync - make sync-api-version-check wired into make check to catch drift - make bump VERSION=x.y.z validates strict semver format
1 parent d3bb9e9 commit 3808d05

File tree

3 files changed

+146
-3
lines changed

3 files changed

+146
-3
lines changed

Makefile

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Orchestrates both Smithy spec and Go SDK
44

5-
.PHONY: all check clean help provenance-sync provenance-check sync-status
5+
.PHONY: all check clean help provenance-sync provenance-check sync-status bump sync-api-version sync-api-version-check
66

77
# Default: run all checks
88
all: check
@@ -23,14 +23,15 @@ smithy-mapper:
2323
@echo "==> Building Smithy OpenAPI mapper..."
2424
cd spec/smithy-bare-arrays && ./gradlew publishToMavenLocal --quiet
2525

26-
# Build OpenAPI from Smithy (also regenerates behavior model)
26+
# Build OpenAPI from Smithy (also regenerates behavior model + syncs API version)
2727
smithy-build: behavior-model smithy-mapper
2828
@echo "==> Building OpenAPI from Smithy..."
2929
cd spec && smithy build
3030
cp spec/build/smithy/openapi/openapi/Basecamp.openapi.json openapi.json
3131
@echo "==> Post-processing OpenAPI for Go types..."
3232
./scripts/enhance-openapi-go-types.sh
3333
@echo "Updated openapi.json"
34+
@$(MAKE) sync-api-version
3435

3536
# Check that openapi.json is up to date
3637
smithy-check: smithy-validate smithy-mapper
@@ -120,6 +121,34 @@ sync-status:
120121
--jq '[.files[] | select(.filename | startswith("app/controllers/"))] | if length == 0 then " (no changes in app/controllers/)" else .[] | " " + .status[:1] + " " + .filename end'; \
121122
fi
122123

124+
#------------------------------------------------------------------------------
125+
# Version management
126+
#------------------------------------------------------------------------------
127+
128+
# Bump SDK version across all languages: make bump VERSION=x.y.z
129+
bump:
130+
ifndef VERSION
131+
$(error VERSION is required. Usage: make bump VERSION=x.y.z)
132+
endif
133+
@./scripts/bump-version.sh $(VERSION)
134+
135+
# Sync API_VERSION constants from openapi.json info.version
136+
sync-api-version:
137+
@./scripts/sync-api-version.sh
138+
139+
# Check that API_VERSION constants match openapi.json info.version
140+
sync-api-version-check:
141+
@echo "==> Checking API version freshness..."
142+
@API_VER=$$(jq -r '.info.version' openapi.json) && \
143+
ok=true && \
144+
grep -q "const APIVersion = \"$$API_VER\"" go/pkg/basecamp/version.go || ok=false && \
145+
grep -q "export const API_VERSION = \"$$API_VER\"" typescript/src/client.ts || ok=false && \
146+
grep -q "API_VERSION = \"$$API_VER\"" ruby/lib/basecamp/version.rb || ok=false && \
147+
grep -q "const val API_VERSION = \"$$API_VER\"" kotlin/sdk/src/commonMain/kotlin/com/basecamp/sdk/BasecampConfig.kt || ok=false && \
148+
grep -q "public static let apiVersion = \"$$API_VER\"" swift/Sources/Basecamp/BasecampConfig.swift || ok=false && \
149+
if [ "$$ok" = false ]; then echo "ERROR: API_VERSION constants are out of date. Run 'make sync-api-version'" && exit 1; fi
150+
@echo "API version constants are up to date"
151+
123152
#------------------------------------------------------------------------------
124153
# Go SDK targets (delegates to go/Makefile)
125154
#------------------------------------------------------------------------------
@@ -344,7 +373,7 @@ swift-clean:
344373
#------------------------------------------------------------------------------
345374

346375
# Run all checks (Smithy + Go + TypeScript + Ruby + Kotlin + Swift + Behavior Model + Conformance + Provenance)
347-
check: smithy-check behavior-model-check provenance-check go-check-drift kt-check-drift go-check ts-check rb-check kt-check swift-check conformance
376+
check: smithy-check behavior-model-check provenance-check sync-api-version-check go-check-drift kt-check-drift go-check ts-check rb-check kt-check swift-check conformance
348377
@echo "==> All checks passed"
349378

350379
# Clean all build artifacts
@@ -422,6 +451,11 @@ help:
422451
@echo " provenance-check Verify Go embedded provenance is up to date"
423452
@echo " sync-status Show upstream changes since last spec sync"
424453
@echo ""
454+
@echo "Version:"
455+
@echo " bump VERSION=x.y.z Bump SDK version across all languages"
456+
@echo " sync-api-version Sync API_VERSION from openapi.json"
457+
@echo " sync-api-version-check Verify API_VERSION constants are up to date"
458+
@echo ""
425459
@echo "Combined:"
426460
@echo " check Run all checks (Smithy + Go + TypeScript + Ruby + Swift + Conformance + Provenance)"
427461
@echo " clean Remove all build artifacts"

scripts/bump-version.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
# Bumps SDK version across all language implementations.
3+
# Usage: scripts/bump-version.sh <version>
4+
# Example: scripts/bump-version.sh 0.3.0
5+
set -euo pipefail
6+
7+
VERSION="${1:-}"
8+
if [ -z "$VERSION" ]; then
9+
echo "Usage: $0 <version>" >&2
10+
echo "Example: $0 0.3.0" >&2
11+
exit 1
12+
fi
13+
14+
# Validate semver format (strict)
15+
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
16+
echo "ERROR: Version must be semver (e.g., 0.3.0)" >&2
17+
exit 1
18+
fi
19+
20+
# Portable in-place sed: use temp file instead of -i flag
21+
sedi() {
22+
local expr="$1" file="$2"
23+
local tmp
24+
tmp=$(mktemp)
25+
sed "$expr" "$file" > "$tmp" && mv "$tmp" "$file"
26+
}
27+
28+
echo "Bumping version to: $VERSION"
29+
30+
# 1. Root package.json
31+
sedi "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" package.json
32+
33+
# 2. Go
34+
sedi "s/^const Version = \".*\"/const Version = \"$VERSION\"/" go/pkg/basecamp/version.go
35+
36+
# 3. TypeScript package.json
37+
sedi "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" typescript/package.json
38+
39+
# 4. TypeScript client.ts
40+
sedi "s/^export const VERSION = \".*\"/export const VERSION = \"$VERSION\"/" typescript/src/client.ts
41+
42+
# 5. Ruby
43+
sedi "s/^ VERSION = \".*\"/ VERSION = \"$VERSION\"/" ruby/lib/basecamp/version.rb
44+
45+
# 6. Kotlin build.gradle.kts
46+
sedi "s/^version = \".*\"/version = \"$VERSION\"/" kotlin/sdk/build.gradle.kts
47+
48+
# 7. Kotlin BasecampConfig.kt
49+
sedi "s/const val VERSION = \".*\"/const val VERSION = \"$VERSION\"/" \
50+
kotlin/sdk/src/commonMain/kotlin/com/basecamp/sdk/BasecampConfig.kt
51+
52+
# 8. Swift BasecampConfig.swift
53+
sedi "s/public static let version = \".*\"/public static let version = \"$VERSION\"/" \
54+
swift/Sources/Basecamp/BasecampConfig.swift
55+
56+
# Sync TypeScript lockfile
57+
echo "Syncing TypeScript lockfile..."
58+
(cd typescript && npm install --package-lock-only --ignore-scripts 2>/dev/null)
59+
60+
echo "Done. Bumped 8 files to $VERSION."

scripts/sync-api-version.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# Syncs API_VERSION constants across all SDKs from openapi.json info.version.
3+
# Usage: scripts/sync-api-version.sh [openapi.json]
4+
set -euo pipefail
5+
6+
OPENAPI="${1:-openapi.json}"
7+
8+
if ! command -v jq &>/dev/null; then
9+
echo "ERROR: jq is required" >&2
10+
exit 1
11+
fi
12+
13+
API_VERSION=$(jq -r '.info.version' "$OPENAPI")
14+
if [ -z "$API_VERSION" ] || [ "$API_VERSION" = "null" ]; then
15+
echo "ERROR: Could not read info.version from $OPENAPI" >&2
16+
exit 1
17+
fi
18+
19+
# Portable in-place sed: use temp file instead of -i flag
20+
sedi() {
21+
local expr="$1" file="$2"
22+
local tmp
23+
tmp=$(mktemp)
24+
sed "$expr" "$file" > "$tmp" && mv "$tmp" "$file"
25+
}
26+
27+
echo "Syncing API version: $API_VERSION"
28+
29+
# Go
30+
sedi "s/^const APIVersion = \".*\"/const APIVersion = \"$API_VERSION\"/" \
31+
go/pkg/basecamp/version.go
32+
33+
# TypeScript
34+
sedi "s/^export const API_VERSION = \".*\"/export const API_VERSION = \"$API_VERSION\"/" \
35+
typescript/src/client.ts
36+
37+
# Ruby
38+
sedi "s/^ API_VERSION = \".*\"/ API_VERSION = \"$API_VERSION\"/" \
39+
ruby/lib/basecamp/version.rb
40+
41+
# Kotlin
42+
sedi "s/const val API_VERSION = \".*\"/const val API_VERSION = \"$API_VERSION\"/" \
43+
kotlin/sdk/src/commonMain/kotlin/com/basecamp/sdk/BasecampConfig.kt
44+
45+
# Swift
46+
sedi "s/public static let apiVersion = \".*\"/public static let apiVersion = \"$API_VERSION\"/" \
47+
swift/Sources/Basecamp/BasecampConfig.swift
48+
49+
echo "Done."

0 commit comments

Comments
 (0)