|
| 1 | +# Refresh Versions Command |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The `refresh-versions` command updates package version information in existing saidata files by querying package repositories directly, without using LLM services. This provides a fast, cost-free way to keep saidata files synchronized with upstream package versions. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **No LLM costs**: Queries repositories directly |
| 10 | +- **Fast execution**: Typically completes in seconds |
| 11 | +- **Safe updates**: Creates backups before modifying files |
| 12 | +- **Selective updates**: Target specific providers |
| 13 | +- **Check mode**: Preview changes without modifying files |
| 14 | +- **Batch processing**: Update multiple files at once (via shell) |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +### Basic Usage |
| 19 | + |
| 20 | +```bash |
| 21 | +# Refresh all package versions in a saidata file |
| 22 | +saigen refresh-versions nginx.yaml |
| 23 | + |
| 24 | +# Check for updates without modifying the file |
| 25 | +saigen refresh-versions --check-only nginx.yaml |
| 26 | + |
| 27 | +# Refresh specific providers only |
| 28 | +saigen refresh-versions --providers apt,brew nginx.yaml |
| 29 | + |
| 30 | +# Save to a different file |
| 31 | +saigen refresh-versions --output nginx-updated.yaml nginx.yaml |
| 32 | + |
| 33 | +# Skip cache for latest data |
| 34 | +saigen refresh-versions --no-cache nginx.yaml |
| 35 | + |
| 36 | +# Show all packages including unchanged ones |
| 37 | +saigen --verbose refresh-versions --show-unchanged nginx.yaml |
| 38 | +``` |
| 39 | + |
| 40 | +### Options |
| 41 | + |
| 42 | +- `--output, -o PATH`: Output file path (default: overwrite input file) |
| 43 | +- `--providers TEXT`: Target specific providers (e.g., apt, brew, winget) |
| 44 | +- `--backup / --no-backup`: Create backup of original file (default: enabled) |
| 45 | +- `--backup-dir PATH`: Directory for backup files (default: same as input file) |
| 46 | +- `--check-only`: Check for version updates without modifying files |
| 47 | +- `--show-unchanged`: Show packages that are already up-to-date |
| 48 | +- `--use-cache / --no-cache`: Use cached repository data (default: enabled) |
| 49 | + |
| 50 | +### Global Options |
| 51 | + |
| 52 | +- `--verbose, -v`: Enable verbose output |
| 53 | +- `--dry-run`: Show what would be done without executing |
| 54 | + |
| 55 | +## How It Works |
| 56 | + |
| 57 | +1. **Load saidata**: Reads the existing saidata YAML file |
| 58 | +2. **Extract packages**: Collects all packages with version information from: |
| 59 | + - Top-level packages |
| 60 | + - Provider-specific packages |
| 61 | + - Package sources |
| 62 | + - Repository packages |
| 63 | + - Binaries |
| 64 | + - Sources |
| 65 | + - Scripts |
| 66 | +3. **Query repositories**: Searches package repositories for current versions |
| 67 | +4. **Update versions**: Updates version fields in the saidata object |
| 68 | +5. **Save changes**: Writes the updated saidata back to file |
| 69 | + |
| 70 | +## What Gets Updated |
| 71 | + |
| 72 | +The command updates version information in these locations: |
| 73 | + |
| 74 | +- `packages[].version` |
| 75 | +- `providers.<provider>.packages[].version` |
| 76 | +- `providers.<provider>.package_sources[].packages[].version` |
| 77 | +- `providers.<provider>.repositories[].packages[].version` |
| 78 | +- `providers.<provider>.binaries[].version` |
| 79 | +- `providers.<provider>.sources[].version` |
| 80 | +- `providers.<provider>.scripts[].version` |
| 81 | + |
| 82 | +All other fields remain unchanged, preserving manual customizations. |
| 83 | + |
| 84 | +## Examples |
| 85 | + |
| 86 | +### Check for Outdated Versions |
| 87 | + |
| 88 | +```bash |
| 89 | +# Check which packages need updates |
| 90 | +saigen refresh-versions --check-only nginx.yaml |
| 91 | +``` |
| 92 | + |
| 93 | +Output: |
| 94 | +``` |
| 95 | +Check Results for nginx: |
| 96 | + Total packages checked: 5 |
| 97 | + Updates available: 2 |
| 98 | + Already up-to-date: 3 |
| 99 | + Execution time: 1.23s |
| 100 | +
|
| 101 | +Available Updates: |
| 102 | + • apt/nginx: 1.20.1 → 1.24.0 |
| 103 | + • brew/nginx: 1.20.1 → 1.25.3 |
| 104 | +``` |
| 105 | + |
| 106 | +### Update Specific Providers |
| 107 | + |
| 108 | +```bash |
| 109 | +# Only update apt and brew packages |
| 110 | +saigen refresh-versions --providers apt,brew nginx.yaml |
| 111 | +``` |
| 112 | + |
| 113 | +### Batch Update Multiple Files |
| 114 | + |
| 115 | +```bash |
| 116 | +# Update all saidata files in a directory |
| 117 | +for file in saidata/*.yaml; do |
| 118 | + saigen refresh-versions "$file" |
| 119 | +done |
| 120 | +``` |
| 121 | + |
| 122 | +### CI/CD Integration |
| 123 | + |
| 124 | +```bash |
| 125 | +# Check for outdated versions in CI pipeline |
| 126 | +if saigen refresh-versions --check-only nginx.yaml | grep -q "Updates available: [1-9]"; then |
| 127 | + echo "Versions are outdated!" |
| 128 | + exit 1 |
| 129 | +fi |
| 130 | +``` |
| 131 | + |
| 132 | +## Backup Management |
| 133 | + |
| 134 | +By default, the command creates timestamped backups before modifying files: |
| 135 | + |
| 136 | +``` |
| 137 | +nginx.yaml |
| 138 | +nginx.backup.20250410_143022.yaml |
| 139 | +``` |
| 140 | + |
| 141 | +To disable backups: |
| 142 | + |
| 143 | +```bash |
| 144 | +saigen refresh-versions --no-backup nginx.yaml |
| 145 | +``` |
| 146 | + |
| 147 | +To specify a backup directory: |
| 148 | + |
| 149 | +```bash |
| 150 | +saigen refresh-versions --backup-dir ./backups nginx.yaml |
| 151 | +``` |
| 152 | + |
| 153 | +## Repository Cache |
| 154 | + |
| 155 | +The command uses cached repository data by default for faster execution. Cache is stored in: |
| 156 | + |
| 157 | +``` |
| 158 | +~/.saigen/cache/repositories/ |
| 159 | +``` |
| 160 | + |
| 161 | +To force fresh queries: |
| 162 | + |
| 163 | +```bash |
| 164 | +saigen refresh-versions --no-cache nginx.yaml |
| 165 | +``` |
| 166 | + |
| 167 | +## Troubleshooting |
| 168 | + |
| 169 | +### Package Not Found |
| 170 | + |
| 171 | +If a package cannot be found in the repository: |
| 172 | + |
| 173 | +``` |
| 174 | +Warnings: |
| 175 | + ⚠ Could not find version for nginx in apt repository |
| 176 | +``` |
| 177 | + |
| 178 | +This can happen if: |
| 179 | +- The package name doesn't match the repository's naming |
| 180 | +- The repository cache is outdated (try `--no-cache`) |
| 181 | +- The repository is not available |
| 182 | + |
| 183 | +### Version Mismatch |
| 184 | + |
| 185 | +If the command finds a different package: |
| 186 | + |
| 187 | +``` |
| 188 | +Using closest match: nginx-full v1.24.0 |
| 189 | +``` |
| 190 | + |
| 191 | +This indicates the exact package name wasn't found, and a similar package was used instead. Verify the package name is correct. |
| 192 | + |
| 193 | +## Best Practices |
| 194 | + |
| 195 | +1. **Use check-only first**: Always preview changes before applying |
| 196 | +2. **Keep backups enabled**: Allows easy rollback if needed |
| 197 | +3. **Target specific providers**: Faster and more predictable |
| 198 | +4. **Use in CI/CD**: Automate version checking in pipelines |
| 199 | +5. **Combine with validate**: Run validation after updates |
| 200 | + |
| 201 | +```bash |
| 202 | +# Safe update workflow |
| 203 | +saigen refresh-versions --check-only nginx.yaml |
| 204 | +saigen refresh-versions nginx.yaml |
| 205 | +saigen validate nginx.yaml |
| 206 | +``` |
| 207 | + |
| 208 | +## Comparison with Update Command |
| 209 | + |
| 210 | +| Feature | refresh-versions | update | |
| 211 | +|---------|-----------------|--------| |
| 212 | +| LLM usage | No | Yes | |
| 213 | +| Cost | Free | Costs tokens | |
| 214 | +| Speed | Fast (seconds) | Slower (minutes) | |
| 215 | +| Updates | Versions only | All metadata | |
| 216 | +| Use case | Version sync | Full regeneration | |
| 217 | + |
| 218 | +Use `refresh-versions` for routine version updates, and `update` for comprehensive metadata refreshes. |
0 commit comments