Skip to content

Commit 653bf5c

Browse files
committed
initial commit
0 parents  commit 653bf5c

File tree

13 files changed

+1240
-0
lines changed

13 files changed

+1240
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/tag-manager

Makefile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Tag Manager Makefile
2+
3+
# Binary name
4+
BINARY_NAME=tag-manager
5+
6+
# Build directory
7+
BUILD_DIR=build
8+
9+
# Go build flags
10+
LDFLAGS=-ldflags "-s -w"
11+
12+
.PHONY: all build clean run list test help
13+
14+
# Default target
15+
all: build
16+
17+
# Build the application
18+
build:
19+
@echo "Building $(BINARY_NAME)..."
20+
@mkdir -p $(BUILD_DIR)
21+
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
22+
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
23+
24+
# Run the application (builds first if needed)
25+
run: build
26+
@echo "Running $(BINARY_NAME)..."
27+
@$(BUILD_DIR)/$(BINARY_NAME) update $(ARGS)
28+
29+
# List discovered packages
30+
list: build
31+
@echo "Discovering Go packages..."
32+
@$(BUILD_DIR)/$(BINARY_NAME) list
33+
34+
# Clean build artifacts
35+
clean:
36+
@echo "Cleaning build artifacts..."
37+
@rm -rf $(BUILD_DIR)
38+
@echo "Clean complete"
39+
40+
# Install dependencies
41+
deps:
42+
@echo "Installing dependencies..."
43+
go mod tidy
44+
go mod download
45+
@echo "Dependencies installed"
46+
47+
# Test the application
48+
test:
49+
@echo "Running tests..."
50+
go test ./...
51+
@echo "Tests complete"
52+
53+
# Show help
54+
help:
55+
@echo "Available targets:"
56+
@echo " build - Build the application"
57+
@echo " run - Build and run the application (update command)"
58+
@echo " list - Build and list discovered packages"
59+
@echo " clean - Clean build artifacts"
60+
@echo " deps - Install dependencies"
61+
@echo " test - Run tests"
62+
@echo " help - Show this help message"
63+
@echo ""
64+
@echo "Usage examples:"
65+
@echo " make run # Interactive tag update"
66+
@echo " make list # List discovered packages"
67+
@echo " make run ARGS=\"\" # Same as make run"

README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Tag Manager
2+
3+
A generic CLI tool for managing version tags across multiple Go repositories.
4+
5+
## Features
6+
7+
- **Generic Package Discovery**: Automatically discovers Go packages across multiple repositories
8+
- **Custom Tag Naming**: Support for custom tag naming conventions via configuration
9+
- **Interactive Setup**: Guided configuration for new packages with sensible defaults
10+
- **Version Management**: Support for major, minor, and patch version updates
11+
- **Configuration Persistence**: Remembers your tag naming preferences
12+
- **Multi-Repository Support**: Works across any number of Go repositories
13+
- **Git Integration**: Automatic tag creation and pushing
14+
15+
## Installation
16+
17+
1. Navigate to the tag-manager directory:
18+
```bash
19+
cd tag-manager
20+
```
21+
22+
2. Install dependencies:
23+
```bash
24+
go mod tidy
25+
```
26+
27+
3. Build the application:
28+
```bash
29+
go build -o tag-manager
30+
```
31+
32+
## Usage
33+
34+
### List discovered packages
35+
36+
```bash
37+
./tag-manager list
38+
```
39+
40+
This command will scan for Go modules in the current directory and its subdirectories, displaying all discovered packages.
41+
42+
### Update a package tag
43+
44+
```bash
45+
./tag-manager update
46+
```
47+
48+
The tool will guide you through the entire process interactively:
49+
1. **Package Discovery**: Automatically scan for Go packages in the current directory and its subdirectories
50+
2. **Package Selection**: Choose from the discovered packages
51+
3. **Configuration Setup**: Configure tag naming convention (first time only)
52+
4. **Version Selection**: Choose version type (major/minor/patch)
53+
5. **Confirmation**: Review and confirm the tag update
54+
55+
### Examples
56+
57+
**First-time setup for a package:**
58+
```bash
59+
./tag-manager update
60+
# 1. Select package from discovered list
61+
# 2. Choose tag format (default or custom)
62+
# 3. Select version type
63+
# 4. Confirm tag creation
64+
```
65+
66+
**Subsequent updates:**
67+
```bash
68+
./tag-manager update
69+
# 1. Select package (configuration remembered)
70+
# 2. Select version type
71+
# 3. Confirm tag creation
72+
```
73+
74+
### Configuration
75+
76+
The tool uses a configuration file (`~/.tag-manager.yaml`) to store package-specific settings:
77+
78+
- **Tag Format**: Custom tag naming conventions per package
79+
- **Repository Mapping**: Links packages to their repositories
80+
- **Default Settings**: Global defaults for new packages
81+
82+
**Default Tag Format**: `{package-name}/v{major}.{minor}.{patch}`
83+
84+
**Custom Format Examples**:
85+
- `{package-name}-v{major}.{minor}.{patch}`
86+
- `v{major}.{minor}.{patch}`
87+
- `{package-name}/{major}.{minor}.{patch}`
88+
89+
### Version Types
90+
91+
- `major`: Increments the major version (e.g., v1.2.3 → v2.0.0)
92+
- `minor`: Increments the minor version (e.g., v1.2.3 → v1.3.0)
93+
- `patch`: Increments the patch version (e.g., v1.2.3 → v1.2.4)
94+
95+
## Using Makefile
96+
97+
You can also use the provided Makefile for easier management:
98+
99+
```bash
100+
# Build the application
101+
make build
102+
103+
# Run the tag manager
104+
make run
105+
106+
# Clean build artifacts
107+
make clean
108+
```
109+
110+
**Note**: For the best interactive experience, run the command directly:
111+
```bash
112+
./tag-manager update
113+
```
114+
115+
# Clean build artifacts
116+
make clean
117+
```
118+
119+
## How it works
120+
121+
1. **Package Discovery**: Scans the current directory and its subdirectories for `go.mod` files to discover Go packages
122+
2. **Package Selection**: User selects from discovered packages
123+
3. **Configuration Check**: Checks if package has custom tag format configuration
124+
4. **Interactive Setup**: For new packages, guides user through tag format configuration
125+
5. **Version Selection**: User chooses version type (major/minor/patch)
126+
6. **Tag Calculation**: Calculates new version based on current tag and selected type
127+
7. **Confirmation**: Shows current and new tags for user confirmation
128+
8. **Git Operations**: Creates and pushes the new git tag
129+
130+
## Tag Format
131+
132+
The tool supports flexible tag formats through configuration:
133+
134+
**Default Format**: `{package-name}/v{major}.{minor}.{patch}`
135+
136+
**Examples**:
137+
- `utils/v1.2.3`
138+
- `authorization/v0.1.0`
139+
- `cache/v2.0.0`
140+
141+
**Custom Formats**:
142+
- `utils-v1.2.3` (using `{package-name}-v{major}.{minor}.{patch}`)
143+
- `v1.2.3` (using `v{major}.{minor}.{patch}`)
144+
- `utils/1.2.3` (using `{package-name}/{major}.{minor}.{patch}`)
145+
146+
## Configuration File
147+
148+
The tool creates a configuration file at `~/.tag-manager.yaml` to store your preferences:
149+
150+
```yaml
151+
packages:
152+
github.com/example/package:
153+
module_path: github.com/example/package
154+
tag_format: "{package-name}/v{major}.{minor}.{patch}"
155+
repository: example-repo
156+
use_default: true
157+
last_updated: "2024-01-01T00:00:00Z"
158+
defaults:
159+
tag_format: "{package-name}/v{major}.{minor}.{patch}"
160+
```

cmd/list.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/fatih/color"
8+
"github.com/gambitier/tag-manager/pkg/discovery"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var listCmd = &cobra.Command{
13+
Use: "list",
14+
Short: "List discovered Go packages",
15+
Long: `List all discovered Go packages across multiple repositories with their configuration status.`,
16+
RunE: runList,
17+
}
18+
19+
func runList(cmd *cobra.Command, args []string) error {
20+
// Discover packages
21+
searchPaths := discovery.GetDefaultSearchPaths()
22+
packages, err := discovery.DiscoverPackages(searchPaths)
23+
if err != nil {
24+
return fmt.Errorf("failed to discover packages: %w", err)
25+
}
26+
27+
if len(packages) == 0 {
28+
color.Red("No Go packages found in the search paths.")
29+
color.Yellow("Searched in: %s", strings.Join(searchPaths, ", "))
30+
return nil
31+
}
32+
33+
color.Cyan("Discovered %d Go packages:", len(packages))
34+
color.White("Search paths: %s", strings.Join(searchPaths, ", "))
35+
color.White("")
36+
37+
for i, pkg := range packages {
38+
color.White("%d. %s", i+1, pkg.ModulePath)
39+
fmt.Printf(" Path: %s\n", pkg.Path)
40+
fmt.Printf(" Package: %s\n", pkg.PackageName)
41+
if pkg.GoVersion != "" {
42+
fmt.Printf(" Go Version: %s\n", pkg.GoVersion)
43+
}
44+
if pkg.GitHubRepo != "" {
45+
fmt.Printf(" GitHub: %s\n", pkg.GitHubRepo)
46+
}
47+
if pkg.LatestTag != "" {
48+
fmt.Printf(" Latest Tag: %s\n", pkg.LatestTag)
49+
} else {
50+
fmt.Printf(" Latest Tag: (no tags found)\n")
51+
}
52+
color.White("")
53+
}
54+
55+
return nil
56+
}

cmd/root.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
var rootCmd = &cobra.Command{
8+
Use: "tag-manager",
9+
Short: "A generic tool for managing tags across Go repositories",
10+
Long: `Tag Manager is a CLI tool that helps manage version tags for Go packages
11+
across multiple repositories. It can discover packages automatically, support
12+
custom tag naming conventions, and provides interactive confirmation before making changes.
13+
14+
The tool will:
15+
- Scan for go.mod files to discover packages
16+
- Support custom tag naming conventions via configuration
17+
- Provide interactive setup for new packages
18+
- Update major, minor, or patch versions with confirmation`,
19+
}
20+
21+
// Execute adds all child commands to the root command and sets flags appropriately.
22+
func Execute() error {
23+
return rootCmd.Execute()
24+
}
25+
26+
func init() {
27+
// Add subcommands
28+
rootCmd.AddCommand(updateCmd)
29+
rootCmd.AddCommand(listCmd)
30+
}

0 commit comments

Comments
 (0)