Skip to content

This is a quick guide on how to implement automatic semantic versioning using husky.js, commitlint, semantic release and github actions.

Notifications You must be signed in to change notification settings

robsonnatanael/automatic-versioning-guide

Repository files navigation

Automatic Versioning Guide

Version Stars Issues

About   |   Requirements   |   Configuration   |   Author

About

This is a quick guide on how to implement automatic semantic versioning using husky.js, commitlint, semantic release and github actions.

Requirements

NOTE: If you choose to use npm, replace yarn with npm run in the command to install dependencies and when executing the release script in the workflow.

Configuration

1. Install husky

yarn add husky --dev

2. Enable Git hooks

yarn husky install

3. To automatically have Git hooks enabled after install, edit package.json

// package.json

{
  "private": true, // <- your package is private, you only need postinstall
  ...
  "scripts": {
    ...
    "postinstall": "husky install"
  }
  ...
}

1. Install commitlint 🔗

yarn add @commitlint/cli @commitlint/config-conventional --dev

2. Configure

// commitlint.config.js

module.exports = {
  extends: ["@commitlint/config-conventional"],
};

3. Add hook

yarn husky add .husky/commit-msg 'yarn commitlint --edit $1'

1. Install semantic-release

yarn add semantic-release --dev

2. Install plugins 🔗

yarn add @semantic-release/git @semantic-release/changelog --dev

3. semantic-release configuration 🔗

  • Create a .releaserc file, written in YAML, with optional extensions: .yaml / .yml / .json / .js
  • 📝 config file example
  • edit package.json and add release script
// package.json

{
  ...
  "scripts": {
    ...
    "release": "semantic-release"
  }
  ...
}

4. Set up Continuous Integration 🔗

Create a workflow with Continuous Integration processes to be executed whenever a new change is sent to the main branch, see an example here.

Optional

Run linters against staged git files and don't let errors slip into your code base

1. Install lint-staged

yarn add lint-staged --dev

2. Set up the pre-commit git hook to run lint-staged

yarn husky add .husky/pre-commit 'npx lint-staged'

3. Install some linters, like ESLint and Prettier

4. Configure lint-staged to run linters and other tasks:

About

This is a quick guide on how to implement automatic semantic versioning using husky.js, commitlint, semantic release and github actions.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published