-
-
Save acrodrig/8ca32ed618fe7d6d82900c1242d2eeb0 to your computer and use it in GitHub Desktop.
Script to release package in GitHub with automatic release notes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check parameters | |
[ -z "$1" ] && echo "usage: release <vX.X.X | minor | patch> [--no-preview|-np]" && exit 1 | |
# Test parameters are valid | |
[[ ! "$1" =~ ^(v[0-9]\.[0-9]\.?[0-9]?|minor|patch)$ ]] && echo -e "Wrong parameter(s)!\nusage: release <vX.X.X | minor | patch> [--no-preview|-np]" && exit 2 | |
# Make sure to fetch all remote before proceeding | |
GF=$(git fetch 2> /dev/null) | |
[[ ! "$?" = 0 ]] && echo -e "Git permission denied!\nusage: release <vX.X.X | minor | patch> [--no-preview|-np]" && exit 3 | |
# Make sure local and remote are identical | |
GD=$(git diff --quiet 2> /dev/null) | |
[[ ! "$?" = 0 ]] && echo -e "Git local different than remote!\nusage: release <vX.X.X | minor | patch> [--no-preview|-np]" && exit 3 | |
# Get Current Version | |
CV=$(gh release view --json tagName | jq -r '.tagName') | |
PARTS=($(echo $CV | tr '.' ' ')) | |
# Build next version | |
NV=$1 | |
if [ "$NV" == "minor" ]; then | |
NV="${PARTS[0]}.$((${PARTS[1]}+1)).0" | |
elif [ "$NV" == "patch" ]; then | |
NV="${PARTS[0]}.${PARTS[1]}.$((${PARTS[2]}+1))" | |
fi | |
# Collect notes (see https://stackoverflow.com/questions/12082981/get-all-git-commits-since-last-tag) | |
LOG=$(git log $CV..HEAD --oneline --no-decorate | sed 's/^/- /') | |
TITLE="### $NV / $(date +%Y-%m-%d)" | |
NOTES="$TITLE\n$LOG\n" | |
echo -e "Last version was $CV, will release version $NV (notes below)...\n" | |
echo -e "$NOTES" | |
NP=${2:-"X"} | |
if [ "$NP" != "--no-preview" ] && [ "$NP" != "-np" ]; then | |
# Preview mode | |
echo "Preview mode (append '-np' or '-no-preview' to release) ..." | |
else | |
# Release and fetch back | |
echo gh release create $NV --title "$NV" --notes "$NOTES" | |
echo git pull --rebase | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment