|
| 1 | +# Contributing to SGS CLI |
| 2 | + |
| 3 | +Thank you for your interest in contributing to SGS CLI! This document provides guidelines and instructions for contributing. |
| 4 | + |
| 5 | +## Development Setup |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +- Go 1.25 or higher |
| 10 | +- Access to a Kubernetes cluster (for testing) |
| 11 | +- Git |
| 12 | + |
| 13 | +### Clone and Build |
| 14 | + |
| 15 | +```bash |
| 16 | +git clone https://github.com/bacchus-snu/sgs-cli.git |
| 17 | +cd sgs-cli |
| 18 | +go build -o bin/sgs ./cmd/sgs |
| 19 | +``` |
| 20 | + |
| 21 | +### Running Tests |
| 22 | + |
| 23 | +```bash |
| 24 | +go test ./... |
| 25 | +``` |
| 26 | + |
| 27 | +### Linting |
| 28 | + |
| 29 | +```bash |
| 30 | +# Install golangci-lint if not already installed |
| 31 | +go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest |
| 32 | + |
| 33 | +# Run linter |
| 34 | +golangci-lint run |
| 35 | +``` |
| 36 | + |
| 37 | +## Project Structure |
| 38 | + |
| 39 | +```text |
| 40 | +sgs-cli/ |
| 41 | +├── cmd/sgs/ # Application entry point |
| 42 | +├── internal/ |
| 43 | +│ ├── cleanup/ # Interrupt handling and cleanup |
| 44 | +│ ├── client/ # Kubernetes client, config, and updates |
| 45 | +│ ├── cmd/ # CLI commands (Cobra) |
| 46 | +│ ├── node/ # Node operations |
| 47 | +│ ├── session/ # Session operations |
| 48 | +│ ├── sgs/ # Shared constants and version |
| 49 | +│ ├── user/ # User identity from OIDC |
| 50 | +│ ├── volume/ # Volume and session management |
| 51 | +│ └── workspace/ # Workspace operations |
| 52 | +└── .github/workflows/ # CI/CD workflows |
| 53 | +``` |
| 54 | + |
| 55 | +## Code Style |
| 56 | + |
| 57 | +- Follow standard Go conventions and idioms |
| 58 | +- Use `gofmt` for formatting |
| 59 | +- Keep functions focused and small |
| 60 | +- Add comments for exported functions and types |
| 61 | +- Error messages should be lowercase and not end with punctuation |
| 62 | + |
| 63 | +### Naming Conventions |
| 64 | + |
| 65 | +- Use camelCase for unexported identifiers |
| 66 | +- Use PascalCase for exported identifiers |
| 67 | +- Keep names concise but descriptive |
| 68 | + |
| 69 | +## Making Changes |
| 70 | + |
| 71 | +### Branch Naming |
| 72 | + |
| 73 | +- `feature/description` - New features |
| 74 | +- `fix/description` - Bug fixes |
| 75 | +- `docs/description` - Documentation updates |
| 76 | +- `refactor/description` - Code refactoring |
| 77 | + |
| 78 | +### Commit Messages |
| 79 | + |
| 80 | +Write clear, concise commit messages: |
| 81 | + |
| 82 | +```text |
| 83 | +feat: add volume copy progress indicator |
| 84 | +
|
| 85 | +- Show bytes transferred during copy |
| 86 | +- Display estimated time remaining |
| 87 | +- Support quiet mode with --quiet flag |
| 88 | +``` |
| 89 | + |
| 90 | +Prefixes: |
| 91 | + |
| 92 | +- `feat:` - New feature |
| 93 | +- `fix:` - Bug fix |
| 94 | +- `docs:` - Documentation |
| 95 | +- `refactor:` - Code refactoring |
| 96 | +- `test:` - Adding tests |
| 97 | +- `chore:` - Maintenance tasks |
| 98 | + |
| 99 | +### Pull Requests |
| 100 | + |
| 101 | +1. Create a feature branch from `main` |
| 102 | +2. Make your changes with clear commits |
| 103 | +3. Ensure tests pass and code is formatted |
| 104 | +4. Submit a PR with a clear description |
| 105 | +5. Address review feedback |
| 106 | + |
| 107 | +## Adding New Commands |
| 108 | + |
| 109 | +1. Create a new file in `internal/cmd/` (e.g., `mycommand.go`) |
| 110 | +2. Define the cobra command |
| 111 | +3. Register it in `init()` or add to parent command |
| 112 | +4. Add tests if applicable |
| 113 | + |
| 114 | +Example: |
| 115 | + |
| 116 | +```go |
| 117 | +package cmd |
| 118 | + |
| 119 | +import ( |
| 120 | + "fmt" |
| 121 | + "github.com/spf13/cobra" |
| 122 | +) |
| 123 | + |
| 124 | +var myCmd = &cobra.Command{ |
| 125 | + Use: "mycommand", |
| 126 | + Short: "Short description", |
| 127 | + Long: `Longer description with examples.`, |
| 128 | + Run: runMyCommand, |
| 129 | +} |
| 130 | + |
| 131 | +func init() { |
| 132 | + rootCmd.AddCommand(myCmd) |
| 133 | +} |
| 134 | + |
| 135 | +func runMyCommand(cmd *cobra.Command, args []string) { |
| 136 | + // Implementation |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +## Modifying Constants |
| 141 | + |
| 142 | +Constants are defined in `internal/sgs/constants.go`. These are hardcoded values used throughout the CLI: |
| 143 | + |
| 144 | +- Label keys for Kubernetes resources |
| 145 | +- Annotation keys |
| 146 | +- Default values (image, storage size) |
| 147 | +- Resource limits |
| 148 | + |
| 149 | +If you need to change these, ensure they match the server-side configuration. |
| 150 | + |
| 151 | +## Version and Releases |
| 152 | + |
| 153 | +### Version Format |
| 154 | + |
| 155 | +We use semantic versioning: `vMAJOR.MINOR.PATCH` |
| 156 | + |
| 157 | +- MAJOR: Breaking changes |
| 158 | +- MINOR: New features (backward compatible) |
| 159 | +- PATCH: Bug fixes |
| 160 | + |
| 161 | +### Creating a Release |
| 162 | + |
| 163 | +1. Update version-related documentation if needed |
| 164 | +1. Create and push a tag: |
| 165 | + |
| 166 | + ```bash |
| 167 | + git tag v1.2.3 |
| 168 | + git push origin v1.2.3 |
| 169 | + ``` |
| 170 | + |
| 171 | +1. GitHub Actions will automatically: |
| 172 | + - Build binaries for all platforms |
| 173 | + - Create a GitHub release |
| 174 | + - Attach binaries to the release |
| 175 | + |
| 176 | +### Building with Version |
| 177 | + |
| 178 | +For local builds with a specific version: |
| 179 | + |
| 180 | +```bash |
| 181 | +go build -ldflags "-X github.com/bacchus-snu/sgs-cli/internal/sgs.Version=v1.2.3" -o bin/sgs ./cmd/sgs |
| 182 | +``` |
| 183 | + |
| 184 | +## Testing |
| 185 | + |
| 186 | +### Manual Testing |
| 187 | + |
| 188 | +Before submitting a PR, test your changes: |
| 189 | + |
| 190 | +```bash |
| 191 | +# Build |
| 192 | +go build -o bin/sgs ./cmd/sgs |
| 193 | + |
| 194 | +# Test basic commands |
| 195 | +bin/sgs version |
| 196 | +bin/sgs --help |
| 197 | +bin/sgs get --help |
| 198 | +``` |
| 199 | + |
| 200 | +### Integration Testing |
| 201 | + |
| 202 | +If you have access to a test cluster: |
| 203 | + |
| 204 | +```bash |
| 205 | +bin/sgs fetch |
| 206 | +bin/sgs set workspace test-workspace |
| 207 | +bin/sgs get nodes |
| 208 | +bin/sgs get volumes |
| 209 | +``` |
| 210 | + |
| 211 | +## Getting Help |
| 212 | + |
| 213 | +- Open an issue for bugs or feature requests |
| 214 | +- Check existing issues before creating new ones |
| 215 | +- Join discussions in pull requests |
| 216 | + |
| 217 | +## License |
| 218 | + |
| 219 | +By contributing, you agree that your contributions will be licensed under the MIT License. |
0 commit comments