Skip to content

Commit 4d85f95

Browse files
authored
Automatically update WEEK_4 WEEK_12 versions (#2585)
This PR adds `update_version_h_cpp.sh` script The script will: - Automatically calculate `WEEK_4` and `WEEK_12` versions based on Version tag date and current date. - Bump CurrentVersion by increasing patch version by 1 This script should be executed at the beginning of the next development cycle, after performing the git tagging. This script: 1. Updates current version in `stablehlo/dialect/Version.h` ```cpp static Version getCurrentVersion() { return Version(x, y, z); } ``` New version will be (x, y, z + 1) 2. Replaces WEEK_4 and WEEK12 versions in stablehlo/dialect/Version.cpp ``` return Version(a, b, c); // WEEK_4 ANCHOR: DO NOT MODIFY return Version(m, n, p); // WEEK_12 ANCHOR: DO NOT MODIFY ``` - WEEK_4 version - The most recent git tag that was created at least 28 days ago. - WEEK_12 version - The most recent git tag that was created at least 84 days ago. ### Usage Example: ```bash $ build_tools/update_version_h_cpp.sh Next Current Version: 1, 8, 3 WEEK_4 Version: 1, 7, 6 WEEK_12 Version: 1, 5, 1 Saving /local/home/user/workspace/stablehlo/build_tools/../stablehlo/dialect/Version.h... static Version getCurrentVersion() { return Version(1, 8, 3); } Saving /local/home/user/workspace/stablehlo/build_tools/../stablehlo/dialect/Version.cpp... return Version(1, 7, 6); // WEEK_4 ANCHOR: DO NOT MODIFY return Version(1, 5, 1); // WEEK_12 ANCHOR: DO NOT MODIFY Done ``` #### Result: ```bash $ git diff diff --git a/stablehlo/dialect/Version.cpp b/stablehlo/dialect/Version.cpp index b4ea0d2..d107ba57 100644 --- a/stablehlo/dialect/Version.cpp +++ b/stablehlo/dialect/Version.cpp @@ -83,9 +83,9 @@ Version Version::fromCompatibilityRequirement( case CompatibilityRequirement::NONE: return Version::getCurrentVersion(); case CompatibilityRequirement::WEEK_4: - return Version(1, 7, 5); // WEEK_4 ANCHOR: DO NOT MODIFY + return Version(1, 7, 6); // WEEK_4 ANCHOR: DO NOT MODIFY case CompatibilityRequirement::WEEK_12: - return Version(1, 5, 0); // WEEK_12 ANCHOR: DO NOT MODIFY + return Version(1, 5, 1); // WEEK_12 ANCHOR: DO NOT MODIFY case CompatibilityRequirement::MAX: return Version::getMinimumVersion(); } diff --git a/stablehlo/dialect/Version.h b/stablehlo/dialect/Version.h index 2ea7442..a6fea6b 100644 --- a/stablehlo/dialect/Version.h +++ b/stablehlo/dialect/Version.h @@ -38,7 +38,7 @@ class Version { static FailureOr<Version> fromString(llvm::StringRef versionRef); /// Return a Version representing the current VHLO dialect version. - static Version getCurrentVersion() { return Version(1, 8, 2); } + static Version getCurrentVersion() { return Version(1, 8, 3); } /// Return a Version representing the minimum supported VHLO dialect version. static Version getMinimumVersion() { return Version(0, 9, 0); } ```
1 parent 1d011d8 commit 4d85f95

File tree

2 files changed

+126
-2
lines changed

2 files changed

+126
-2
lines changed

build_tools/update_version_h_cpp.sh

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/bash
2+
# Copyright 2024 The StableHLO Authors.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This script:
16+
# 1. Replaces current version in stablehlo/dialect/Version.h with the next
17+
# patch version
18+
# static Version getCurrentVersion() { return Version(x, y, z); }
19+
# new version will be (x, y, z + 1)
20+
# 2. Replaces WEEK_4 and WEEK12 versions in stablehlo/dialect/Version.cpp
21+
# return Version(a, b, c); // WEEK_4 ANCHOR: DO NOT MODIFY
22+
# return Version(m, n, p); // WEEK_12 ANCHOR: DO NOT MODIFY
23+
# WEEK_4 version - The most recent git tag that was created at least 28 days ago.
24+
# WEEK_12 version - The most recent git tag that was created at least 84 days ago.
25+
26+
set -o errexit
27+
set -o nounset
28+
set -o pipefail
29+
30+
script_dir="$(dirname "$(realpath "$0")")"
31+
version_h="$script_dir/../stablehlo/dialect/Version.h"
32+
version_cpp="$script_dir/../stablehlo/dialect/Version.cpp"
33+
34+
fetch_current_version() {
35+
# getCurrentVersion() { Version(X, Y, Z); }
36+
ver_str=$(grep -A1 getCurrentVersion "$version_h" | grep -o 'Version(.*[0-9])')
37+
REGEX="Version\(([0-9]+), ([0-9]+), ([0-9]+)\)"
38+
if [[ $ver_str =~ $REGEX ]]; then
39+
curr_ver=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}")
40+
else
41+
echo "Error: Could not find current version string in $version_h" >&2
42+
exit 1
43+
fi
44+
}
45+
fetch_current_version
46+
47+
# calculate next current ver (patch ver + 1)
48+
next_curr_z=$((curr_ver[2] + 1))
49+
50+
utc_time=$(date -u +%s)
51+
52+
week_4_tag=""
53+
week_12_tag=""
54+
55+
while IFS= read -r line; do
56+
# split line CSV
57+
IFS=',' read -r tag_ts tag_v <<< "$line"
58+
ts_diff=$(( (utc_time - tag_ts) / 86400 ))
59+
60+
if [ -z "$week_4_tag" ] && [ "$ts_diff" -ge 28 ]; then
61+
week_4_tag=$tag_v
62+
fi
63+
64+
if [ -z "$week_12_tag" ] && [ "$ts_diff" -ge 84 ]; then
65+
week_12_tag=$tag_v
66+
break
67+
fi
68+
done < <(git for-each-ref --sort=taggerdate --format '%(taggerdate:unix),%(refname:short)' refs/tags | tail -40 | tac)
69+
70+
if [ -z "$week_4_tag" ] || [ -z "$week_12_tag" ]; then
71+
echo "Error: WEEK_4 or WEEK_12 tag not found." >&2
72+
exit 1
73+
fi
74+
75+
week_4_tag=$(echo "$week_4_tag" | sed -n 's/.*v\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\).*/\1, \2, \3/p')
76+
week_12_tag=$(echo "$week_12_tag" | sed -n 's/.*v\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\).*/\1, \2, \3/p')
77+
78+
if [ -z "$week_4_tag" ] || [ -z "$week_12_tag" ]; then
79+
echo "Error: Unable to parse the WEEK_4 or WEEK_12 tag" >&2
80+
exit 1
81+
fi
82+
83+
echo "Next Current Version: ${curr_ver[0]}, ${curr_ver[1]}, $next_curr_z" >&2
84+
echo "WEEK_4 Version: $week_4_tag" >&2
85+
echo "WEEK_12 Version: $week_12_tag" >&2
86+
87+
# Saving Version.h values
88+
echo "Saving $version_h..." >&2
89+
90+
sed -i -E \
91+
-e "s/(static Version getCurrentVersion\(\) \{ return Version\()([0-9]+), ([0-9]+), ([0-9]+)(\); \})/\1\2, \3, $next_curr_z\5/" \
92+
"$version_h"
93+
94+
# Checking Version.h values
95+
grep "static Version getCurrentVersion()" "$version_h" >&2
96+
97+
if [ "$(grep -c "static Version getCurrentVersion() { return Version(${curr_ver[0]}, ${curr_ver[1]}, $next_curr_z); }" "$version_h")" -ne 1 ]; then
98+
echo "ERROR: getCurrentVersion() version is not correct" >&2
99+
exit 1
100+
fi
101+
102+
# Saving Version.cpp values
103+
echo "Saving $version_cpp..." >&2
104+
105+
sed -i -E \
106+
-e "s/(return Version\()([0-9]+), ([0-9]+), ([0-9]+)(\);\s+\/\/ WEEK_4 ANCHOR: DO NOT MODIFY)/\1$week_4_tag\5/" \
107+
-e "s/(return Version\()([0-9]+), ([0-9]+), ([0-9]+)(\);\s+\/\/ WEEK_12 ANCHOR: DO NOT MODIFY)/\1$week_12_tag\5/" \
108+
"$version_cpp"
109+
110+
# Checking Version.cpp values
111+
grep "WEEK_4 ANCHOR: DO NOT MODIFY" "$version_cpp" >&2
112+
grep "WEEK_12 ANCHOR: DO NOT MODIFY" "$version_cpp" >&2
113+
114+
if [ "$(grep -c -E "return Version\($week_4_tag\);\s+\/\/ WEEK_4 ANCHOR: DO NOT MODIFY" "$version_cpp")" -ne 1 ]; then
115+
echo "ERROR: WEEK_4 version is not correct" >&2
116+
exit 1
117+
fi
118+
119+
if [ "$(grep -c -E "return Version\($week_12_tag\);\s+\/\/ WEEK_12 ANCHOR: DO NOT MODIFY" "$version_cpp")" -ne 1 ]; then
120+
echo "ERROR: WEEK_12 version is not correct" >&2
121+
exit 1
122+
fi
123+
124+
echo "Done" >&2

stablehlo/dialect/Version.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ Version Version::fromCompatibilityRequirement(
8383
case CompatibilityRequirement::NONE:
8484
return Version::getCurrentVersion();
8585
case CompatibilityRequirement::WEEK_4:
86-
return Version(1, 7, 5); // Sep 26, 2024
86+
return Version(1, 7, 5); // WEEK_4 ANCHOR: DO NOT MODIFY
8787
case CompatibilityRequirement::WEEK_12:
88-
return Version(1, 5, 0); // Aug 1, 2024
88+
return Version(1, 5, 0); // WEEK_12 ANCHOR: DO NOT MODIFY
8989
case CompatibilityRequirement::MAX:
9090
return Version::getMinimumVersion();
9191
}

0 commit comments

Comments
 (0)