Skip to content

Commit

Permalink
add version support and release configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
systemshift committed Dec 30, 2024
1 parent ffef3c6 commit a156a2b
Show file tree
Hide file tree
Showing 12 changed files with 690 additions and 16 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release

on:
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78 changes: 78 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- id: memex
main: ./cmd/memex
binary: memex
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.version={{.Version}}

- id: memexd
main: ./cmd/memexd
binary: memexd
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.version={{.Version}}

archives:
- id: memex-archive
builds:
- memex
- memexd
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
format_overrides:
- goos: windows
format: zip
files:
- README.md
- LICENSE
- docs/*

checksum:
name_template: 'checksums.txt'

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- '^ci:'
- Merge pull request
- Merge branch

brews:
- repository:
owner: systemshift
name: homebrew-memex
homepage: "https://github.com/systemshift/memex"
description: "Graph-oriented data management tool"
install: |
bin.install "memex"
bin.install "memexd"
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,39 @@ Memex is a graph-oriented data management tool.

## Installation

### From Pre-built Binaries

Download the latest pre-built binaries for your platform from the [GitHub Releases](https://github.com/systemshift/memex/releases) page.

#### Linux and macOS
```bash
# Download and extract the archive
tar xzf memex_<OS>_<ARCH>.tar.gz

# Move binaries to your PATH
sudo mv memex /usr/local/bin/
sudo mv memexd /usr/local/bin/

# Verify installation
memex --version
memexd --version
```

#### Windows
1. Download the ZIP archive for Windows
2. Extract the contents
3. Add the extracted directory to your PATH
4. Verify installation by running `memex --version` and `memexd --version`

### Using Homebrew (macOS)

```bash
# Install both memex and memexd
brew install systemshift/memex/memex
```

### Build from Source

```bash
# Build the CLI tool
go build -o ~/bin/memex ./cmd/memex
Expand All @@ -40,6 +73,9 @@ memex connect myrepo.mx
# Show repository status
memex status

# Show version information
memex version

# Add a file
memex add document.txt

Expand Down
25 changes: 24 additions & 1 deletion cmd/memex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ import (
"os"
"path/filepath"

"github.com/systemshift/memex/pkg/memex"
"github.com/systemshift/memex/internal/memex"
)

var (
showVersion = flag.Bool("version", false, "Show version information")
)

func printVersion() {
fmt.Println(memex.BuildInfo())
os.Exit(0)
}

func usage() {
fmt.Printf(`Usage: %s <command> [arguments]
Expand All @@ -21,6 +30,7 @@ Built-in Commands:
link <src> <dst> <type> Create a link between nodes
links <id> Show links for a node
status Show repository status
version Show version information
export <path> Export repository to tar archive
import <path> Import repository from tar archive
Expand All @@ -47,6 +57,10 @@ func main() {
flag.Usage = usage
flag.Parse()

if *showVersion {
printVersion()
}

cmds := memex.NewCommands()
defer cmds.Close()

Expand Down Expand Up @@ -138,6 +152,15 @@ func main() {
}
err = cmds.Status()

case "version":
if err := cmds.AutoConnect(); err == nil {
// If connected to a repo, show its version too
err = cmds.ShowVersion()
} else {
// Just show memex version
fmt.Println(memex.BuildInfo())
}

case "export":
if len(args) != 1 {
usage()
Expand Down
36 changes: 36 additions & 0 deletions cmd/memexd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ import (
"net/http"
"os"
"path/filepath"
"strings"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/systemshift/memex/internal/memex"
"github.com/systemshift/memex/internal/memex/core"
"github.com/systemshift/memex/internal/memex/repository"
)

// VersionResponse represents version information
type VersionResponse struct {
Version string `json:"version"`
Commit string `json:"commit"`
BuildDate string `json:"buildDate"`
}

// Server handles HTTP requests and manages the repository
type Server struct {
repo core.Repository
Expand Down Expand Up @@ -51,8 +60,14 @@ func main() {
// Parse command line flags
addr := flag.String("addr", ":3000", "HTTP service address")
repoPath := flag.String("repo", "", "Repository path")
showVersion := flag.Bool("version", false, "Show version information")
flag.Parse()

if *showVersion {
fmt.Println(memex.BuildInfo())
os.Exit(0)
}

if *repoPath == "" {
log.Fatal("Repository path required")
}
Expand Down Expand Up @@ -87,6 +102,7 @@ func main() {
// Routes
r.Get("/", server.handleIndex)
r.Route("/api", func(r chi.Router) {
r.Get("/version", server.handleVersion)
r.Get("/graph", server.handleGraph)
r.Get("/nodes/{id}", server.handleGetNode)
r.Get("/nodes/{id}/content", server.handleGetContent)
Expand Down Expand Up @@ -242,3 +258,23 @@ func (s *Server) handleGetContent(w http.ResponseWriter, r *http.Request) {

w.Write(content)
}

// handleVersion returns version information
func (s *Server) handleVersion(w http.ResponseWriter, r *http.Request) {
info := strings.Split(memex.BuildInfo(), "\n")
version := strings.TrimPrefix(info[0], "Version: ")
commit := strings.TrimPrefix(info[1], "Commit: ")
date := strings.TrimPrefix(info[2], "Build Date: ")

response := VersionResponse{
Version: version,
Commit: commit,
BuildDate: date,
}

w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(response); err != nil {
http.Error(w, fmt.Sprintf("Error encoding response: %v", err), http.StatusInternalServerError)
return
}
}
74 changes: 74 additions & 0 deletions docs/VERSION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Version Compatibility Guide

Memex uses semantic versioning for both the application and repository format to ensure safe upgrades and compatibility.

## Version Types

### Application Version
- The version of the memex binaries (e.g., 1.2.3)
- Follows semantic versioning (MAJOR.MINOR.PATCH)
- Displayed with `memex --version`

### Repository Format Version
- The version of the .mx file format (e.g., 1.0)
- Uses MAJOR.MINOR format
- Stored in repository header
- Checked when opening repositories

## Compatibility Rules

When opening a repository, Memex checks:
1. Repository format version compatibility
2. Records which version of memex created the repository

Version compatibility rules:
- Major version must match exactly (e.g., 1.x can't open 2.x repositories)
- Minor version of the repository must be <= current version
- The version that created a repository is stored in its header

## Version Information

Use `memex version` to check:
- Current memex version
- Repository format version
- Which memex version created the repository

Example output:
```
Memex Version: 1.2.3
Commit: abc123
Build Date: 2024-01-01
Repository Format Version: 1.0
Created by Memex Version: 1.2.0
```

## Version History

### Repository Format Versions

- 1.0: Initial stable format
- Content-addressable storage
- DAG structure
- Transaction log
- Basic metadata

Future versions will maintain backward compatibility within the same major version.

## Upgrading Repositories

When a new version of Memex is released:

1. If only PATCH version changes:
- No action needed
- Full compatibility maintained

2. If MINOR version changes:
- Repository format is compatible
- New features may be available
- No migration needed

3. If MAJOR version changes:
- Repository format may be incompatible
- Migration tool will be provided
- Check release notes for upgrade path
Loading

0 comments on commit a156a2b

Please sign in to comment.