on
Automatically create releases using GitHub Actions and Python
Photo by Franck V. on Unsplash
Performing repetitive tasks is time-consuming and can be tedious. Luckily, we have tools that we can leverage to do repetitive tasks for us and save time. Recently, I decided to automate the release process in one of my repositories. In this article, I will share my journey of automating the release process using GitHub Actions and Python.
The problem
I maintain a repository that depends on new releases of Detekt CLI
. When there is a new version of Detekt CLI
, I receive email and make a new release of my repository whenever I have free time. With this approach, I used to make new releases by following the steps below:
- Receive an e-mail about the new release of Detekt.
- Update version in
Dockerfile
andREADME.md
whenever I have free time. - Commit changes.
- Create a new tag.
- Push changes.
- Publish the release.
Although the timing of new releases is critical, it is clear that the time difference from step 1 to step 2 can vary depending on my situation that might not make users happy. Besides the timing of new releases and keeping the users of my repository happy, personal time is also important which can be spent on more exciting things than just doing some work manually that can be automated.
Solution
As we know the problem and we have the steps written down, we can think of a way to approach this problem. The solution I wanted to make needed the following features:
- Check new releases of
Detekt CLI
every 24 hours. - If the latest release of
Detekt CLI
is different than the latest tag of my repository,- Update the
Detekt CLI
version inDockerfile
andREADME.md
- Commit changes
- Create a new tag
- Create a release branch
- Push changes
- Update the
- When the new release branch is created, create a new pull request.
Creating a new release branch and a new pull request is something that I did not do when I used to make releases manually. I added the aforementioned steps to ensure that I can review changes so that broken code is not merged to the master branch. For checking new releases and running my Python script, I created two workflows where the first workflow runs the script every 24 hours, and the second workflow creates a pull request when a new release branch is created. Besides the workflow which runs the release script every 24 hours, I noticed that workflow_dispatch
trigger in GitHub actions can be used for running a workflow manually.
According to the release history of Detekt
, there are approximately two to three new releases each month. With the simple solution I created by using GitHub Actions and Python, my goal is to save at least 20 to 30 minutes each month. Besides, I can use the solution in other projects that can save a more significant amount of time in total.
Final words
The purpose of this article was to encourage you to leverage existing tools and save time by automating tasks. As you can see, once you write down the steps, automation is easy with the tools you use.
I hope that you have enjoyed this article.
Share on: