|
| 1 | +# Version Management Guide |
| 2 | + |
| 3 | +This document explains how version synchronization works across the WrongSecrets project. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The project maintains version consistency between: |
| 8 | +- `pom.xml` (Maven project version) |
| 9 | +- `Dockerfile` (Docker build argument) |
| 10 | +- `Dockerfile.web` (Docker build argument and base image) |
| 11 | + |
| 12 | +## Version Schema |
| 13 | + |
| 14 | +``` |
| 15 | +pom.xml version: 1.12.3B2-SNAPSHOT |
| 16 | +Dockerfile version: 1.12.3B2 |
| 17 | +Dockerfile.web version: 1.12.3B2-no-vault |
| 18 | +``` |
| 19 | + |
| 20 | +## Automated Solutions |
| 21 | + |
| 22 | +### 1. GitHub Actions Integration |
| 23 | + |
| 24 | +All build workflows now automatically extract the version from `pom.xml`: |
| 25 | + |
| 26 | +```yaml |
| 27 | +- name: Extract version from pom.xml |
| 28 | + id: extract-version |
| 29 | + run: | |
| 30 | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 31 | + DOCKER_VERSION=${VERSION%-SNAPSHOT} |
| 32 | + echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT |
| 33 | +
|
| 34 | +- name: Build Docker image |
| 35 | + run: | |
| 36 | + docker build --build-arg argBasedVersion="${{ steps.extract-version.outputs.docker_version }}" -t image . |
| 37 | +``` |
| 38 | +
|
| 39 | +### 2. Version Sync Scripts |
| 40 | +
|
| 41 | +#### Validate Versions |
| 42 | +```bash |
| 43 | +./scripts/validate-versions.sh |
| 44 | +``` |
| 45 | +Checks if all versions are consistent and reports mismatches. |
| 46 | + |
| 47 | +#### Auto-Sync Versions |
| 48 | +```bash |
| 49 | +./scripts/sync-versions.sh |
| 50 | +``` |
| 51 | +Automatically updates Dockerfiles to match `pom.xml` version. |
| 52 | + |
| 53 | +#### Build with Version Sync |
| 54 | +```bash |
| 55 | +./scripts/build-with-version-sync.sh |
| 56 | +``` |
| 57 | +Builds both Docker images with correct versions from `pom.xml`. |
| 58 | + |
| 59 | +### 3. CI/CD Integration |
| 60 | + |
| 61 | +The `version-sync-check.yml` workflow: |
| 62 | +- ✅ Runs on PR/push when version files change |
| 63 | +- ✅ Validates version consistency |
| 64 | +- ✅ Comments on PRs with fix instructions if mismatched |
| 65 | +- ✅ Prevents version drift |
| 66 | + |
| 67 | +## Manual Process |
| 68 | + |
| 69 | +### When Updating Versions |
| 70 | + |
| 71 | +1. **Update pom.xml version**: |
| 72 | + ```xml |
| 73 | + <version>1.13.0-SNAPSHOT</version> |
| 74 | + ``` |
| 75 | + |
| 76 | +2. **Run sync script**: |
| 77 | + ```bash |
| 78 | + ./scripts/sync-versions.sh |
| 79 | + ``` |
| 80 | + |
| 81 | +3. **Verify changes**: |
| 82 | + ```bash |
| 83 | + ./scripts/validate-versions.sh |
| 84 | + ``` |
| 85 | + |
| 86 | +4. **Commit all changes**: |
| 87 | + ```bash |
| 88 | + git add pom.xml Dockerfile Dockerfile.web |
| 89 | + git commit -m "Bump version to 1.13.0" |
| 90 | + ``` |
| 91 | + |
| 92 | +## Workflow Integration |
| 93 | + |
| 94 | +### All Build Workflows Include: |
| 95 | + |
| 96 | +1. **Version Extraction**: Gets version from `pom.xml` |
| 97 | +2. **Dynamic Build Args**: Passes version to Docker build |
| 98 | +3. **Validation**: Ensures JAR file matches expected name |
| 99 | +4. **Logging**: Shows which versions are being used |
| 100 | + |
| 101 | +### Benefits: |
| 102 | + |
| 103 | +- ✅ **Single Source of Truth**: `pom.xml` is the authoritative version |
| 104 | +- ✅ **No Manual Updates**: Dockerfiles auto-sync with Maven version |
| 105 | +- ✅ **CI Validation**: Catches version mismatches early |
| 106 | +- ✅ **Consistent Builds**: Same version used across all environments |
| 107 | + |
| 108 | +## Troubleshooting |
| 109 | + |
| 110 | +### Common Issues: |
| 111 | + |
| 112 | +1. **JAR Not Found**: Version mismatch between build arg and actual JAR name |
| 113 | + - **Solution**: Run `./scripts/sync-versions.sh` |
| 114 | + |
| 115 | +2. **Docker Build Fails**: Hard-coded version in Dockerfile |
| 116 | + - **Solution**: Use `--build-arg argBasedVersion=...` |
| 117 | + |
| 118 | +3. **CI Version Mismatch**: Manual updates to Dockerfiles |
| 119 | + - **Solution**: Let CI extract from `pom.xml` dynamically |
| 120 | + |
| 121 | +### Debug Commands: |
| 122 | + |
| 123 | +```bash |
| 124 | +# Check current versions |
| 125 | +mvn help:evaluate -Dexpression=project.version -q -DforceStdout |
| 126 | +grep "argBasedVersion" Dockerfile Dockerfile.web |
| 127 | + |
| 128 | +# Test build with current version |
| 129 | +VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 130 | +DOCKER_VERSION=${VERSION%-SNAPSHOT} |
| 131 | +docker build --build-arg argBasedVersion="$DOCKER_VERSION" . |
| 132 | +``` |
| 133 | + |
| 134 | +## Best Practices |
| 135 | + |
| 136 | +1. **Always use scripts** for version updates |
| 137 | +2. **Never hard-code versions** in CI workflows |
| 138 | +3. **Run validation** before committing changes |
| 139 | +4. **Update pom.xml first**, then sync other files |
| 140 | +5. **Test builds locally** before pushing |
| 141 | + |
| 142 | +This system ensures version consistency and eliminates manual synchronization errors! |
0 commit comments