| 1 |
#!/bin/zsh |
| 2 |
# -*- vim:fenc=utf-8:et:sw=2:ts=2:sts=2 |
| 3 |
# |
| 4 |
# Copyright (c) 2026 Enrico M. Crisostomo |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify it under |
| 7 |
# the terms of the GNU General Public License as published by the Free Software |
| 8 |
# Foundation; either version 3, or (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 13 |
# details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License along with |
| 16 |
# this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
setopt local_options |
| 19 |
setopt local_traps |
| 20 |
unsetopt glob_subst |
| 21 |
|
| 22 |
set -o errexit |
| 23 |
set -o nounset |
| 24 |
|
| 25 |
RELEASE_REPO=${RELEASE_REPO:-emcrisostomo/fswatch} |
| 26 |
|
| 27 |
release_die() |
| 28 |
{ |
| 29 |
print -u2 -- "error: $*" |
| 30 |
exit 1 |
| 31 |
} |
| 32 |
|
| 33 |
release_warn() |
| 34 |
{ |
| 35 |
print -u2 -- "warning: $*" |
| 36 |
} |
| 37 |
|
| 38 |
release_info() |
| 39 |
{ |
| 40 |
print -- "$*" |
| 41 |
} |
| 42 |
|
| 43 |
release_repo_root() |
| 44 |
{ |
| 45 |
git rev-parse --show-toplevel 2> /dev/null || |
| 46 |
release_die "not inside a git repository" |
| 47 |
} |
| 48 |
|
| 49 |
release_parse_version() |
| 50 |
{ |
| 51 |
(( $# == 1 )) || release_die "release_parse_version expects one argument" |
| 52 |
|
| 53 |
RELEASE_VERSION=$1 |
| 54 |
if [[ "${RELEASE_VERSION}" =~ '^([0-9]+[.][0-9]+[.][0-9]+)(-rc[0-9]+|-develop)?$' ]] |
| 55 |
then |
| 56 |
RELEASE_BASE_VERSION=${match[1]} |
| 57 |
RELEASE_VERSION_MODIFIER=${match[2]:-} |
| 58 |
else |
| 59 |
release_die "invalid version '${RELEASE_VERSION}'; expected X.Y.Z, X.Y.Z-rcN, or X.Y.Z-develop" |
| 60 |
fi |
| 61 |
|
| 62 |
RELEASE_IS_DEVELOP=0 |
| 63 |
RELEASE_IS_PRERELEASE=0 |
| 64 |
|
| 65 |
if [[ "${RELEASE_VERSION_MODIFIER}" == "-develop" ]] |
| 66 |
then |
| 67 |
RELEASE_IS_DEVELOP=1 |
| 68 |
elif [[ "${RELEASE_VERSION_MODIFIER}" == -rc<-> ]] |
| 69 |
then |
| 70 |
RELEASE_IS_PRERELEASE=1 |
| 71 |
elif [[ -n "${RELEASE_VERSION_MODIFIER}" ]] |
| 72 |
then |
| 73 |
release_die "unsupported version modifier '${RELEASE_VERSION_MODIFIER}'" |
| 74 |
fi |
| 75 |
} |
| 76 |
|
| 77 |
release_m4_define() |
| 78 |
{ |
| 79 |
(( $# == 2 )) || release_die "release_m4_define expects file and macro name" |
| 80 |
local file=$1 |
| 81 |
local macro=$2 |
| 82 |
|
| 83 |
sed -n "s/^m4_define(\\[${macro}\\], \\[\\([^]]*\\)\\])$/\\1/p" "${file}" | |
| 84 |
tail -n 1 |
| 85 |
} |
| 86 |
|
| 87 |
release_cmake_project_version() |
| 88 |
{ |
| 89 |
sed -n 's/^project(fswatch VERSION *\([^ ]*\) .*/\1/p' CMakeLists.txt | |
| 90 |
tail -n 1 |
| 91 |
} |
| 92 |
|
| 93 |
release_cmake_version_modifier() |
| 94 |
{ |
| 95 |
sed -n 's/^set(VERSION_MODIFIER *"\([^"]*\)")$/\1/p' CMakeLists.txt | |
| 96 |
tail -n 1 |
| 97 |
} |
| 98 |
|
| 99 |
release_news_top_version() |
| 100 |
{ |
| 101 |
(( $# == 1 )) || release_die "release_news_top_version expects one file" |
| 102 |
sed -n 's/^New in \(.*\):$/\1/p' "$1" | |
| 103 |
head -n 1 |
| 104 |
} |
| 105 |
|
| 106 |
release_tag_exists() |
| 107 |
{ |
| 108 |
(( $# == 1 )) || release_die "release_tag_exists expects one tag" |
| 109 |
git rev-parse -q --verify "refs/tags/$1" > /dev/null |
| 110 |
} |
| 111 |
|
| 112 |
release_tag_type() |
| 113 |
{ |
| 114 |
(( $# == 1 )) || release_die "release_tag_type expects one tag" |
| 115 |
git cat-file -t "$1" 2> /dev/null || true |
| 116 |
} |