Skip to content

Commit

Permalink
Merge pull request #617 from arogge/dev/arogge/master/devtools
Browse files Browse the repository at this point in the history
devtools: introduce devtools directory
  • Loading branch information
pstorz committed Nov 5, 2020
2 parents 3f510d1 + 64d411a commit c69420f
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 15 deletions.
15 changes: 15 additions & 0 deletions devtools/README.md
@@ -0,0 +1,15 @@
# Bareos Developer Tools

This directory contains tools to work with the Bareos sourcecode. As a user, you will probably never need them.

## `prepare-release.sh`

This script does most of the hard work when releasing Bareos. It is used to prepare and tag the release-commit and a following base-commit for the ongoing work on the branch.

## `update-changelog-links.sh`

Script to find common link references in CHANGELOG.md (i.e. versions and bugs) and add the correct reference to the end of the file. Should be called after adding a link reference to CHANGELOG.md, but will not hurt if called too often.

## `new-changelog-release.sh`

Update the changelog when a release is made. Will either add a new "Unreleased" chapter in the changelog or replace an existing one with a provided version number and release-date.
85 changes: 85 additions & 0 deletions devtools/new-changelog-release.sh
@@ -0,0 +1,85 @@
#!/bin/bash
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2020-2020 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation and included
# in the file LICENSE.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

set -e
set -u

# this script edits the current release in the release notes or adds a new
# unreleased section

prog="$(basename "$0")"
topdir="$(realpath "$(dirname "$0")/..")"
pushd "$topdir" >/dev/null

if [ $# -ne 2 ] && [ "${1:-}" != unreleased ]; then
echo "usage: $prog {<version> <date>|unreleased}" >&2
exit 1
fi

if [ ! -f CHANGELOG.md ]; then
echo "No CHANGELOG.md to work with" >&2
exit 1
fi

tmp="$(mktemp)"

function cleanup {
rm -f "$tmp"
}
trap cleanup EXIT

if [ $# -eq 2 ]; then
version="$1" date="$2" awk '
{
if($0 == "## [Unreleased]") {
printf("## [%s] - %s\n", ENVIRON["version"], ENVIRON["date"])
} else {
print
}
}
' CHANGELOG.md >"$tmp"

else
awk '
BEGIN {
found=0
}
/^## \[Unreleased\]/ {
found=1
}
/^## \[/ {
if(found == 0 && $0 != "## [Unreleased]") {
printf("## [Unreleased]\n\n")
found=1
}
}
{
print
}
' CHANGELOG.md >"$tmp"
fi

if diff -u CHANGELOG.md "$tmp" >/dev/null; then
echo "$prog: CHANGELOG.md is unchanged."
else
mv "$tmp" CHANGELOG.md
echo "$prog: updated CHANGELOG.md"
echo "$prog: run update-changelog-links.sh to update link references"
fi
75 changes: 60 additions & 15 deletions prepare-release.sh → devtools/prepare-release.sh
@@ -1,4 +1,23 @@
#!/bin/bash
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2019-2020 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation and included
# in the file LICENSE.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

set -e
set -u

Expand All @@ -10,7 +29,7 @@ version_regexp='([[:digit:]]+\.){2}[[:digit:]]+(~[[:alnum:]]+)?'
# "18.2.7"
stable_version_regexp='([[:digit:]]+\.){2}[[:digit:]]+'

topdir="$(dirname "$0")"
topdir="$(realpath "$(dirname "$0")/..")"
prog="$(basename "$0")"

git="${GIT:-$(type -p git)}"
Expand All @@ -36,7 +55,7 @@ print_block() {
local s='\e[44m\e[97m' e='\e[0m'
printf "\n%b┏" "$s"; printf -- "━%.0s" {1..77}; printf "┓%b\n" "$e"
printf "%b┃ %-73s ┃%b\n" "$s" '' "$e"
while read line; do
while read -r line; do
printf "%b┃ %-73s ┃%b\n" "$s" "$line" "$e"
done
printf "%b┃ %-73s ┃%b\n" "$s" '' "$e"
Expand All @@ -47,7 +66,7 @@ print_block() {
# it will then return the patch-version that follows after the provided version.
get_next_version() {
local in_parts out_parts last
IFS=. in_parts=($1) # split into an array
IFS=. read -ra in_parts <<< "$1" # split into an array
((last=${#in_parts[@]} - 1 )) # get index of last element
out_parts=()
# concatenate up to, but not including last element
Expand All @@ -65,9 +84,9 @@ confirm() {
[[ $REPLY =~ ^[Yy]$ ]]
}

if [ -z "$git" -o ! -x "$git" ]; then
if [ -z "$git" ] || [ ! -x "$git" ]; then
log_fatal "git not found."
elif [ -z "$cmake" -o ! -x "$cmake" ]; then
elif [ -z "$cmake" ] || [ ! -x "$cmake" ]; then
log_fatal "cmake not found."
elif [ ! -e .git ]; then
log_fatal "This is not a git working copy."
Expand Down Expand Up @@ -111,6 +130,7 @@ fi

release_tag="Release/${version/\~/-}"
release_ts="$(date --utc --iso-8601=seconds | sed --expression='s/T/ /;s/+.*$//')"
release_date="$(sed --expression='s/ .*$//' <<< "$release_ts")"
release_message="Release $version"

# Only if we are preparing a stable release
Expand Down Expand Up @@ -145,14 +165,24 @@ If this is not a pre-release a new work-in-progress tag will be created:
This script will do the following:
1. Create an empty git commit with the version timestamp
2. Generate and add */cmake/BareosVersion.cmake
3. Amend the previous commit with the version files
4. Remove */cmake/BareosVersion.cmake
5. Commit the removed version files.
6. Add an empty commit for a WIP tag (not for pre-releases)
7. Set the release tag
8. Set the WIP tag (not for pre-releases)
1. Create release commit
1a. create empty commit with version timestamp
1b. generate and add */cmake/BareosVersion.cmake
1c. update CHANGELOG.md to reflect new release
1d. amend commit from a. with changes from b. and c.
2. Clean up after release commit
2a. remove */cmake/BareosVersion.cmake
2b. commit the removed files
3. Set up a new base for future work (not for pre-releases)
3a. add a new "unreleased" section to CHANGELOG.md
3b. commit updated CHANGELOG.md
4. Set tags
4a. add the release-tag pointing to the commit from 1d.
4b. add WIP tag pointing to the commit form 3b. if applicable
Please make sure you're on the right branch before continuing and review
the commits, tags and branch pointers before you push!
Expand Down Expand Up @@ -182,11 +212,17 @@ log_info "if you want to rollback the commits" \

"$cmake" -DVERSION_STRING="$version" -P write_version_files.cmake

if [ "$wip_enable" -eq 1 ]; then
./devtools/new-changelog-release.sh "$version" "$release_date"
./devtools/update-changelog-links.sh
fi

"$git" add \
--no-all \
--force \
-- \
./*/cmake/BareosVersion.cmake
./*/cmake/BareosVersion.cmake \
./CHANGELOG.md

"$git" commit \
--quiet \
Expand All @@ -195,7 +231,8 @@ log_info "if you want to rollback the commits" \
--date="$release_ts" \
-m "$release_message" \
-- \
./*/cmake/BareosVersion.cmake
./*/cmake/BareosVersion.cmake \
./CHANGELOG.md

release_commit="$(git rev-parse HEAD)"
log_info "commit for release tag will be $release_commit"
Expand All @@ -210,6 +247,14 @@ log_info "commit for release tag will be $release_commit"
-m "Remove */cmake/BareosVersion.cmake after release"

if [ "$wip_enable" -eq 1 ]; then
./devtools/new-changelog-release.sh unreleased
./devtools/update-changelog-links.sh

"$git" add \
--no-all \
-- \
./CHANGELOG.md

"$git" commit \
--quiet \
--allow-empty \
Expand Down
101 changes: 101 additions & 0 deletions devtools/update-changelog-links.sh
@@ -0,0 +1,101 @@
#!/bin/bash
# BAREOS® - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2020-2020 Bareos GmbH & Co. KG
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of version three of the GNU Affero General Public
# License as published by the Free Software Foundation and included
# in the file LICENSE.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

set -e
set -u

# This script will update link references at the end of a CHANGELOG.md
# 1. remove all references (lines starting with "[...]: "
# 2. look for reference tokens ([...]) and for each one that adheres to a
# known format add a reference to the correct url.
# A message will be shown for each unsupported token.
#
# Currently supported:
# * "unreleased" -> link to github master branch
# * version numbers -> link to gitgub release
# * issue numbers -> link to bugs.bareos.org
# * pull requests -> link to github PR

topdir="$(realpath "$(dirname "$0")/..")"
pushd "$topdir" >/dev/null

if [ ! -f CHANGELOG.md ]; then
echo "No CHANGELOG.md to work with" >&2
exit 1
fi

tmp="$(mktemp)"

function cleanup {
rm -f "$tmp"
}
trap cleanup EXIT

# strip all references first
grep -v -E '^\[[^]]+\]: ' CHANGELOG.md > "$tmp"

# grab every reference token, repetitions only once
readarray -t ref_tokens < <(
grep -o -E '\[[^]]+\]' "$tmp" \
| sed -e 's/^\[//;s/\]$//;' \
| sort -uV)

for ref_tok in "${ref_tokens[@]}"; do
case "$ref_tok" in
Unreleased)
echo '[unreleased]: https://github.com/bareos/bareos/tree/master' \
>>"$tmp"
;;
[0-9].[0-9].[0-9]|\
[0-9].[0-9].[0-9][0-9]|\
[0-9].[0-9][0-9].[0-9]|\
[0-9].[0-9][0-9].[0-9][0-9]|\
[0-9][0-9].[0-9].[0-9]|\
[0-9][0-9].[0-9].[0-9][0-9]|\
[0-9][0-9].[0-9][0-9].[0-9]|\
[0-9][0-9].[0-9][0-9].[0-9][0-9])
printf \
"[%s]: https://github.com/bareos/bareos/releases/tag/Release%%2F%s\n" \
"$ref_tok" \
"$ref_tok" \
>>"$tmp"
;;
Issue\ \#[0-9]*|\
\#[0-9]*)
ticket="$(grep -o -E '[0-9]+$' <<< "$ref_tok")"
printf "[%s]: https://bugs.bareos.org/view.php?id=%d\n" \
"$ref_tok" \
"$ticket" \
>>"$tmp"
;;
PR\ \#[0-9]*)
pr="$(grep -o -E '[0-9]+$' <<< "$ref_tok")"
printf "[%s]: https://github.com/bareos/bareos/pull/%d\n" \
"$ref_tok" \
"$pr" \
>>"$tmp"
;;
*)
echo "Ignoring token [$ref_tok]" >&2
;;
esac
done

mv "$tmp" CHANGELOG.md

0 comments on commit c69420f

Please sign in to comment.