|
| 1 | +# Development Guide |
| 2 | + |
| 3 | +This guide covers development workflows, building, testing, and deployment for the FLAC to 16-bit Converter. |
| 4 | + |
| 5 | +## Setting Version During Build |
| 6 | + |
| 7 | +The application version is embedded at build time using Go's `-ldflags` with the `-X` flag. This version is used by the `--self-update` feature to determine if updates are available. |
| 8 | + |
| 9 | +### Method 1: Manual Version Setting |
| 10 | + |
| 11 | +Set a specific version during build: |
| 12 | + |
| 13 | +```bash |
| 14 | +# Set version to v1.2.3 |
| 15 | +go build -ldflags="-X main.version=v1.2.3" -o flac-converter . |
| 16 | + |
| 17 | +# Use environment variable |
| 18 | +VERSION=v1.2.3 go build -ldflags="-X main.version=$VERSION" -o flac-converter . |
| 19 | +``` |
| 20 | + |
| 21 | +### Method 2: Using Git Tags (Recommended) |
| 22 | + |
| 23 | +The Makefile automatically uses git tags for versioning: |
| 24 | + |
| 25 | +```bash |
| 26 | +# Create and push a git tag |
| 27 | +git tag v1.0.0 |
| 28 | +git push origin v1.0.0 |
| 29 | + |
| 30 | +# Build with automatic version detection |
| 31 | +make build |
| 32 | +# or |
| 33 | +go build -ldflags="-X main.version=$(git describe --tags --always --dirty)" -o flac-converter . |
| 34 | +``` |
| 35 | + |
| 36 | +The `git describe` command will output something like: |
| 37 | +- `v1.0.0` (exact tag match) |
| 38 | +- `v1.0.0-1-g1234567` (1 commit after tag) |
| 39 | +- `v1.0.0-dirty` (uncommitted changes) |
| 40 | + |
| 41 | +### Method 3: Using Makefile |
| 42 | + |
| 43 | +The Makefile provides convenient targets: |
| 44 | + |
| 45 | +```bash |
| 46 | +# Build for current platform with git version |
| 47 | +make build |
| 48 | + |
| 49 | +# Build for all platforms |
| 50 | +make build-all |
| 51 | + |
| 52 | +# Clean and rebuild |
| 53 | +make clean && make build |
| 54 | +``` |
| 55 | + |
| 56 | +## Development Workflow |
| 57 | + |
| 58 | +### Prerequisites |
| 59 | + |
| 60 | +- Go 1.25.1 or later |
| 61 | +- Git |
| 62 | +- Make (optional, for convenience) |
| 63 | +- Docker (for containerized testing) |
| 64 | +- golangci-lint (for linting) |
| 65 | + |
| 66 | +### Setting Up Development Environment |
| 67 | + |
| 68 | +```bash |
| 69 | +# Clone the repository |
| 70 | +git clone https://github.com/Ardakilic/flac-to-16bit-converter.git |
| 71 | +cd flac-to-16bit-converter |
| 72 | + |
| 73 | +# Install dependencies |
| 74 | +go mod download |
| 75 | + |
| 76 | +# Run tests |
| 77 | +make test |
| 78 | +# or |
| 79 | +go test -v ./... |
| 80 | + |
| 81 | +# Build for development |
| 82 | +make build |
| 83 | +``` |
| 84 | + |
| 85 | +### Code Quality |
| 86 | + |
| 87 | +```bash |
| 88 | +# Format code |
| 89 | +make fmt |
| 90 | +# or |
| 91 | +go fmt ./... |
| 92 | + |
| 93 | +# Lint code |
| 94 | +make lint |
| 95 | +# or |
| 96 | +golangci-lint run |
| 97 | + |
| 98 | +# Run tests with coverage |
| 99 | +go test -cover ./... |
| 100 | +``` |
| 101 | + |
| 102 | +## Testing |
| 103 | + |
| 104 | +### Running Tests |
| 105 | + |
| 106 | +```bash |
| 107 | +# Run all tests |
| 108 | +go test ./... |
| 109 | + |
| 110 | +# Run tests with verbose output |
| 111 | +go test -v ./... |
| 112 | + |
| 113 | +# Run tests with coverage |
| 114 | +go test -cover ./... |
| 115 | + |
| 116 | +# Generate coverage report |
| 117 | +go test -coverprofile=coverage.out ./... |
| 118 | +go tool cover -html=coverage.out |
| 119 | +``` |
| 120 | + |
| 121 | +### Test Coverage |
| 122 | + |
| 123 | +Current test coverage: ~68% |
| 124 | + |
| 125 | +Key test areas: |
| 126 | +- Version comparison logic |
| 127 | +- Audio file processing |
| 128 | +- Docker integration |
| 129 | +- Self-update functionality |
| 130 | +- Error handling |
| 131 | + |
| 132 | +## Building for Different Platforms |
| 133 | + |
| 134 | +### Single Platform Build |
| 135 | + |
| 136 | +```bash |
| 137 | +# Linux x64 |
| 138 | +GOOS=linux GOARCH=amd64 go build -ldflags="-X main.version=v1.0.0" -o flac-converter-linux-amd64 . |
| 139 | + |
| 140 | +# Windows x64 |
| 141 | +GOOS=windows GOARCH=amd64 go build -ldflags="-X main.version=v1.0.0" -o flac-converter-windows-amd64.exe . |
| 142 | + |
| 143 | +# macOS ARM64 |
| 144 | +GOOS=darwin GOARCH=arm64 go build -ldflags="-X main.version=v1.0.0" -o flac-converter-darwin-arm64 . |
| 145 | + |
| 146 | +# Linux ARM64 |
| 147 | +GOOS=linux GOARCH=arm64 go build -ldflags="-X main.version=v1.0.0" -o flac-converter-linux-arm64 . |
| 148 | +``` |
| 149 | + |
| 150 | +### Cross-Platform Build (Using Makefile) |
| 151 | + |
| 152 | +```bash |
| 153 | +# Build for all supported platforms |
| 154 | +make build-all |
| 155 | + |
| 156 | +# Create distribution packages |
| 157 | +make package |
| 158 | +``` |
| 159 | + |
| 160 | +This creates binaries in the `dist/` directory with proper naming and compression. |
| 161 | + |
| 162 | +## Self-Update Feature |
| 163 | + |
| 164 | +The self-update feature uses the embedded version to: |
| 165 | + |
| 166 | +1. Check current version against GitHub releases |
| 167 | +2. Download platform-specific binaries |
| 168 | +3. Replace the running binary safely |
| 169 | + |
| 170 | +### Version Format |
| 171 | + |
| 172 | +The version should follow semantic versioning: |
| 173 | +- `v1.0.0` - major.minor.patch |
| 174 | +- `v1.0.0-rc.1` - release candidate |
| 175 | +- `v1.0.0-dev` - development version |
| 176 | + |
| 177 | +### Testing Self-Update |
| 178 | + |
| 179 | +```bash |
| 180 | +# Test with development version (skips update) |
| 181 | +go build -ldflags="-X main.version=dev" -o flac-converter . |
| 182 | +./flac-converter --self-update |
| 183 | + |
| 184 | +# Test with specific version |
| 185 | +go build -ldflags="-X main.version=v1.0.0" -o flac-converter . |
| 186 | +./flac-converter --self-update |
| 187 | +``` |
| 188 | + |
| 189 | +## Release Process |
| 190 | + |
| 191 | +### Creating a Release |
| 192 | + |
| 193 | +1. Update version in code/docs if needed |
| 194 | +2. Create and push git tag: |
| 195 | + ```bash |
| 196 | + git tag v1.0.0 |
| 197 | + git push origin v1.0.0 |
| 198 | + ``` |
| 199 | +3. GitHub Actions will automatically build and create release |
| 200 | +4. Update release notes with changes |
| 201 | + |
| 202 | +### Pre-release Builds |
| 203 | + |
| 204 | +For development/testing releases: |
| 205 | + |
| 206 | +```bash |
| 207 | +# Build with pre-release version |
| 208 | +go build -ldflags="-X main.version=v1.0.0-rc.1" -o flac-converter . |
| 209 | + |
| 210 | +# Or use git describe for automatic pre-release detection |
| 211 | +make build # Will include commit hash if not on exact tag |
| 212 | +``` |
| 213 | + |
| 214 | +## Docker Development |
| 215 | + |
| 216 | +### Building Docker Image |
| 217 | + |
| 218 | +```bash |
| 219 | +# Build the Docker image for testing |
| 220 | +docker build -t flac-converter-test . |
| 221 | + |
| 222 | +# Run tests in Docker |
| 223 | +docker run --rm flac-converter-test go test ./... |
| 224 | +``` |
| 225 | + |
| 226 | +### Using Docker for SoX |
| 227 | + |
| 228 | +The application supports using Docker for SoX operations: |
| 229 | + |
| 230 | +```bash |
| 231 | +# Build with Docker support |
| 232 | +./flac-converter /source/dir --use-docker --docker-image ardakilic/sox_ng:latest |
| 233 | +``` |
| 234 | + |
| 235 | +## Debugging |
| 236 | + |
| 237 | +### Enable Debug Output |
| 238 | + |
| 239 | +The application uses standard Go logging. For more verbose output: |
| 240 | + |
| 241 | +```bash |
| 242 | +# Run with debug flags if implemented |
| 243 | +./flac-converter --verbose /source/dir |
| 244 | +``` |
| 245 | + |
| 246 | +### Common Issues |
| 247 | + |
| 248 | +1. **Version not updating**: Ensure you're using `-ldflags="-X main.version=..."` during build |
| 249 | +2. **Self-update fails**: Check network connectivity and GitHub API access |
| 250 | +3. **Cross-platform builds**: Use correct GOOS/GOARCH combinations |
| 251 | +4. **Docker issues**: Ensure Docker is running and accessible |
| 252 | + |
| 253 | +## Contributing |
| 254 | + |
| 255 | +1. Fork the repository |
| 256 | +2. Create a feature branch |
| 257 | +3. Make changes with tests |
| 258 | +4. Ensure all tests pass: `make test` |
| 259 | +5. Format code: `make fmt` |
| 260 | +6. Submit pull request |
| 261 | + |
| 262 | +## CI/CD |
| 263 | + |
| 264 | +The project uses GitHub Actions for: |
| 265 | +- Automated testing on all platforms |
| 266 | +- Cross-platform builds |
| 267 | +- Release creation |
| 268 | +- Code quality checks |
| 269 | + |
| 270 | +Workflow files are in `.github/workflows/`. |
0 commit comments