Skip to content

Commit 1bc2c3a

Browse files
authored
docs: Document CRAFT_NEW_VERSION and CRAFT_OLD_VERSION for pre-release command (#719)
## Summary Document the `CRAFT_NEW_VERSION` and `CRAFT_OLD_VERSION` environment variables in the pre-release command documentation. Using environment variables is the recommended way to handle version bumping in custom scripts as it is safer and more explicit than relying on positional arguments. ## Changes - Updated `docs/src/content/docs/configuration.md` to include environment variable documentation. - Updated the example script to demonstrate usage of `CRAFT_NEW_VERSION`. - Verified that existing tests in `src/commands/__tests__/prepare.test.ts` already cover the propagation of these environment variables.
1 parent 480439f commit 1bc2c3a

File tree

1 file changed

+47
-39
lines changed

1 file changed

+47
-39
lines changed

docs/src/content/docs/configuration.md

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,28 @@ This command runs on your release branch as part of `craft prepare`. Default: `b
2323
preReleaseCommand: bash scripts/bump-version.sh
2424
```
2525

26+
The command is executed with the following environment variables:
27+
28+
- `CRAFT_OLD_VERSION`: The previous version (or `0.0.0` if no previous version exists)
29+
- `CRAFT_NEW_VERSION`: The new version being released
30+
2631
The script should:
27-
- Accept old and new version as the last two arguments
28-
- Replace version occurrences
32+
33+
- Use these environment variables to perform version replacement
2934
- Not commit changes
3035
- Not change git state
3136

37+
> **Note:** For backward compatibility, the old and new versions are also passed as the last two command-line arguments to the script, but using environment variables is safer and recommended.
38+
3239
Example script:
3340

3441
```bash
3542
#!/bin/bash
3643
set -eux
37-
OLD_VERSION="${1}"
38-
NEW_VERSION="${2}"
3944
45+
# Use CRAFT_NEW_VERSION provided by craft
4046
export npm_config_git_tag_version=false
41-
npm version "${NEW_VERSION}"
47+
npm version "${CRAFT_NEW_VERSION}"
4248
```
4349

4450
## Post-release Command
@@ -94,10 +100,10 @@ Auto mode uses `.github/release.yml` to categorize PRs. This file follows [GitHu
94100

95101
Craft extends GitHub's format with two additional fields:
96102

97-
| Field | Description |
98-
|-------|-------------|
103+
| Field | Description |
104+
| ----------------- | ------------------------------------------------------------------------- |
99105
| `commit_patterns` | Array of regex patterns to match commit/PR titles (in addition to labels) |
100-
| `semver` | Version bump type for auto-versioning: `major`, `minor`, or `patch` |
106+
| `semver` | Version bump type for auto-versioning: `major`, `minor`, or `patch` |
101107

102108
#### Default Configuration
103109

@@ -120,7 +126,7 @@ changelog:
120126
- title: Bug Fixes 🐛
121127
commit_patterns:
122128
- "^(?<type>fix(?:\\((?<scope>[^)]+)\\))?!?:\\s*)"
123-
- "^Revert \""
129+
- '^Revert "'
124130
semver: patch
125131
- title: Documentation 📚
126132
commit_patterns:
@@ -198,12 +204,13 @@ of the PR title. If no such section is present, the PR title is used as usual.
198204
### Changelog Entry
199205

200206
- Add authentication system
201-
- OAuth2 support
202-
- Two-factor authentication
203-
- Session management
207+
- OAuth2 support
208+
- Two-factor authentication
209+
- Session management
204210
```
205211

206212
This will generate:
213+
207214
```markdown
208215
- Add authentication system by @user in [#123](url)
209216
- OAuth2 support
@@ -228,7 +235,7 @@ Changes are automatically grouped by scope (e.g., `feat(api):` groups under "Api
228235
```yaml
229236
changelog:
230237
policy: auto
231-
scopeGrouping: true # default
238+
scopeGrouping: true # default
232239
```
233240
234241
Scope headers are only shown for scopes with more than one entry. Entries without
@@ -262,17 +269,17 @@ This behavior is controlled by named capture groups in `commit_patterns`:
262269
- `(?<type>...)` - The type prefix to strip (includes type, scope, and colon)
263270
- `(?<scope>...)` - Scope to preserve when not under a scope header
264271

265-
| Original Title | Scope Header | Displayed Title |
266-
|----------------|--------------|-----------------|
267-
| `feat(api): add endpoint` | Yes (Api) | `Add endpoint` |
268-
| `feat(api): add endpoint` | No | `(api) Add endpoint` |
269-
| `feat: add endpoint` | N/A | `Add endpoint` |
272+
| Original Title | Scope Header | Displayed Title |
273+
| ------------------------- | ------------ | -------------------- |
274+
| `feat(api): add endpoint` | Yes (Api) | `Add endpoint` |
275+
| `feat(api): add endpoint` | No | `(api) Add endpoint` |
276+
| `feat: add endpoint` | N/A | `Add endpoint` |
270277

271278
To disable stripping, provide custom patterns using non-capturing groups:
272279

273280
```yaml
274281
commit_patterns:
275-
- "^feat(?:\\([^)]+\\))?!?:" # No named groups = no stripping
282+
- "^feat(?:\\([^)]+\\))?!?:" # No named groups = no stripping
276283
```
277284

278285
### Skipping Changelog Entries
@@ -310,29 +317,29 @@ changelog:
310317

311318
### Configuration Options
312319

313-
| Option | Description |
314-
|--------|-------------|
315-
| `changelog` | Path to changelog file (string) OR configuration object |
316-
| `changelog.filePath` | Path to changelog file. Default: `CHANGELOG.md` |
317-
| `changelog.policy` | Mode: `none`, `simple`, or `auto`. Default: `none` |
318-
| `changelog.scopeGrouping` | Enable scope-based grouping. Default: `true` |
320+
| Option | Description |
321+
| ------------------------- | ------------------------------------------------------- |
322+
| `changelog` | Path to changelog file (string) OR configuration object |
323+
| `changelog.filePath` | Path to changelog file. Default: `CHANGELOG.md` |
324+
| `changelog.policy` | Mode: `none`, `simple`, or `auto`. Default: `none` |
325+
| `changelog.scopeGrouping` | Enable scope-based grouping. Default: `true` |
319326

320327
## Versioning
321328

322329
Configure default versioning behavior:
323330

324331
```yaml
325332
versioning:
326-
policy: auto # auto, manual, or calver
333+
policy: auto # auto, manual, or calver
327334
```
328335
329336
### Versioning Policies
330337
331-
| Policy | Description |
332-
|--------|-------------|
333-
| `auto` | Analyze commits to determine version bump (default when using `craft prepare auto`) |
334-
| `manual` | Require explicit version argument |
335-
| `calver` | Use calendar-based versioning |
338+
| Policy | Description |
339+
| -------- | ----------------------------------------------------------------------------------- |
340+
| `auto` | Analyze commits to determine version bump (default when using `craft prepare auto`) |
341+
| `manual` | Require explicit version argument |
342+
| `calver` | Use calendar-based versioning |
336343

337344
### Calendar Versioning (CalVer)
338345

@@ -342,11 +349,12 @@ For projects using calendar-based versions:
342349
versioning:
343350
policy: calver
344351
calver:
345-
format: "%y.%-m" # e.g., 24.12 for December 2024
346-
offset: 14 # Days to look back for date calculation
352+
format: '%y.%-m' # e.g., 24.12 for December 2024
353+
offset: 14 # Days to look back for date calculation
347354
```
348355

349356
Format supports:
357+
350358
- `%y` - 2-digit year
351359
- `%m` - Zero-padded month
352360
- `%-m` - Month without padding
@@ -387,7 +395,7 @@ Configure where to fetch artifacts from:
387395

388396
```yaml
389397
artifactProvider:
390-
name: github # or 'gcs' or 'none'
398+
name: github # or 'gcs' or 'none'
391399
```
392400

393401
## Targets
@@ -410,11 +418,11 @@ See [Target Configurations](./targets/) for details on each target.
410418

411419
These options apply to all targets:
412420

413-
| Option | Description |
414-
|--------|-------------|
415-
| `includeNames` | Regex: only matched files are processed |
416-
| `excludeNames` | Regex: matched files are skipped |
417-
| `id` | Unique ID for the target (use with `-t target[id]`) |
421+
| Option | Description |
422+
| -------------- | --------------------------------------------------- |
423+
| `includeNames` | Regex: only matched files are processed |
424+
| `excludeNames` | Regex: matched files are skipped |
425+
| `id` | Unique ID for the target (use with `-t target[id]`) |
418426

419427
Example:
420428

0 commit comments

Comments
 (0)