Skip to content

Instantly share code, notes, and snippets.

@saschpe
Created February 12, 2020 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saschpe/907aea57d9b97f7ac785fe93d04c0e93 to your computer and use it in GitHub Desktop.
Save saschpe/907aea57d9b97f7ac785fe93d04c0e93 to your computer and use it in GitHub Desktop.
A script to figure out if a release commit was part of a merge (i.e. part of the entire merged branch or current HEAD commit)
#!/bin/bash
#
# Script to publish apps to the Play Store in case a release is discovered
#
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "${SCRIPT_DIR}/../inc.functions.sh"
# Constants
SECRET_FILE=config/play-publishing-api.json
# Checks
[[ -f ${SECRET_FILE} ]] || die "App update requires credentials at '${SECRET_FILE}'"
# Functions
function is_release_commit {
commit_message=$(git log --oneline --format=%B -n 1 ${1} | head -n 1)
if [[ "${commit_message}" == "Release version "* ]] ; then
return 0
else
return 1
fi
}
# Let's roll
git_head_commit=$(git rev-parse HEAD)
git_last_merge_commit=$(git log -1 --format=%H --merges)
if [[ ${git_head_commit} == ${git_last_merge_commit} ]] ; then
# HEAD is a merge commit, check commits on merged branch for a release commit by
# finding common ancestor and by iterating all commits from that branch
git_branch_parent_commits=( $(git log -1 --merges --pretty=format:%P) )
git_branch_merge_base_commit=$(git merge-base --all ${git_branch_parent_commits[0]} ${git_branch_parent_commits[1]})
for commit in $(git log --pretty=%H ${git_branch_merge_base_commit}..${git_branch_parent_commits[1]}) ; do
if is_release_commit ${commit} ; then
approve "Release commit found in branch at ${commit}, publishing app..."
# Checkout release commit and build exactly that...
git checkout ${commit}
./gradlew publishReleaseBundle --artifact-dir mobile/build/outputs/bundle/release
git checkout ${git_head_commit}
exit 0
fi
done
elif is_release_commit ${git_head_commit} ; then
approve "Release commit found at HEAD (${git_head_commit}), publishing app..."
./gradlew publishReleaseBundle --artifact-dir mobile/build/outputs/bundle/release
exit 0
fi
warn "No release commit, skipping..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment