DEV Community

Natig Babayev
Natig Babayev

Posted on

Automating releases of Github Action that depends on another repository

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 submission, 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:

  1. Receive an e-mail about the new release of Detekt.
  2. Update version in Dockerfile and README.md whenever I have free time.
  3. Commit changes.
  4. Create a new tag.
  5. Push changes.
  6. 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 in Dockerfile and README.md
    • Commit changes
    • Create a new tag
    • Create a release branch
    • Push changes
  • 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.

My Workflow


name: Create Release

on:
  schedule:
    - cron: "0 0 * * *"
  workflow_dispatch:

jobs:
  check_release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
      - name: Install dependencies
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          python -m pip install --upgrade pip
          if [ -f .release-manager/requirements.txt ]; then pip install -r .release-manager/requirements.txt; fi
      - name: Run script
        run: |
          python .release-manager/create_release.py

Submission Category:

Maintainer Must-Haves

Yaml File or Link to Code

GitHub logo natiginfo / action-detekt-all

Run detekt for all files

GitHub Action: Detekt All

GitHub Action for running detekt checks to enforce best practices. Detekt is a static code analysis tool for Kotlin.

Version of the action is aligned with detekt versions.

Example usage

name: detekt

on:
  push:
    branches: [ master ]

 jobs:
   detekt:
     runs-on: ubuntu-latest

     steps:
       - name: "checkout"
         uses: actions/checkout@v2

       - name: "detekt"
         uses: natiginfo/action-detekt-all@1.13.1

Usage with CLI parameters

name: detekt

on:
  push:
    branches: [ master ]

 jobs:
   detekt:
     runs-on: ubuntu-latest

     steps:
       - name: "checkout"
         uses: actions/checkout@v2

       - name: "detekt"
         uses: natiginfo/action-detekt-all@1.13.1
         with:
          args: --fail-fast --config detekt.yml

You can check available CLI parameters here

Ending

The purpose of this submission is 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 believe by checking existing actions, you can create workflow that works for your need.

Thanks for reading!

Top comments (0)