Add sync-version
This commit is contained in:
27
Makefile
27
Makefile
@ -10,9 +10,17 @@ GO_FILES=$(SOURCE_DIR)/main.go
|
|||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
|
# Sync version from debian/changelog to Go source
|
||||||
|
.PHONY: sync-version
|
||||||
|
sync-version:
|
||||||
|
@echo "Syncing version from debian/changelog..."
|
||||||
|
@VERSION=$$(head -1 debian/changelog | sed 's/.*(\([^)]*\)).*/\1/'); \
|
||||||
|
sed -i "s/const Version = \".*\"/const Version = \"$$VERSION\"/" $(SOURCE_DIR)/main.go; \
|
||||||
|
echo "Version synced: $$VERSION"
|
||||||
|
|
||||||
# Build the Go binary
|
# Build the Go binary
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build: sync-version
|
||||||
@echo "Building $(BINARY_NAME)..."
|
@echo "Building $(BINARY_NAME)..."
|
||||||
cd $(SOURCE_DIR) && go build -o ../$(BUILD_DIR)/$(BINARY_NAME) main.go
|
cd $(SOURCE_DIR) && go build -o ../$(BUILD_DIR)/$(BINARY_NAME) main.go
|
||||||
@echo "Build complete: $(BINARY_NAME)"
|
@echo "Build complete: $(BINARY_NAME)"
|
||||||
@ -38,7 +46,7 @@ fmt:
|
|||||||
|
|
||||||
# Build Debian package
|
# Build Debian package
|
||||||
.PHONY: pkg-deb
|
.PHONY: pkg-deb
|
||||||
pkg-deb:
|
pkg-deb: sync-version build
|
||||||
fakeroot dpkg-buildpackage -us -uc -b
|
fakeroot dpkg-buildpackage -us -uc -b
|
||||||
|
|
||||||
# Clean package artifacts
|
# Clean package artifacts
|
||||||
@ -52,10 +60,11 @@ clean-pkg:
|
|||||||
.PHONY: help
|
.PHONY: help
|
||||||
help:
|
help:
|
||||||
@echo "Available targets:"
|
@echo "Available targets:"
|
||||||
@echo " build - Build the router_backup binary"
|
@echo " build - Build the router_backup binary"
|
||||||
@echo " clean - Remove build artifacts"
|
@echo " clean - Remove build artifacts"
|
||||||
@echo " test - Run tests"
|
@echo " test - Run tests"
|
||||||
@echo " fmt - Format Go code"
|
@echo " fmt - Format Go code"
|
||||||
@echo " pkg-deb - Create Debian package"
|
@echo " sync-version - Sync version from debian/changelog to Go source"
|
||||||
@echo " clean-pkg - Remove package artifacts"
|
@echo " pkg-deb - Create Debian package"
|
||||||
@echo " help - Show this help message"
|
@echo " clean-pkg - Remove package artifacts"
|
||||||
|
@echo " help - Show this help message"
|
||||||
|
@ -15,6 +15,8 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const Version = "1.0.0"
|
||||||
|
|
||||||
// Config structures
|
// Config structures
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Types map[string]DeviceType `yaml:"types"`
|
Types map[string]DeviceType `yaml:"types"`
|
||||||
@ -228,6 +230,8 @@ func main() {
|
|||||||
Short: "SSH Router Backup Tool",
|
Short: "SSH Router Backup Tool",
|
||||||
Long: "Connects to routers via SSH and runs commands, saving output to local files.",
|
Long: "Connects to routers via SSH and runs commands, saving output to local files.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("IPng Networks Router Backup v%s\n", Version)
|
||||||
|
|
||||||
// Load configuration
|
// Load configuration
|
||||||
config, err := loadConfig(configPath)
|
config, err := loadConfig(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
17
src/version_test.go
Normal file
17
src/version_test.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestVersion(t *testing.T) {
|
||||||
|
if Version == "" {
|
||||||
|
t.Error("Version constant should not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that version follows semantic versioning pattern
|
||||||
|
// This is a basic check - could be more sophisticated
|
||||||
|
if len(Version) < 5 { // minimum "1.0.0" format
|
||||||
|
t.Errorf("Version '%s' seems too short for semantic versioning", Version)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user