]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/buildscripts/pre-commit
3 # Copyright The OpenTelemetry Authors
4 # SPDX-License-Identifier: Apache-2.0
8 if [[ ! -w "$(pwd)/sdk/src/version/version.cc" && ! -w "$(pwd)/api/include/opentelemetry/version.h" ]]; then
9 echo "Error: Version file(s) are not writable. Check permissions and try again."
13 # format: "v<MAJOR>.<MINOR>.<PATCH>-<PRERELEASE>+<BUILDMETADATA>-<NUMBER_OF_NEW_COMMITS>-g<LAST_COMMIT_HASH>""
14 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]+)$"
15 git_tag
=$
(git describe
--tags --long 2>/dev
/null
) || true
16 if [[ ! -z $git_tag ]] && [[ $git_tag =~
$semver_regex ]]; then
17 major
="${BASH_REMATCH[1]}"
18 minor
="${BASH_REMATCH[2]}"
19 patch="${BASH_REMATCH[3]}"
20 pre_release
="${BASH_REMATCH[5]}" #optional
21 build_metadata
="${BASH_REMATCH[7]}" #optional
22 count_new_commits
="${BASH_REMATCH[9]}"
23 latest_commit_hash
="${BASH_REMATCH[10]}"
24 if [[ -z ${major} ]] || [[ -z ${minor} ]] || [[ -z ${patch} ]] || [[ -z ${count_new_commits} ]] || [[ -z ${latest_commit_hash} ]]; then
25 echo "Error: Incorrect tag format recevived. Exiting.."
29 major
=0 && minor
=0 && patch=0 && pre_release
="" && build_metadata
="" && count_new_commits
=0
30 latest_commit_hash
="$(git rev-parse --short HEAD)"
32 : ${pre_release:="NONE"} # use default string if not defined
33 : ${build_metadata:="NONE"} # use default string if not defined
34 latest_commit_hash
=$
(git rev-parse
${latest_commit_hash}) # get full hash from short
36 if [[ -z ${latest_commit_hash} ]]; then
37 echo "Error: Incorrect short hash received. Exiting.."
41 branch
="$(git rev-parse --abbrev-ref HEAD)"
42 short_version
="${major}.${minor}.${patch}"
43 full_version
="${short_version}-${pre_release}-${build_metadata}-${count_new_commits}-${branch}-${latest_commit_hash}"
45 # Update api version.h
46 sed -i "/^\#define OPENTELEMETRY_VERSION/c\#define OPENTELEMETRY_VERSION \"${short_version}\"" "$(pwd)/api/include/opentelemetry/version.h"
47 git add
"$(pwd)/api/include/opentelemetry/version.h"
49 # Update sdk version.cc
50 cat > "$(pwd)/sdk/src/version/version.cc" <<END
51 // Please DONOT touch this file.
52 // Any changes done here would be overwritten by pre-commit git hook
54 #include "opentelemetry/sdk/version/version.h"
56 OPENTELEMETRY_BEGIN_NAMESPACE
61 const int MAJOR_VERSION = ${major};
62 const int MINOR_VERSION = ${minor};
63 const int PATCH_VERSION = ${patch};
64 const char* PRE_RELEASE = "${pre_release}";
65 const char* BUILD_METADATA = "${build_metadata}";
66 const int COUNT_NEW_COMMITS = ${count_new_commits};
67 const char* BRANCH = "${branch}";
68 const char* COMMIT_HASH = "${latest_commit_hash}";
69 const char* SHORT_VERSION = "${short_version}";
70 const char* FULL_VERSION = "${full_version}";
71 const char* BUILD_DATE = "$(date -u)";
74 OPENTELEMETRY_END_NAMESPACE
76 git add
"$(pwd)/sdk/src/version/version.cc"
78 # Update documentation version
79 sed -i "/^release =/crelease = \"${short_version}\"" "$(pwd)/docs/public/conf.py"
80 git add
"$(pwd)/docs/public/conf.py"