-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_version.sh
More file actions
executable file
·140 lines (124 loc) · 4.39 KB
/
Copy pathupdate_version.sh
File metadata and controls
executable file
·140 lines (124 loc) · 4.39 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
set -euo pipefail
readonly POM_FILE="pom.xml"
readonly VERSION_PROPERTY="revision"
readonly TIMESTAMP_PROPERTY="project.build.outputTimestamp"
readonly VERSIONS_PLUGIN="org.codehaus.mojo:versions-maven-plugin:2.18.0"
readonly MODULES=(
featureframework-testkit
featureframework-mockito-testkit
featureframework-api
featureframework-toolkit
featureframework-core
featureframework-dataprovider
featureframework-dataregistry
featureframework-paper
featureframework-paper-toolkit
featureframework-paper-integrations
featureframework-velocity
featureframework-velocity-integrations
featureframework-bom
)
die() {
echo "Error: $*" >&2
exit 1
}
usage() {
cat >&2 <<'USAGE'
Usage: ./update_version.sh <major|minor|patch>
Bumps FeatureFramework's reactor revision and reproducible-build timestamp, verifies the
complete platform-acceptance gate, then creates a local release commit and annotated tag.
USAGE
}
require_file() {
local path="$1"
[[ -f "$path" ]] || die "${path} not found."
}
resolve_version() {
local module="${1:-}"
local -a module_args=()
local version
if [[ -n "$module" ]]; then
module_args=(-pl "$module")
fi
version="$(
./mvnw -q -ntp "${module_args[@]}" -DforceStdout help:evaluate -Dexpression=project.version \
| awk '/^[0-9]+\.[0-9]+\.[0-9]+$/ { print; exit }'
)"
[[ -n "$version" ]] || die "Unable to resolve a semantic Maven version${module:+ for ${module}}."
printf '%s\n' "$version"
}
bump_semver() {
local semver="$1"
local bump_type="$2"
local major minor patch
[[ "$semver" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]] \
|| die "Current version must be semantic (X.Y.Z), got '${semver}'."
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
case "$bump_type" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
*) usage; exit 1 ;;
esac
printf '%s.%s.%s\n' "$major" "$minor" "$patch"
}
update_build_timestamp() {
local timestamp="$1"
local temporary_file
temporary_file="$(mktemp "${POM_FILE}.XXXXXX")"
awk -v timestamp="$timestamp" '
BEGIN { replaced = 0 }
{
if (!replaced && $0 ~ /<project\.build\.outputTimestamp>[^<]+<\/project\.build\.outputTimestamp>/) {
sub(/<project\.build\.outputTimestamp>[^<]+<\/project\.build\.outputTimestamp>/,
"<project.build.outputTimestamp>" timestamp "</project.build.outputTimestamp>")
replaced = 1
}
print
}
END { if (!replaced) exit 2 }
' "$POM_FILE" >"$temporary_file" || {
rm -f "$temporary_file"
die "Could not update ${TIMESTAMP_PROPERTY} in ${POM_FILE}."
}
mv "$temporary_file" "$POM_FILE"
}
if [[ $# -eq 1 && ( "$1" == "--help" || "$1" == "-h" ) ]]; then
usage
exit 0
fi
[[ $# -eq 1 ]] || { usage; exit 1; }
[[ "$1" == "major" || "$1" == "minor" || "$1" == "patch" ]] || { usage; exit 1; }
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || die "Run this script inside the repository."
REPOSITORY_ROOT="$(git rev-parse --show-toplevel)"
cd "$REPOSITORY_ROOT"
for required in "$POM_FILE" "mvnw"; do
require_file "$required"
done
[[ -z "$(git status --porcelain)" ]] || die "Working tree is not clean. Commit or stash changes first."
current_version="$(resolve_version)"
new_version="$(bump_semver "$current_version" "$1")"
new_tag="v${new_version}"
git rev-parse -q --verify "refs/tags/${new_tag}" >/dev/null 2>&1 && die "Tag ${new_tag} already exists."
echo "Current version: ${current_version}"
echo "Bumping to: ${new_version}"
./mvnw -B -ntp "${VERSIONS_PLUGIN}:set-property" \
-Dproperty="${VERSION_PROPERTY}" -DnewVersion="${new_version}" -DgenerateBackupPoms=false
update_build_timestamp "$(date -u +%Y-%m-%dT00:00:00Z)"
resolved="$(resolve_version)"
[[ "$resolved" == "$new_version" ]] || die "Resolved reactor version '${resolved}', expected '${new_version}'."
for module in "${MODULES[@]}"; do
resolved="$(resolve_version "$module")"
[[ "$resolved" == "$new_version" ]] || die "Resolved ${module} version '${resolved}', expected '${new_version}'."
done
echo "==> Verifying FeatureFramework"
./mvnw -B -ntp -Pplatform-acceptance verify
git diff --check
git add "$POM_FILE"
git commit -m "Bump version to ${new_tag} for release"
git tag --annotate "$new_tag" --message "Release ${new_tag}"
echo "Version updated locally."
echo "Next step: git push origin HEAD && git push origin ${new_tag}"