-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathbump_version.sh
More file actions
executable file
·140 lines (124 loc) · 5.68 KB
/
Copy pathbump_version.sh
File metadata and controls
executable file
·140 lines (124 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
# bump_version.sh — update version.py, commit, and tag a new emapper release.
#
# Usage:
# ./bump_version.sh [BUMP] [OPTIONS]
#
# BUMP types:
# pre — increment pre-release counter: 3.0.0-beta1 → 3.0.0-beta2
# if not currently on a pre-release, starts at label1: 3.0.0 → 3.0.0-beta1
# release — drop pre-release suffix: 3.0.0-beta3 → 3.0.0
# patch — (default) increment patch: 3.0.0 → 3.0.1 / 3.0.0-beta1 → 3.0.1
# minor — increment minor, reset patch: 3.0.0 → 3.1.0
# major — increment major, reset rest: 3.0.0 → 4.0.0
# X.Y.Z[-preN] — set an exact version string
#
# Options:
# --pre-label LABEL pre-release label to use with 'pre' bump (default: beta)
# --db-version X.Y.Z set __DB_VERSION__ (default: 7.0.0)
# --yes skip confirmation prompt
#
# After a successful tag the script prints the git push commands to run.
# It does NOT push automatically — review the tag first.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION_FILE="$REPO_ROOT/eggnogmapper/version.py"
# ── defaults ──────────────────────────────────────────────────────────────────
BUMP="patch"
DB_VERSION="7.0.0"
PRE_LABEL="beta"
AUTO_YES=0
# ── parse args ────────────────────────────────────────────────────────────────
while [[ $# -gt 0 ]]; do
case "$1" in
--db-version) DB_VERSION="$2"; shift 2 ;;
--pre-label) PRE_LABEL="$2"; shift 2 ;;
--yes) AUTO_YES=1; shift ;;
patch|minor|major|pre|release) BUMP="$1"; shift ;;
[0-9]*.*) BUMP="$1"; shift ;; # exact version e.g. 3.0.0-beta1
*) echo "Unknown argument: $1" >&2; exit 1 ;;
esac
done
# ── read current version ──────────────────────────────────────────────────────
[[ -f "$VERSION_FILE" ]] || { echo "ERROR: $VERSION_FILE not found." >&2; exit 1; }
CURRENT="$(grep "__VERSION__" "$VERSION_FILE" | cut -d"'" -f2)"
[[ -n "$CURRENT" ]] || { echo "ERROR: could not parse __VERSION__ from $VERSION_FILE" >&2; exit 1; }
NOVEL_FAMS_VERSION="$(grep "__NOVEL_FAMS_DB_VERSION__" "$VERSION_FILE" | cut -d"'" -f2)"
# split into base (X.Y.Z) and optional pre-release suffix (betaN)
if [[ "$CURRENT" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)-([a-zA-Z]+)([0-9]+)$ ]]; then
VMAJ="${BASH_REMATCH[1]}"
VMIN="${BASH_REMATCH[2]}"
VPAT="${BASH_REMATCH[3]}"
CUR_LABEL="${BASH_REMATCH[4]}"
CUR_NUM="${BASH_REMATCH[5]}"
elif [[ "$CURRENT" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
VMAJ="${BASH_REMATCH[1]}"
VMIN="${BASH_REMATCH[2]}"
VPAT="${BASH_REMATCH[3]}"
CUR_LABEL=""
CUR_NUM=""
else
echo "ERROR: cannot parse version '$CURRENT'" >&2; exit 1
fi
# ── compute new version ───────────────────────────────────────────────────────
case "$BUMP" in
pre)
if [[ -n "$CUR_LABEL" ]]; then
# already on a pre-release — increment the number
NEW_VERSION="${VMAJ}.${VMIN}.${VPAT}-${CUR_LABEL}$((CUR_NUM + 1))"
else
# start a new pre-release series
NEW_VERSION="${VMAJ}.${VMIN}.${VPAT}-${PRE_LABEL}1"
fi
;;
release)
# drop the pre-release suffix to produce a stable release
NEW_VERSION="${VMAJ}.${VMIN}.${VPAT}"
;;
patch)
NEW_VERSION="${VMAJ}.${VMIN}.$((VPAT + 1))"
;;
minor)
NEW_VERSION="${VMAJ}.$((VMIN + 1)).0"
;;
major)
NEW_VERSION="$((VMAJ + 1)).0.0"
;;
*)
# exact version string passed directly
NEW_VERSION="$BUMP"
;;
esac
TAG="v${NEW_VERSION}"
# ── confirm ───────────────────────────────────────────────────────────────────
echo "=================================================="
echo " current : $CURRENT"
echo " new : $NEW_VERSION (tag: $TAG)"
echo " db : $DB_VERSION"
echo " novel db : $NOVEL_FAMS_VERSION (unchanged)"
echo "=================================================="
if [[ "$AUTO_YES" == "0" ]]; then
read -rp "Proceed? [y/N] " CONFIRM
[[ "${CONFIRM,,}" == "y" ]] || { echo "Aborted."; exit 0; }
fi
# ── write version.py ──────────────────────────────────────────────────────────
cat > "$VERSION_FILE" <<EOF
#autogenerated during release process. Do not modify
__VERSION__='${NEW_VERSION}'
__DB_VERSION__='${DB_VERSION}'
__NOVEL_FAMS_DB_VERSION__='${NOVEL_FAMS_VERSION}'
EOF
echo "Written: $VERSION_FILE"
# ── commit and tag ────────────────────────────────────────────────────────────
git -C "$REPO_ROOT" add eggnogmapper/version.py
git -C "$REPO_ROOT" commit -m "chore: release ${TAG}"
git -C "$REPO_ROOT" tag "$TAG"
echo ""
echo "Done. Commit and tag '${TAG}' created."
echo ""
echo "To publish:"
echo " git -C $REPO_ROOT push && git -C $REPO_ROOT push --tags"
echo ""
echo "To build Apptainer image:"
echo " cd $REPO_ROOT/apptainer && ./build.sh"
echo " # or for a dev image: ./build.sh --local"