Automate release process with Release Please
In this article I will try to explain how to automate the release process of your projects with Release Please and some tools that I'm using with it.
What is Release Please?
From GitHub:
Release Please automates CHANGELOG generation, the creation of GitHub releases, and version bumps for your projects.
It does so by parsing your git history, looking for Conventional Commit messages, and creating release PRs.
It does not handle publication to package managers or handle complex branch management.
In other words it will create a PR with the changes that you made in your project, and it will bump the version of your project based on the changes that you made.
How to use it?
First of all you need to start using Conventional Commit messages, this is a standard for commit messages. It let Release Please know what to add to CHANGELOG and how to bump the version of your project.
I'm using commitlint to enforce this standard in my projects. You can use it with husky or pre-commit to run it before every commit. And also it's good to use it in your CI.
Setup with husky
Install husky. There I will show how to do it with npm
, for other package managers you can check the documentation.
1npx husky-init && npm install
It will:
- Add prepare script to package.json
- Create a sample pre-commit hook that you can edit (by default, npm test will run when you commit)
- Configure Git hooks path
Install commitlint and the conventional config.
1npm install --save-dev @commitlint/{cli,config-conventional}
2
3# Configure commitlint to use conventional config
4echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
Add a commit-msg hook to run commitlint on every commit.
1npx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}'
Setup with pre-commit
If you are using pre-commit you can add this to your .pre-commit-config.yaml
file.
1repos:
2 - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
3 rev: v9.4.0
4 hooks:
5 - id: commitlint
6 stages: [commit-msg]
7 additional_dependencies:
8 - '@commitlint/config-conventional'
Setup with CI
For GitHub Actions you can use this action.
Example of usage. File .github/workflows/commitlint.yml
.
1name: Lint Commit Messages
2on: [push, pull_request]
3
4jobs:
5 commitlint:
6 runs-on: ubuntu-latest
7 steps:
8 - uses: actions/checkout@v3
9 with:
10 fetch-depth: 0
11 - uses: wagoid/commitlint-github-action@v5
Also you can check documentation for more examples.
Setup Release Please
I propose to use release-please-action to automate the release process. It's a GitHub Action that will run Release Please on every push to the main branch.
Example file .github/workflows/release-please.yml
:
1on:
2 push:
3 branches:
4 - main
5
6permissions:
7 contents: write
8 pull-requests: write
9
10name: release-please
11
12jobs:
13 release-please:
14 runs-on: ubuntu-latest
15 steps:
16 - uses: google-github-actions/release-please-action@v3
17 with:
18 release-type: node
19 package-name: release-please-action
Do not forget to update the package-name
with the name of your project and the release-type
with the type of your project. You can check the documentation to find supported release types.
Workflow example
- You create a separate branch for your changes.
- You make your changes and commit them with a conventional commit message. You should use
fix
orfeat
types for your commits to make release happen. - You push your changes to the remote repository.
- You create a PR to merge your changes to the main branch.
- After merging your changes to the main branch, the release-please-action will run and create a PR with the changes that you made and bump the version of your project.
- When you are ready to release your changes you can merge the PR created by release-please-action.
- After merging the PR, release-please-action will create a GitHub release with the changes that you made and the new version of your project.
Conclusion
Release Please is a great tool to automate the release process of your projects. It's easy to setup and use. I hope this article will help you to start using it in your projects.