Skip to content

Commit

Permalink
[SDK] Simplify SDK version
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Jun 6, 2023
1 parent 600bd30 commit d980e8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
27 changes: 11 additions & 16 deletions buildscripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ ! -w "$(pwd)/sdk/src/version/version.cc" && ! -w "$(pwd)/api/include/open
exit 1
fi

# format: "v<MAJOR>.<MINOR>.<PATCH>-<PRERELEASE>+<BUILDMETADATA>-<NUMBER_OF_NEW_COMMITS>-g<LAST_COMMIT_HASH>""
# format: "v<MAJOR>.<MINOR>.<PATCH>-<PRERELEASE>+<BUILDMETADATA>-<NUMBER_OF_NEW_COMMITS>-g<LAST_COMMIT_HASH>"
semver_regex="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-([0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*))?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?-([0-9]+)-g([0-9|a-z]+)$"
git_tag=$(git describe --tags --long 2>/dev/null) || true
if [[ ! -z $git_tag ]] && [[ $git_tag =~ $semver_regex ]]; then
Expand All @@ -22,7 +22,7 @@ if [[ ! -z $git_tag ]] && [[ $git_tag =~ $semver_regex ]]; then
count_new_commits="${BASH_REMATCH[9]}"
latest_commit_hash="${BASH_REMATCH[10]}"
if [[ -z ${major} ]] || [[ -z ${minor} ]] || [[ -z ${patch} ]] || [[ -z ${count_new_commits} ]] || [[ -z ${latest_commit_hash} ]]; then
echo "Error: Incorrect tag format recevived. Exiting.."
echo "Error: Incorrect tag format received. Exiting.."
exit 1
fi
else
Expand All @@ -38,9 +38,8 @@ if [[ -z ${latest_commit_hash} ]]; then
exit 1
fi

branch="$(git rev-parse --abbrev-ref HEAD)"
short_version="${major}.${minor}.${patch}"
full_version="${short_version}-${pre_release}-${build_metadata}-${count_new_commits}-${branch}-${latest_commit_hash}"
full_version="${short_version}-${pre_release}-${build_metadata}"

# Update api version.h
sed -i "/^\#define OPENTELEMETRY_VERSION /c\#define OPENTELEMETRY_VERSION \"${short_version}\"" "$(pwd)/api/include/opentelemetry/version.h"
Expand All @@ -64,18 +63,14 @@ namespace sdk
{
namespace version
{
const int major_version = ${major};
const int minor_version = ${minor};
const int patch_version = ${patch};
const char *pre_release = "${pre_release}";
const char *build_metadata = "${build_metadata}";
const int count_new_commits = ${count_new_commits};
const char *branch = "${branch}";
const char *commit_hash = "${latest_commit_hash}";
const char *short_version = "${short_version}";
const char *full_version =
"${full_version}";
const char *build_date = "$(date -u)";
const int major_version = ${major};
const int minor_version = ${minor};
const int patch_version = ${patch};
const char *pre_release = "${pre_release}";
const char *build_metadata = "${build_metadata}";
const char *short_version = "${short_version}";
const char *full_version = "${full_version}";
const char *build_date = "$(date -u)";
} // namespace version
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
Expand Down
3 changes: 0 additions & 3 deletions sdk/include/opentelemetry/sdk/version/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ extern const int minor_version;
extern const int patch_version;
extern const char *pre_release;
extern const char *build_metadata;
extern const int count_new_commits;
extern const char *branch;
extern const char *commit_hash;
extern const char *short_version;
extern const char *full_version;
extern const char *build_date;
Expand Down
20 changes: 8 additions & 12 deletions sdk/src/version/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ namespace sdk
{
namespace version
{
const int major_version = 1;
const int minor_version = 9;
const int patch_version = 1;
const char *pre_release = "NONE";
const char *build_metadata = "NONE";
const int count_new_commits = 22;
const char *branch = "make_release_1.9.1";
const char *commit_hash = "5592180d539b59c4e8293bc927f5a6431fcbacdf";
const char *short_version = "1.9.1";
const char *full_version =
"1.9.1-NONE-NONE-22-make_release_1.9.1-5592180d539b59c4e8293bc927f5a6431fcbacdf";
const char *build_date = "Fri 26 May 2023 07:14:07 AM UTC";
const int major_version = 1;
const int minor_version = 9;
const int patch_version = 1;
const char *pre_release = "NONE";
const char *build_metadata = "NONE";
const char *short_version = "1.9.1";
const char *full_version = "1.9.1-NONE-NONE";
const char *build_date = "Fri 26 May 2023 07:14:07 AM UTC";
} // namespace version
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

0 comments on commit d980e8b

Please sign in to comment.