|
| 1 | +# Versioning with npm version + Git Tags |
| 2 | + |
| 3 | +This project uses `npm version` with Git tags for version management, similar to Python's setuptools_scm approach. |
| 4 | + |
| 5 | +## How it works |
| 6 | + |
| 7 | +- Version numbers are manually managed using `npm version` commands |
| 8 | +- Versions are based on Git tags (e.g., `v1.0.0`) |
| 9 | +- No automatic version bumping based on commits |
| 10 | +- Releases are triggered by creating and pushing Git tags |
| 11 | + |
| 12 | +## Version Format |
| 13 | + |
| 14 | +- **Semantic versioning**: `MAJOR.MINOR.PATCH` (e.g., `1.0.0`) |
| 15 | +- **Git tags**: `vMAJOR.MINOR.PATCH` (e.g., `v1.0.0`) |
| 16 | + |
| 17 | +## Creating a Release |
| 18 | + |
| 19 | +### 1. Development Phase |
| 20 | +Developers work normally, committing changes to the repository. |
| 21 | + |
| 22 | +### 2. Version Bump (Manual) |
| 23 | +When ready to release, use `npm version` to bump the version: |
| 24 | + |
| 25 | +```bash |
| 26 | +# Patch version (1.0.0 → 1.0.1) |
| 27 | +npm version patch |
| 28 | + |
| 29 | +# Minor version (1.0.0 → 1.1.0) |
| 30 | +npm version minor |
| 31 | + |
| 32 | +# Major version (1.0.0 → 2.0.0) |
| 33 | +npm version major |
| 34 | + |
| 35 | +# Specific version |
| 36 | +npm version 1.2.3 |
| 37 | +``` |
| 38 | + |
| 39 | +### 3. What npm version does |
| 40 | +- Updates `package.json` version field |
| 41 | +- Creates a Git commit with the version change |
| 42 | +- Creates a Git tag (e.g., `v1.0.0`) |
| 43 | +- Pushes both commit and tag to remote |
| 44 | + |
| 45 | +### 4. Automated Release |
| 46 | +GitHub Actions detects the new tag and automatically: |
| 47 | +- Builds the project |
| 48 | +- Runs tests |
| 49 | +- Publishes to npm |
| 50 | +- Creates a GitHub release |
| 51 | + |
| 52 | +## Release Workflow |
| 53 | + |
| 54 | +```bash |
| 55 | +# 1. Ensure all changes are committed |
| 56 | +git add . |
| 57 | +git commit -m "feat: add new feature" |
| 58 | + |
| 59 | +# 2. Bump version (this creates commit + tag) |
| 60 | +npm version patch # or minor/major |
| 61 | + |
| 62 | +# 3. Push changes and tag |
| 63 | +git push origin main |
| 64 | +git push origin --tags |
| 65 | + |
| 66 | +# 4. GitHub Actions automatically publishes |
| 67 | +``` |
| 68 | + |
| 69 | +## Version Types |
| 70 | + |
| 71 | +| Command | When to use | Example | |
| 72 | +|---------|-------------|---------| |
| 73 | +| `npm version patch` | Bug fixes, small changes | `1.0.0` → `1.0.1` | |
| 74 | +| `npm version minor` | New features, backwards compatible | `1.0.0` → `1.1.0` | |
| 75 | +| `npm version major` | Breaking changes | `1.0.0` → `2.0.0` | |
| 76 | + |
| 77 | +## Checking Current Version |
| 78 | + |
| 79 | +```bash |
| 80 | +# From package.json |
| 81 | +npm version |
| 82 | + |
| 83 | +# Or check npm registry |
| 84 | +npm view wavespeed version |
| 85 | + |
| 86 | +# Check latest Git tag |
| 87 | +git describe --tags --abbrev=0 |
| 88 | +``` |
| 89 | + |
| 90 | +## GitHub Actions Workflow |
| 91 | + |
| 92 | +The release process is automated when tags are pushed: |
| 93 | + |
| 94 | +```yaml |
| 95 | +name: Release |
| 96 | +on: |
| 97 | + push: |
| 98 | + tags: |
| 99 | + - 'v*.*.*' |
| 100 | +jobs: |
| 101 | + release: |
| 102 | + runs-on: ubuntu-latest |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + - uses: actions/setup-node@v4 |
| 106 | + - run: npm ci |
| 107 | + - run: npm test |
| 108 | + - run: npm run build |
| 109 | + - run: npm publish |
| 110 | + - run: Create GitHub release |
| 111 | +``` |
| 112 | +
|
| 113 | +## Pre-release Versions |
| 114 | +
|
| 115 | +For beta/rc versions: |
| 116 | +
|
| 117 | +```bash |
| 118 | +npm version 1.0.0-beta.1 |
| 119 | +npm version 1.0.0-rc.1 |
| 120 | +``` |
| 121 | + |
| 122 | +## Best Practices |
| 123 | + |
| 124 | +### When to Release |
| 125 | +- **Patch releases**: Bug fixes, documentation updates, small improvements |
| 126 | +- **Minor releases**: New features that are backwards compatible |
| 127 | +- **Major releases**: Breaking changes, API modifications |
| 128 | + |
| 129 | +### Commit Messages |
| 130 | +While not strictly enforced, descriptive commit messages are recommended: |
| 131 | + |
| 132 | +```bash |
| 133 | +feat: add support for custom timeout options |
| 134 | +fix: resolve issue with prediction polling |
| 135 | +docs: update API reference documentation |
| 136 | +refactor: simplify error handling logic |
| 137 | +``` |
| 138 | + |
| 139 | +### Version Planning |
| 140 | +- Plan version bumps during development |
| 141 | +- Test thoroughly before releasing |
| 142 | +- Consider deprecation warnings for breaking changes |
| 143 | + |
| 144 | +## Troubleshooting |
| 145 | + |
| 146 | +### Common Issues |
| 147 | + |
| 148 | +1. **Tag already exists**: Delete the tag and try again |
| 149 | + ```bash |
| 150 | + git tag -d v1.0.0 |
| 151 | + git push origin :refs/tags/v1.0.0 |
| 152 | + ``` |
| 153 | + |
| 154 | +2. **Version not updated**: Check if package.json was modified correctly |
| 155 | + |
| 156 | +3. **Publish fails**: Verify NPM_TOKEN permissions and package name uniqueness |
| 157 | + |
| 158 | +### Manual Publish (If needed) |
| 159 | + |
| 160 | +```bash |
| 161 | +# Build and test locally |
| 162 | +npm run build |
| 163 | +npm test |
| 164 | + |
| 165 | +# Publish manually |
| 166 | +npm publish |
| 167 | +``` |
| 168 | + |
| 169 | +## Comparison with Python setuptools_scm |
| 170 | + |
| 171 | +| Aspect | npm version + Git tags | setuptools_scm | |
| 172 | +|--------|----------------------|----------------| |
| 173 | +| Version source | package.json | Git tags + commit count | |
| 174 | +| Version format | 1.2.3 | 1.2.3.dev4+g1234567 | |
| 175 | +| Trigger | Manual npm version | Manual git tag | |
| 176 | +| Automation | GitHub Actions on tag | Build-time version detection | |
| 177 | +| Development versions | Not supported | Automatic dev versions | |
| 178 | + |
| 179 | +This approach provides similar manual control as Python's setuptools_scm while leveraging npm's built-in versioning tools. |
0 commit comments