From b8335555f7c377d7e73c20686f5755579c17f57d Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Wed, 10 Jun 2020 16:26:12 +0200 Subject: [PATCH 1/6] add release.sh script to generate changelog, release to GH and Dockerhub --- .circleci/config.yml | 3 + release.sh | 139 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100755 release.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 7f608a37..7088a0f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/release.sh b/release.sh new file mode 100755 index 00000000..35c4271e --- /dev/null +++ b/release.sh @@ -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] " + 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 "$@" From ffd0de5f45197a62057be1f1bd081474e237aaf8 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Wed, 10 Jun 2020 17:32:28 +0200 Subject: [PATCH 2/6] release.sh: Fix changelog markdown syntax --- release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/release.sh b/release.sh index 35c4271e..9758cfc5 100755 --- a/release.sh +++ b/release.sh @@ -97,7 +97,7 @@ submodule_changelog () { 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,^Submodule \\([^ ]\\+\\) \\([^\.]\\+\\)..\\([^\.]\\+\\):,### [\1]($smurl) [\2]($smurl/commits\2)..[\3]($smurl/commits/\3)\\n$smtag," \ -e 's,^\s*>, > *,' } @@ -105,7 +105,7 @@ update_changelog () { ( echo "# Changelog" echo "" - echo "## [$version](https://github.com/OCR-D/ocrd_all/releases/$version" + echo "## [$version](https://github.com/OCR-D/ocrd_all/releases/$version)" echo "" for sm in $(list_changed_submodules);do submodule_changelog $sm From bfe99abf3ef8e0786daf803a5c81b18ca540e782 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Thu, 11 Jun 2020 14:48:02 +0200 Subject: [PATCH 3/6] Fixes by @bertsky Co-authored-by: Robert Sachunsky <38561704+bertsky@users.noreply.github.com> --- release.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/release.sh b/release.sh index 9758cfc5..600d457c 100755 --- a/release.sh +++ b/release.sh @@ -85,7 +85,7 @@ update_all_submodules () { sms=($(list_all_submodules)) fi for sm in "${sms[@]}";do - echo "$sm" + update_one_submodule "$sm" done } @@ -111,7 +111,7 @@ update_changelog () { submodule_changelog $sm echo "" done - sed -n "2,$ p" CHANGELOG.md + sed "/^[#] Changelog/d" CHANGELOG.md ) > CHANGELOG.md.tmp mv CHANGELOG.md.tmp CHANGELOG.md } @@ -121,11 +121,11 @@ release_github () { 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 + git add CHANGELOG.md + git commit -m ":package: v$version" + git tag $version + git push + 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" } From d45d4c3542683cf09ae86f8e279e3bdcc4f4fc1c Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Thu, 11 Jun 2020 16:42:27 +0200 Subject: [PATCH 4/6] release.sh release-github: Automate release on GH --- release.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/release.sh b/release.sh index 600d457c..07a74a2f 100755 --- a/release.sh +++ b/release.sh @@ -121,13 +121,17 @@ release_github () { echo "CHANGELOG.md is unmodified. Did you update it?" exit 1 fi + changelog=$(git diff CHANGELOG.md|grep '^+'|sed -e 's,^.,,' -e 's,",\",g' ) git add CHANGELOG.md - git commit -m ":package: v$version" + git commit -m ":package: $version" git tag $version git push 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" + wget \ + --method=PATCH \ + --header="Accept: application/vnd.github.v3+json" \ + --body-data "{ \"body\": \"$changelog\" }" \ + "https://api.github.com/repos/OCR-D/ocrd_all/releases/$version" } release_dockerhub () { From 6ba7608483b99fecf206ec06d9ad940ae6826c6f Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Thu, 11 Jun 2020 17:42:15 +0200 Subject: [PATCH 5/6] replace release wget with option to print changelog or copy to clipboard --- release.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/release.sh b/release.sh index 07a74a2f..1222b52f 100755 --- a/release.sh +++ b/release.sh @@ -127,11 +127,22 @@ release_github () { git tag $version git push git push --tags - wget \ - --method=PATCH \ - --header="Accept: application/vnd.github.v3+json" \ - --body-data "{ \"body\": \"$changelog\" }" \ - "https://api.github.com/repos/OCR-D/ocrd_all/releases/$version" + echo -n "(p)rint changelog, (c)opy changelog to clipboard, (i)gnore? > " + read resp; + if [[ $resp = p* || $resp = P* ]];then + echo "$changelog" + elif [[ $resp = c* || $resp = C* ]];then + if command -v pbcopy 2>/dev/null;then + echo "$changelog" | pbcopy + echo "Copied to clipboard" + elif command -v xclip 2>/dev/null;then + echo "$changelog" | xclip -i + echo "Copied to clipboard" + else + echo "!! Neither xclip nor pbcopy available. Install xclip or pbcopy or copy by hand:" + echo "$changelog" + fi + fi } release_dockerhub () { From 66f0c8d9c3f6c46a2cc7c24d963971d4e4f04fb4 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Thu, 11 Jun 2020 18:52:13 +0200 Subject: [PATCH 6/6] :memo: contributing guide, update license date --- .github/contributing.md | 34 ++++++++++++++++++++++++++++++++++ LICENSE | 1 + README.md | 7 +++++++ 3 files changed, 42 insertions(+) create mode 100644 .github/contributing.md diff --git a/.github/contributing.md b/.github/contributing.md new file mode 100644 index 00000000..e786fb39 --- /dev/null +++ b/.github/contributing.md @@ -0,0 +1,34 @@ +# ocrd_all Contributing guidelines + +For general information on how to use `ocrd_all`, please see the [README](https://github.com/OCR-D/ocrd_all). + +Thank you for being interested in contributing to `ocrd_all`! + +If you have any questions, feel free to ask them in the [OCR-D gitter chat](https://gitter.im/OCR-D/Lobby). + +## How to create PR for updated submodules + +1. Create a new branch with any name, e.g. `git checkout -b update-$(date +'%Y-%m-%d')` +2. Selectively update submodules in a way that makes sense to you. To upgrade + all submodules to the latest upstream versions, run `./release.sh update`. To + update only a specific submodule, such as `ocrd_cis`, run `./release.sh update + ocrd_cis`. Or update individual submodules manually: `cd ; git pull + origin master` (replace `master` if you want to merge another branch instead) +3. Manually check with `git status` that the changes are consistent with what + you want to update in the PR. +4. `git add` / `git commit` +5. `git push` to your `ocrd_all` fork on GitHub +6. Open a new PR for that branch (The `git push` request will show you the right URL) + +## How to merge update PR for updated submodules + +You need to be a "Maintainer" or "Admin" to merge pull requests. + +1. Wait for CI to successfully finish (ensuring that the `maximum` image can be built) +2. **Do not merge on GitHub**. Do the following locally: +3. Check out the `master` branch locally, `git pull` to make sure it's up-to-date. +4. Merge the PR branch with the `--no-commit` flag so the merge commit doesn't hide the changes: `git merge --no-commit pr-branch` +5. Generate the changelog: `./release.sh changelog`. +6. Inspect the CHANGELOG.md and remove superfluous information like merge commits or spurious newlines. Copy the new section to the clipboard (see step 8) +7. Release to GitHub with `./release.sh release-github`. This will take care of comitting, tagging and pushing the release. +8. Create a new release on GitHub, paste the new changelog section as the release notes. diff --git a/LICENSE b/LICENSE index 7c8aceec..97f7a936 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ Copyright © 2019 Stefan Weil +Copyright © 2020 OCR-D/ocrd_all contributors (https://github.com/OCR-D/ocrd_all/graphs/contributors) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/README.md b/README.md index cdf348c4..5fcb2edc 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ in the current shell environment via PATH and PYTHONHOME.) * [No published/recent version on PyPI](#no-publishedrecent-version-on-pypi) * [Conflicting requirements](#conflicting-requirements) * [System requirements](#system-requirements) + * [Contributing](#contributing) ## Preconditions @@ -387,3 +388,9 @@ Not all modules advertise their system package requirements via `make deps-ubunt - `tesseract` (when installing from source not PPA): depends on `libleptonica-dev` etc _(Solved by maintaining these requirements under `deps-ubuntu` here.)_ + +## Contributing + +Please see our [contributing +guide](https://github.com/OCR-D/ocrd_all/blob/master/.github/contributing.md) +to learn how you can support the project.