automatic-versioning-guide
automatic-versioning-guide copied to clipboard
This is a quick guide on how to implement automatic semantic versioning using husky.js, commitlint, semantic release and github actions.
Automatic Versioning Guide
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
yarnwithnpm runin the command to install dependencies and when executing the release script in the workflow.
Configuration
HuskyJS
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"
}
...
}
Commitlint
1. Install commitlint :link:
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'
Semantic Release
1. Install semantic-release
yarn add semantic-release --dev
2. Install plugins :link:
-
Default plugins
These four plugins are already part of semantic-release and are listed in order of execution. They do not have to be installed separately:
-
Additional plugins
yarn add @semantic-release/git @semantic-release/changelog --dev
3. semantic-release configuration :link:
- Create a .releaserc file, written in YAML, with optional extensions:
.yaml/.yml/.json/.js - :memo: config file example
- edit
package.jsonand addrelease script
// package.json
{
...
"scripts": {
...
"release": "semantic-release"
}
...
}
4. Set up Continuous Integration :link:
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:
- see an example file