Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add release.sh script to generate changelog, release to GH and Dockerhub #107

Merged
merged 6 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
docker push ocrd/all:maximum-git &
jobs+=($!)
while sleep 60; ps -p "${jobs[*]}"; do :; done
- run:
name: Create a date-versioned mirror of ocrd/all:maximum
command: bash release.sh release-dockerhub
- run: curl -X POST "$MICROBADGER_WEBHOOK" || true
workflows:
version: 2
Expand Down
139 changes: 139 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env bash
# set -ex

# SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# PATH="$SCRIPTDIR:$PATH"
SCRIPTNAME=$(basename $0)

version=$(git describe --abbrev=0 --tags --exact-match 2>/dev/null||date +'v%Y-%m-%d')

usage () {
echo "$SCRIPTNAME [options] <command>"
echo ""
echo "Options:"
echo ""
echo " -V Version to release. Default: $version"
echo " -h Show this help"
echo ""
echo "Commands:"
echo ""
echo " update Update all submodules to most recent master/dev branch"
echo " changelog Generate a changelog for all modified submodules"
echo " release-github Release to GitHub as $version"
echo " release-dockerhub Release ocrd/all:maximum as ocrd/all:${version#v} to DockerHub"
}

main () {
while [[ "$1" = -* ]];do
case "$1" in
-V) version="$2";
if [[ "$version" != v* ]];then
echo "Version must start with 'v': $version"
exit 1
fi
shift; ;;
-h) usage; exit; ;;
esac
shift
done
if [[ -z "$1" ]];then
usage
exit 1
fi
cmd="$1"
shift
case "$cmd" in
update) update_all_submodules "$@" ;;
changelog) update_changelog ;;
release-github) release_github ;;
release-dockerhub) release_dockerhub ;;
*) usage; exit 1 ;;
esac
}

submodule_url () {
local sm="$1"
git config --file .gitmodules --get-regexp "$sm.url" |cut -d' ' -f 2|sed 's,\.git$,,'
}

list_all_submodules () {
git config --file .gitmodules --get-regexp path | awk '{ print $2 }' |sort -n
}

list_changed_submodules () {
git submodule status |grep '^+'|cut -d ' ' -f 2|sort -n
}

update_one_submodule () {
local sm="$1"
local branch="master"
if test $sm = 'ocrd_cis';then
branch="dev"
fi
(
cd $sm
git pull origin "$branch"
git pull origin "$branch" --tags
git submodule update --init
)
}

update_all_submodules () {
if [[ $# -gt 0 ]];then
sms="$@"
else
sms=($(list_all_submodules))
fi
for sm in "${sms[@]}";do
echo "$sm"
done
}

submodule_changelog () {
local sm="$1"
local smurl=$(submodule_url "$sm")
local smtag=$(cd $sm; git describe --abbrev=0 --tags 2>/dev/null|| echo '')
if [[ -n "$smtag" ]];then
smtag="\\n> Release: [$smtag]($smurl/releases/$smtag)\\n"
fi
git diff --submodule=log "$sm"| sed \
-e "s,^Submodule \\([^ ]\\+\\) \\([^\.]\\+\\)..\\([^\.]\\+\\):,### [\1]($smurl) [\2]($smurl/commits\2)..[\3]($smurl/commits/\3)\\n$smtag," \
-e 's,^\s*>, > *,'
}

update_changelog () {
(
echo "# Changelog"
echo ""
echo "## [$version](https://github.com/OCR-D/ocrd_all/releases/$version)"
echo ""
for sm in $(list_changed_submodules);do
submodule_changelog $sm
echo ""
done
sed -n "2,$ p" CHANGELOG.md
) > CHANGELOG.md.tmp
mv CHANGELOG.md.tmp CHANGELOG.md
}

release_github () {
if [[ "$(git status CHANGELOG.md)" = "" ]];then
echo "CHANGELOG.md is unmodified. Did you update it?"
exit 1
fi
echo git add .
echo git commit -m ":package: v$version"
echo git tag $version
echo git push
echo git push --tags
echo "Go to https://github.com/OCR-D/ocrd_all/releases/$version and paste"
echo "the CHANGELOG.md section as release notes"
}

release_dockerhub () {
docker tag ocrd/all:maximum ocrd/all:${version#v}
docker push ocrd/all:${version#v}
}


main "$@"