About | Requirements | Configuration | Author
This is a quick guide on how to implement automatic semantic versioning using husky.js, commitlint, semantic release and github actions.
NOTE: If you choose to use npm, replace
yarn
withnpm run
in the command to install dependencies and when executing the release script in the workflow.
yarn add husky --dev
yarn husky install
// 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
// commitlint.config.js
module.exports = {
extends: ["@commitlint/config-conventional"],
};
yarn husky add .husky/commit-msg 'yarn commitlint --edit $1'
yarn add semantic-release --dev
2. Install plugins
🔗
-
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
🔗
- Create a .releaserc file, written in YAML, with optional extensions:
.yaml
/.yml
/.json
/.js
- 📝 config file example
- edit
package.json
and addrelease 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.
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
yarn husky add .husky/pre-commit 'npx lint-staged'
- see an example file