Automated release notes for Android

Setup “Release Drafter”

name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- develop

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5.6.0
with:
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
config-name: develop-config.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CI setup

  • Get the latest tag.
  • If there are new commits since the latest tag, proceed, otherwise stop the process (we don’t want to deliver the same build twice)
  • Assuming there are new commits -> take the latest tag and increase its version
  • Take the latest draft release from GitHub, add the tag name and change its status to published.

Getting latest tag version and commits since it

latestTag=$(git describe --tags --abbrev=0)
commitsSinceLastTag=$(git log $latestTag..HEAD)
#!/usr/bin/env bash

#fetch the history
git pull --rebase
latestTag=$(git describe --tags --abbrev=0)
commitsSinceLastTag=$(git log $latestTag..HEAD)

# Check if there are commits since latest tag
if [ -n "$commitsSinceLastTag" ]; then
echo "There are commits since last tag"

latestTagNumber=""
# Splits passed var by specified separator
IFS='_'
read -ra ADDR <<<"$latestTag"

# Gets beta number
latestTagNumber=${ADDR[1]}

# Increases beta number
latestTagNumber=$(($latestTagNumber + 1))
echo $latestTagNumber

# Generates new beta name and stores it
newTagToPush="Beta_"${latestTagNumber}
echo $newTagToPush
export GIT_BETA_TAG="$newTagToPush"
envman add --key GIT_BETA_TAG --value "$GIT_BETA_TAG"
else
echo "There are NO commits since last tag"
exit 1
fi
latestTag=$(git describe --tags --abbrev=0)
commitsSinceLastTag=$(git log $latestTag..HEAD)

# Check if there are commits since latest tag
if [ -n "$commitsSinceLastTag" ]; then
echo "There are commits since last tag"

latestTagNumber=""
# Splits passed var by specified separator
IFS='_'
read -ra ADDR <<<"$latestTag"

# Gets beta number
latestTagNumber=${ADDR[1]}

# Increases beta number
latestTagNumber=$(($latestTagNumber + 1))
echo $latestTagNumber

# Generates new beta name and stores it
newTagToPush="Beta_"${latestTagNumber}
echo $newTagToPush
export GIT_BETA_TAG="$newTagToPush"
envman add --key GIT_BETA_TAG --value "$GIT_BETA_TAG"
else
echo "There are NO commits since last tag"
exit 1
fi

Publish the latest release in draft status on GitHub

sudo apt-get -y install jq
#!/usr/bin/env bash

releaseId=$(curl -u $GITHUB_USERNAME:$GITHUB_TOKEN https://api.github.com/repos/[OWNER]/[REPO]/releases |
jq '.[] | select(.draft == true) | "\(.id)"')

releaseIdWithoutQuotes=$(sed -e 's/^"//' -e 's/"$//' <<<"$releaseId")

curl -u $GITHUB_USERNAME:$GITHUB_TOKEN --request PATCH "https://api.github.com/repos/[OWNER]/[REPO]/releases/$releaseIdWithoutQuotes" --header "Content-Type: application/json" --header "Accept: application/json" --data "{\"tag_name\": \"$GIT_BETA_TAG\", \"target_commitish\": \"develop\", \"name\": \"$GIT_BETA_TAG\", \"draft\": false, \"prerelease\": false}"
{
"tag_name": "Beta 23",
"target_commitish": "develop",
"name": "Release Beta 23",
"draft": false,
"prerelease": false
}
  • We used to have the scripts directly in our CI, that is a bit dangerous because you can lose them every time we make a change. This time we decided to store them in the project itself, and we invoke them from the CI.
  • If you need to quickly test your bash scripts you can work on them directly in Android Studio, there is a nice plugin that comes bundled in AS called Shell Script that supports running them quickly, styling and code autocompletion.
  • Always keep your secrets out of the scripts
Bitrise workflow example

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alessandro Mautone

Alessandro Mautone

Senior Android Engineer @WeTransfer 🤖 🇻🇪🇮🇹 Paraglider, Runner, Kayaker.