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
npm
andnpm run
withyarn
in the command to install dependencies and when executing the release script in the workflow.
# npm
npm install --save-dev husky
# yarn
yarn add --dev husky
npx husky init
1. Install commitlint
🔗
# npm
npm install --save-dev @commitlint/{cli,config-conventional}
# yarn
yarn add --dev @commitlint/{cli,config-conventional}
echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg
# npm
npm install --save-dev semantic-release
# yarn
yarn add --dev semantic-release
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
# npm
npm install --save-dev @semantic-release/git @semantic-release/changelog
# yarn
yarn add --dev @semantic-release/git @semantic-release/changelog
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
# npm
npm install --save-dev lint-staged
#yarn
yarn add --dev lint-staged
echo "npx lint-staged" > .husky/pre-commit
# prettier
# npm
npm install --save-dev --save-exact prettier
# yarn
yarn add --dev --exact prettier
# eslint
# npm
npm init @eslint/config@latest
# yarn
yarn create @eslint/config
- see an example file