Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 114 additions & 4 deletions docs/src/content/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,116 @@ export npm_config_git_tag_version=false
npm version "${CRAFT_NEW_VERSION}"
```

## Automatic Version Bumping

When `minVersion: "2.21.0"` or higher is set and no custom `preReleaseCommand` is defined, Craft automatically bumps version numbers based on your configured publish targets. This eliminates the need for a `scripts/bump-version.sh` script in most cases.

### How It Works

1. Craft examines your configured `targets` in `.craft.yml`
2. For each target that supports version bumping, Craft updates the appropriate project files
3. Targets are processed in the order they appear in your configuration
4. Each target type is only processed once (e.g., multiple npm targets won't bump `package.json` twice)

### Supported Targets

| Target | Detection | Version Bump Method |
| --------- | ----------------------- | ----------------------------------------------------------- |
| `npm` | `package.json` exists | `npm version --no-git-tag-version` (with workspace support) |
| `pypi` | `pyproject.toml` exists | hatch, poetry, setuptools-scm, or direct edit |
| `crates` | `Cargo.toml` exists | `cargo set-version` (requires cargo-edit) |
| `gem` | `*.gemspec` exists | Direct edit of gemspec and `lib/**/version.rb` |
| `pub-dev` | `pubspec.yaml` exists | Direct edit of pubspec.yaml |
| `hex` | `mix.exs` exists | Direct edit of mix.exs |
| `nuget` | `*.csproj` exists | dotnet-setversion or direct XML edit |

### npm Workspace Support

For npm/yarn/pnpm monorepos, Craft automatically detects and bumps versions in all workspace packages:

- **npm 7+**: Uses `npm version --workspaces` to bump all packages at once
- **yarn/pnpm or npm < 7**: Falls back to bumping each non-private package individually
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where's my dear Bun? we can add it later, i think we could just look for Bun lockfiles bun.lockb / bun.lock, add BUN_BIN, USE_BUN env vars, and bun publishsupport.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it supports workspaces too https://bun.com/docs/pm/workspaces


Workspace detection checks for:

- `workspaces` field in root `package.json` (npm/yarn)
- `pnpm-workspace.yaml` (pnpm)

Private packages (`"private": true`) are skipped during workspace version bumping.

### Python (pypi) Detection Priority

For Python projects, Craft detects the build tool and uses the appropriate method:

1. **Hatch** - If `[tool.hatch]` section exists → `hatch version <version>`
2. **Poetry** - If `[tool.poetry]` section exists → `poetry version <version>`
3. **setuptools-scm** - If `[tool.setuptools_scm]` section exists → No-op (version derived from git tags)
4. **Direct edit** - If `[project]` section with `version` field exists → Edit `pyproject.toml` directly

### Enabling Automatic Version Bumping

To enable automatic version bumping, ensure your `.craft.yml` has:

```yaml
minVersion: '2.21.0'
targets:
- name: npm # or pypi, crates, etc.
# ... other targets
```

And either:

- Remove any custom `preReleaseCommand`, or
- Don't define `preReleaseCommand` at all

### Disabling Automatic Version Bumping

To disable automatic version bumping while still using minVersion 2.21.0+:

```yaml
minVersion: '2.21.0'
preReleaseCommand: '' # Explicitly set to empty string
```

Or define a custom script:

```yaml
minVersion: '2.21.0'
preReleaseCommand: bash scripts/my-custom-bump.sh
```

### Error Handling

If automatic version bumping fails:

- **Missing tool**: Craft reports which tool is missing (e.g., "Cannot find 'npm' for version bumping")
- **Command failure**: Craft shows the error from the failed command
- **No supported targets**: Craft warns that no targets support automatic bumping

In all error cases, Craft suggests defining a custom `preReleaseCommand` as a fallback.

### Recovery from Failed Prepare

If version bumping succeeds but `craft prepare` fails mid-way (e.g., during changelog generation or git operations), you may need to clean up manually:

1. **Check the release branch**: If a release branch was created, you can delete it:

```bash
git branch -D release/<version>
```

2. **Revert version changes**: If files were modified but not committed, reset them:

```bash
git checkout -- package.json pyproject.toml Cargo.toml # or whichever files were changed
```

3. **Re-run prepare**: Once the issue is fixed, run `craft prepare` again. Version bumping is idempotent—running it multiple times with the same version is safe.

:::tip
Use `craft prepare --dry-run` first to preview what changes will be made without modifying any files.
:::

## Post-release Command

This command runs after a successful `craft publish`. Default: `bash scripts/post-release.sh`.
Expand Down Expand Up @@ -444,12 +554,12 @@ artifactProvider:
name: github
config:
artifacts:
build: release-artifacts # exact workflow → exact artifact
/^build-.*$/: artifacts # workflow pattern → exact artifact
ci: # exact workflow → multiple artifacts
build: release-artifacts # exact workflow → exact artifact
/^build-.*$/: artifacts # workflow pattern → exact artifact
ci: # exact workflow → multiple artifacts
- /^output-.*$/
- bundle
/^release-.*$/: # workflow pattern → multiple artifacts
/^release-.*$/: # workflow pattern → multiple artifacts
- /^dist-.*$/
- checksums
```
Expand Down
4 changes: 3 additions & 1 deletion docs/src/content/docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ export NUGET_API_TOKEN=abcdefgh

3. **Add `.craft.yml`** to your project with targets and options.

4. **Add a pre-release script** (default: `scripts/bump-version.sh`).
4. **Set up version bumping** (one of):
- **Automatic** (recommended): Set `minVersion: "2.19.0"` and Craft will automatically bump versions based on your targets (npm, pypi, crates, etc.)
- **Custom script**: Add `scripts/bump-version.sh` (or set `preReleaseCommand`)

5. **Configure environment variables** for your targets.

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"pnpm": "10.27.0"
},
"dependencies": {
"ignore": "^7.0.5",
"marked": "^17.0.1",
"p-limit": "^6.2.0",
"semver": "^7.7.3"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading