versions

CLI to increment a project's version and optionally publish release to Github/Gitea

BSD-2-Clause 116 个版本
安装
npm install versions
yarn add versions
pnpm add versions
bun add versions
README

versions

CLI to increment a project's version and optionally publish release to Github/Gitea

Usage

To increment patch version of current project:

npx versions patch package.json

If files are given, at least one must contain the version. With no files, only a commit and tag are created.

Options

usage: versions [options] patch|minor|major|prerelease [files...]

  Options:
    -a, --all             Add all changed files to the commit
    -b, --base <version>  Base version. Default is from latest git tag, package.json, pyproject.toml, or 0.0.0
    -p, --prefix          Prefix version string with a "v" character. Default is none
    -c, --command <cmd>   Run command after files are updated but before git commit and tag
    -d, --date [<date>]   Replace dates in format YYYY-MM-DD with current or given date
    -i, --preid <id>      Prerelease identifier, e.g., alpha, beta, rc
    -m, --message <str>   Custom tag and commit message
    -r, --replace <str>   Additional replacements in the format "s#regexp#replacement#flags"
    -g, --gitless         Do not perform any git action like creating commit and tag
    -D, --dry             Change nothing, just print what would be done
    -R, --release         Create a GitHub or Gitea release with the changelog as body
    -n, --no-push         Skip pushing commit and tag
    -o, --remote <name>   Git remote to push to. Default is "origin"
    -B, --branch <name>   Git branch to push. Default is the current branch
    -V, --verbose         Print verbose output to stderr
    -v, --version         Print the version
    -h, --help            Print this help

  The message and replacement strings accept tokens _VER_, _MAJOR_, _MINOR_, _PATCH_.

  If files are given, at least one must contain the version.

  Examples:
    $ versions patch package.json
    $ versions prerelease --preid=alpha package.json
    $ versions -c 'npm run build' -m 'Release _VER_' minor file.css

Lockfiles

When a package.json with a packageManager pin changes, its lockfile joins the same commit. A package-lock.json also gets the new version, other lockfiles are committed untouched.

Signing commits and tags

To automatically sign commits and tags created by versions with GPG add this to your ~/.gitconfig:

[user]
  signingkey = <keyid>
[commit]
  gpgSign = true
[tag]
  forceSignAnnotated = true
[push]
  gpgSign = if-asked

Pushing

By default, versions pushes the commit and tag to origin after creating them. Pass --no-push to skip the push and keep changes local. Use --remote and --branch to override the target remote and branch.

Changelog

If a CHANGELOG.md is present at the project root with a heading for the new version, its body is used as the commit message, tag annotation, and release body. Heading matching is lenient — # 1.2.3, ## v1.2.3, ## [1.2.3], ## [1.2.3] - 2024-01-15, ## 1.2.3 (YYYY-MM-DD) all work. If the heading has no date or a placeholder (YYYY-MM-DD, xxxx-xx-xx, etc.), it gets rewritten to today's date and included in the commit. With no matching entry, the tool falls back to a git log summary.

Creating releases

When using the --release option, versions will automatically create a GitHub or Gitea release after pushing the tag. The release body will contain the same changelog as the commit message. --release requires the push and is incompatible with --no-push.

The tool will automatically detect whether you're using GitHub or Gitea based on your git remote URL.

API Tokens

VERSIONS_FORGE_TOKENS wins over everything else and is the only way to reach more than one Gitea or Forgejo instance. It holds comma-separated host:token pairs whose host must match the remote exactly, port included, so a ported instance needs an https remote:

export VERSIONS_FORGE_TOKENS="git.example.com:tok_xxx,localhost:3000:tok_yyy"

Otherwise every one of these that is set is tried in order, only ever against github.com:

  • VERSIONS_GITHUB_API_TOKEN
  • GITHUB_API_TOKEN
  • GH_TOKEN
  • GITHUB_TOKEN
  • HOMEBREW_GITHUB_API_TOKEN

gh auth token follows as one more candidate, so a read-only env token cannot lock out a working gh login.

The same for Gitea and Forgejo, only ever against the instance named by GITEA_URL. The names do not say which instance they belong to, so without a matching GITEA_URL they go unused:

  • VERSIONS_GITEA_API_TOKEN
  • GITEA_API_TOKEN
  • GITEA_AUTH_TOKEN
  • GITEA_TOKEN
  • FORGEJO_TOKEN
export GITEA_URL=https://git.example.com
export GITEA_TOKEN=tok_xxx
versions --release patch package.json

CI environments

CI environments usually do incomplete git checkouts without tags. Fetch tags first:

git fetch --tags --force

--release needs no token wired up on GitHub, Gitea or Forgejo Actions. actions/checkout leaves the job token in git config as http.<origin>/.extraheader, and versions reads it back for that host as a last resort, so it is only ever returned to the forge that issued it. Needs permissions: contents: write on GitHub and releases: write on Gitea. A release created with the job token triggers no release workflows.

© silverwind, distributed under BSD licence

版本列表
15.3.1 2026-08-04
15.3.0 2026-08-04
15.2.1 2026-08-03
15.2.0 2026-07-30
15.1.4 2026-07-27
15.1.3 2026-06-30
15.1.2 2026-06-27
15.1.1 2026-06-08
15.1.0 2026-05-28
15.0.4 2026-05-14
15.0.3 2026-05-04
15.0.2 2026-04-28
15.0.1 2026-04-23
15.0.0 2026-04-15
14.3.2 2026-04-13
14.3.1 2026-04-11
14.3.0 2026-04-11
14.2.7 2026-04-10
14.2.6 2026-03-26
14.2.5 2026-03-25
14.2.4 2026-03-18
14.2.2 2026-03-17
14.2.1 2026-03-04
14.2.0 2026-02-21
14.1.3 2026-02-20
14.1.2 2026-02-09
14.1.1 2026-02-09
14.1.0 2026-01-30
14.0.4 2026-01-29
14.0.3 2025-11-19
14.0.2 2025-10-23
14.0.1 2025-10-13
14.0.0 2025-10-13
13.2.3 2025-10-08
13.2.1 2025-09-29
13.2.0 2025-09-29
13.1.3 2025-09-29
13.1.2 2025-09-23
13.1.1 2025-07-31
13.1.0 2025-07-16
13.0.0 2025-07-15
12.1.3 2025-01-23
12.1.2 2024-05-27
12.1.1 2024-05-24
12.1.0 2024-05-23
12.0.2 2024-05-17
12.0.1 2024-02-08
12.0.0 2023-10-20
11.1.0 2023-08-22
11.0.2 2023-08-07
11.0.1 2023-05-24
11.0.0 2023-04-18
10.4.3 2023-04-17
10.4.2 2023-03-07
10.4.1 2022-12-09
10.4.0 2022-12-01
10.3.0 2022-11-28
10.2.4 2022-11-13
10.2.3 2022-11-13
10.2.2 2022-11-13
10.2.1 2022-11-13
10.2.0 2022-11-07
10.1.0 2022-10-25
10.0.5 2022-10-22
10.0.4 2022-10-20
10.0.3 2022-10-20
10.0.2 2022-10-20
10.0.1 2022-10-20
10.0.0 2022-10-19
9.3.4 2022-10-17
9.3.3 2022-09-25
9.3.2 2022-09-20
9.3.1 2022-09-20
9.3.0 2022-06-24
9.2.3 2022-04-06
9.2.2 2022-02-17
9.2.1 2022-01-11
9.2.0 2022-01-11
9.1.1 2021-12-17
9.1.0 2021-10-14
9.0.1 2021-09-21
9.0.0 2021-09-11
8.4.7 2021-04-22
8.4.6 2021-04-22
8.4.5 2021-03-02
8.4.4 2020-12-22
8.4.3 2020-08-13
8.4.2 2020-06-24
8.4.1 2020-06-18
8.4.0 2020-06-03
8.3.1 2020-05-30
8.3.0 2020-05-30
8.2.11 2020-05-30
8.2.10 2020-05-20
8.2.9 2020-05-13
8.2.8 2020-05-08
8.2.7 2020-03-25
8.2.6 2020-03-20
8.2.5 2020-03-13
8.2.4 2020-03-08
8.2.3 2020-03-07
8.2.2 2020-03-07
8.2.1 2020-03-07
8.2.0 2020-03-07
8.1.0 2020-03-01
8.0.4 2020-03-01
8.0.3 2020-03-01
8.0.2 2020-03-01
8.0.1 2020-03-01
8.0.0 2020-03-01
7.0.5 2019-12-15
7.0.4 2019-12-14
7.0.3 2019-11-21
7.0.2 2019-11-19
7.0.1 2019-11-18
7.0.0 2019-11-18