Skip to content

sonallux/release-script

Repository files navigation

Release script

Build codecov GitHub tag (latest SemVer) GitHub

Release script automates your release process for projects using git. Typically, releases involve a fixed number of steps to be executed in a given order. Most often these steps are always present:

  1. Update the version number and do a git commit
  2. Do a git tag
  3. Update the version number to the next development version and do a git commit
  4. Push the new version to your package manager
  5. Do a git push

Release Script will execute all these steps and can be customized to your needs with preconditions, version update hook and release hook.

Usage

Configuration

Release Script takes an optional configuration object. Following properties are available:

  • push: boolean whether to execute the git push command. Defaults to true.
  • nextDevelopmentVersion: boolean | string whether to update to the next development version after the release. If set to true and a release of version 1.0.0, the next development version will be 1.0.0-0. A string can used to specify the prerelease id (e.g. using 'dev' will result in 1.0.0-dev.0). Defaults to true.
  • tag: boolean | string whether to perform a git tag. A string can be used to specify a prefix for the tag name (e.g. a prefix of 'v' will generate a git tag v1.0.0). Defaults to 'v'.
  • gitSign Whether to sign git commits and tags
  • preconditions Array of precondition hook function.
  • versionHook Array of version update hook function.
  • releaseHook Array of release hook function.

Custom Hooks

The release script can be customized by the following hooks

  • Precondition: Checks that must be valid before performing a release.
  • Version update hook: Update to the new version (e.g. change version field in package.json)
  • Release hook: Perform the actual release (e.g. publish package to npm). This hook should not change any files, use the version update hook instead.

Every hook is a function which gets the current ReleaseContext as the only argument and should return a Promise, that resolves for a successfull execution and rejects for an error. Errors will cause release script to terminate without any special error handling or reverting changes. Therefore extra care must be taken by the user if release script terminates with an error.

Execution order

  1. All precondition hooks
  2. All version update hook with the version to release
  3. git commit (only if previous version hook changed any files)
  4. git tag
  5. All release hooks
  6. All version update hooks with the next development version (optional)
  7. git commit (only if previous version hook changed any files)
  8. git push

ReleaseContext

The ReleaseContext holds any information relevant to the current release. The following properties are available:

  • directory: string The root directory of the git repository
  • version An instance of the SemVer class holding the current version number
  • config the configuration object the release script was started with.
  • git An instance of the Git class holding a reference to the current git repository
  • isNextDevelopmentVersion: boolean This will only be true for the version update hook with the next development version, otherwise it will be false

License

MIT