---
title: "How to automate GitHub releases using GitHub Actions"
description: "Using GitHub Actions to push new releases without manually tagging commits."
datePublished: 2021-11-02T07:30:00.000Z
slug: "automated-github-release"
previewImage: "/preview/automated-github-release.jpeg"
permalink: "https://obviy.us/blog/automated-github-release/"
---

## Problem

At [Vume](https://www.vume.in/), the majority of our backend is written in Clojure. As new commits are pushed, we needed a way to automatically build JAR binaries but at the same time, avoid having to manually tag a release. The developers define the current version in the base `project.clj` file present on the root of every repository as:

```clojure
(defproject mprgs "0.12.12-SNAPSHOT"
    :min-lein-version "2.0.0"
    :java-source-paths ["src/java"]
    :source-paths ["src/clj"]
...
```

I needed a way to automatically grab that version number and push a release to GitHub whenever a PR was merged to the `master` branch.

## Solution

Since all our code is already present on GitHub, I chose to simply use GitHub Actions for building the JAR binaries. Native integration with GitHub features (access to repository secrets, access tokens to push a new release) made it all the more easier.

Grabbing the version number from the root `project.clj` was trivial by using a simple bash command:

```yaml
- name: Get Version
    run: |
    echo "MPRGS_VERSION=$(grep -oP -m 1 '(?<=")(?:\\.|[^"\\])*(?=")' project.clj)" >> $GITHUB_ENV
```

Here, the `-m 1` argument instructs `grep` to only consider the first match in the entire body. The regex itself captures the first string encoded in double quotes[\[1\]](https://stackoverflow.com/a/2808751/11940280).

If the build succeeds, then [marvinpinto/action-automatic-releases](https://github.com/marvinpinto/action-automatic-releases) is invoked with the following parameters:

```yaml
- uses: "marvinpinto/action-automatic-releases@latest"
    with:
    repo_token: "${{ secrets.GITHUB_TOKEN }}"
    automatic_release_tag: "${{ env.MPRGS_VERSION }}"
    prerelease: false
    title: "v${{ env.MPRGS_VERSION }}"
    files: |
        LICENSE
        ./target/*.jar
```

Which simply uploads all the assets we describe as a part of the GitHub release. I had some issues with grabbing the environment variable (`set-env` is now deprecated due to a [security vulnerability](https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/)).

And finally:

![Automated Release](https://obviy.us/_astro/gh-release.i3bBShRG_1JFP8V.webp)

Automated Release

And as a bonus, the Action also creates a changelog with the commits that were part of the newest build.
