Skip to content

Commit

Permalink
Merge pull request #455 from ksuderman/tag-and-release-script
Browse files Browse the repository at this point in the history
Add tag and release script
  • Loading branch information
nuwang authored Feb 23, 2024
2 parents 3e3d1b5 + 1f4240d commit 0afe341
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions scripts/tag-and-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env bash

# Determine our name for use in the help message.
SCRIPT=$(basename $(realpath $0))

# ANSI color codes for the console.
reset="\033[0m"
bold="\033[1m"
ital="\033[3m" # does not work on OS X

# Function used to highlight text.
function hi() {
echo -e "$bold$@$reset"
}

# The last version that was tagged.
LATEST=$(git describe --tags `git rev-list --tags --max-count=1` | tr -d 'v')

# Date since the last release. We will search for commits newer than this.
SINCE=$(git log -1 --format=%as v$LATEST)

function help() {
less -RX << EOF
$(hi NAME)
$SCRIPT
$(hi DESCRIPTION)
Tags and generates a GitHub release for all commits that have "Automatic" in the
commit messages. These will be the commits that were generated by the packaging
GitHub action.
$(hi SYNOPSIS)
$SCRIPT --since DATE --latest TAG_NAME
$(hi OPTIONS)
-l|--latest the tag name of the last commit that was tagged. Default to $LATEST
-s|--since search the git log after this date (YYYY-MM-DD). Defaults to $SINCE
-h|--help prints this help message and exits
The $(hi --latest) and $(hi --since) fields will be determined from the Git log
if they are not provided.
Press $(hi Q) to quit this help.
EOF
}

while [[ $# > 0 ]] ; do
case $1 in
-l|--latest)
LATEST=$2
shift
;;
-s|--since)
SINCE=$2
shift
;;
-h|--help|help)
help
exit
;;
*)
echo "Invalid option $1"
echo "Run $(hi $SCRIPT help) for usage information"
exit
esac
shift
done
PREVIOUS="v$LATEST"

# Search the git log for commits that did an Automatic version bump.
git log --oneline --grep=Automatic --since=$SINCE | awk '{print $1,$NF}' | grep -v $LATEST | tail -r | while read -r line ; do
commit=$(echo $line | awk '{print $1}')
tag=v$(echo $line | awk '{print $2}')
# Get the actual date the commit was made
export GIT_COMMITTER_DATE=$(git show --format=%aD $commit | head -1)
# Tag the commit
echo "Tagging $commit as $tag $GIT_COMMITTER_DATE"
git checkout $commit
git tag -a -m "Automatic tagging of $tag" $tag
git push origin $tag
# Generate the release.
gh release create $tag --generate-notes --latest --notes-start-tag $PREVIOUS
PREVIOUS=$tag
done
git checkout master
echo "Done."

0 comments on commit 0afe341

Please sign in to comment.