| 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 |
PROGNAME=${0:t} |
| 26 |
PROGDIR=${0:A:h} |
| 27 |
|
| 28 |
. "${PROGDIR}/lib.zsh" |
| 29 |
|
| 30 |
usage() |
| 31 |
{ |
| 32 |
print -- "Usage: ${PROGNAME} [options] VERSION" |
| 33 |
print |
| 34 |
print -- "Create the release tag and GitHub release. Defaults to dry-run." |
| 35 |
print |
| 36 |
print -- "Options:" |
| 37 |
print -- " --execute Actually create/push the tag and create the GitHub release." |
| 38 |
print -- " --notes FILE Release notes file. Default: release-notes.md." |
| 39 |
print -- " --repo OWNER/REPO GitHub repository. Default: ${RELEASE_REPO}." |
| 40 |
print -- " -h, --help Print this message." |
| 41 |
} |
| 42 |
|
| 43 |
typeset -i execute=0 |
| 44 |
notes_file=release-notes.md |
| 45 |
repo=${RELEASE_REPO} |
| 46 |
|
| 47 |
while (( $# > 0 )) |
| 48 |
do |
| 49 |
case "$1" in |
| 50 |
--execute) |
| 51 |
execute=1 |
| 52 |
shift |
| 53 |
;; |
| 54 |
--dry-run) |
| 55 |
execute=0 |
| 56 |
shift |
| 57 |
;; |
| 58 |
--notes) |
| 59 |
(( $# >= 2 )) || release_die "--notes requires a file" |
| 60 |
notes_file=$2 |
| 61 |
shift 2 |
| 62 |
;; |
| 63 |
--repo) |
| 64 |
(( $# >= 2 )) || release_die "--repo requires OWNER/REPO" |
| 65 |
repo=$2 |
| 66 |
shift 2 |
| 67 |
;; |
| 68 |
-h|--help) |
| 69 |
usage |
| 70 |
exit 0 |
| 71 |
;; |
| 72 |
--) |
| 73 |
shift |
| 74 |
break |
| 75 |
;; |
| 76 |
-*) |
| 77 |
release_die "unknown option: $1" |
| 78 |
;; |
| 79 |
*) |
| 80 |
break |
| 81 |
;; |
| 82 |
esac |
| 83 |
done |
| 84 |
|
| 85 |
(( $# == 1 )) || { |
| 86 |
usage |
| 87 |
exit 1 |
| 88 |
} |
| 89 |
|
| 90 |
release_parse_version "$1" |
| 91 |
(( ! RELEASE_IS_DEVELOP )) || |
| 92 |
release_die "publish refuses -develop versions" |
| 93 |
|
| 94 |
repo_root=$(release_repo_root) |
| 95 |
cd "${repo_root}" |
| 96 |
|
| 97 |
[[ -f "${notes_file}" ]] || |
| 98 |
release_die "release notes file does not exist: ${notes_file}" |
| 99 |
|
| 100 |
release_flags=() |
| 101 |
if (( RELEASE_IS_PRERELEASE )) |
| 102 |
then |
| 103 |
release_flags+=( --prerelease --latest=false ) |
| 104 |
fi |
| 105 |
|
| 106 |
print -- "Publish plan for ${RELEASE_VERSION}:" |
| 107 |
print -- " repository: ${repo}" |
| 108 |
print -- " notes: ${notes_file}" |
| 109 |
print -- " prerelease: ${RELEASE_IS_PRERELEASE}" |
| 110 |
print -- " assets: produced later by .github/workflows/release-tarball.yml" |
| 111 |
|
| 112 |
if (( ! execute )) |
| 113 |
then |
| 114 |
print |
| 115 |
print -- "Dry run only. These commands would run:" |
| 116 |
print -- " scripts/release/check.zsh --release --require-clean --notes '${notes_file}' '${RELEASE_VERSION}'" |
| 117 |
print -- " git tag -a '${RELEASE_VERSION}' -m '${RELEASE_VERSION}' # only if the tag does not exist" |
| 118 |
print -- " git push origin '${RELEASE_VERSION}'" |
| 119 |
print -- " gh release create '${RELEASE_VERSION}' --repo '${repo}' --verify-tag --title 'fswatch v. ${RELEASE_VERSION}' --notes-file '${notes_file}' ${release_flags[*]}" |
| 120 |
exit 0 |
| 121 |
fi |
| 122 |
|
| 123 |
"${PROGDIR}/check.zsh" --release --require-clean --notes "${notes_file}" "${RELEASE_VERSION}" |
| 124 |
|
| 125 |
if release_tag_exists "${RELEASE_VERSION}" |
| 126 |
then |
| 127 |
tag_type=$(release_tag_type "${RELEASE_VERSION}") |
| 128 |
[[ "${tag_type}" == "tag" ]] || |
| 129 |
release_die "local tag ${RELEASE_VERSION} exists but is '${tag_type}', not an annotated tag" |
| 130 |
else |
| 131 |
git tag -a "${RELEASE_VERSION}" -m "${RELEASE_VERSION}" |
| 132 |
fi |
| 133 |
|
| 134 |
git push origin "${RELEASE_VERSION}" |
| 135 |
|
| 136 |
gh release create "${RELEASE_VERSION}" \ |
| 137 |
--repo "${repo}" \ |
| 138 |
--verify-tag \ |
| 139 |
--title "fswatch v. ${RELEASE_VERSION}" \ |
| 140 |
--notes-file "${notes_file}" \ |
| 141 |
"${release_flags[@]}" |