Automating releases of Github Action that depends on another repository
Tags: actionshackathon, github, opensource
Published: 2020-09-16 07:33:55

---
title: Automating releases of Github Action that depends on another repository
published: true
description: My submission to the GitHub Actions x DEV Hackathon!
tags: actionshackathon, github, opensource
---

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](https://github.com/natiginfo/action-detekt-all). In this submission, I will share my journey of automating the release process using [GitHub Actions](https://github.com/features/actions) and [Python](https://www.python.org/).

### The problem

I maintain a [repository](https://github.com/natiginfo/action-detekt-all) 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](https://github.com/natiginfo/action-detekt-all/tree/master/.release-manager), I created two workflows where [the first workflow](https://github.com/natiginfo/action-detekt-all/blob/master/.github/workflows/create_new_release.yml) runs the script every 24 hours, and [the second workflow](https://github.com/natiginfo/action-detekt-all/blob/master/.github/workflows/create_release_pr.yml) 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

```yaml

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 natiginfo/action-detekt-all %}


### 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](https://github.com/marketplace?type=actions), you can create workflow that works for your need.

Thanks for reading!