Debian Codegraph @

buildscripts/pre-commit

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 # Copyright The OpenTelemetry Authors
4 # SPDX-License-Identifier: Apache-2.0
5
6 set -eo pipefail
7
8 if [[ ! -w "$(pwd)/sdk/src/version/version.cc" && ! -w "$(pwd)/api/include/opentelemetry/version.h" ]]; then
9 echoscip-shell system . . echo. "Error: Version file(s) are not writable. Check permissions and try again."
10 exit 1
11 fi
12
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=$(gitscip-shell system . . git. describe --tags --long 2>/dev/nullscip-shell filesystem . . `/dev/null`.) || truescip-shell system . . 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 echoscip-shell system . . echo. "Error: Incorrect tag format received. Exiting.."
26 exit 1
27 fi
28 else
29 major=0 && minor=0 && patch=0 && pre_release="" && build_metadata="" && count_new_commits=0
30 latest_commit_hash="$(gitscip-shell system . . git. rev-parse --short HEAD)"
31 fi
32 : ${pre_release:="NONE"} # use default string if not defined
33 : ${build_metadata:="NONE"} # use default string if not defined
34 latest_commit_hash=$(gitscip-shell system . . git. rev-parse ${latest_commit_hash}) # get full hash from short
35
36 if [[ -z ${latest_commit_hash} ]]; then
37 echoscip-shell system . . echo. "Error: Incorrect short hash received. Exiting.."
38 exit 1
39 fi
40
41 short_version="${major}.${minor}.${patch}"
42 full_version="${short_version}-${pre_release}-${build_metadata}"
43
44 # Update api version.h
45 sedscip-shell system . . sed. -i "/^\#define OPENTELEMETRY_VERSION /c\#define OPENTELEMETRY_VERSION \"${short_version}\"" "$(pwdscip-shell system . . pwd.)/api/include/opentelemetry/version.h"
46 sedscip-shell system . . sed. -i "/^\#define OPENTELEMETRY_VERSION_MAJOR /c\#define OPENTELEMETRY_VERSION_MAJOR ${major}" "$(pwdscip-shell system . . pwd.)/api/include/opentelemetry/version.h"
47 sedscip-shell system . . sed. -i "/^\#define OPENTELEMETRY_VERSION_MINOR /c\#define OPENTELEMETRY_VERSION_MINOR ${minor}" "$(pwdscip-shell system . . pwd.)/api/include/opentelemetry/version.h"
48 sedscip-shell system . . sed. -i "/^\#define OPENTELEMETRY_VERSION_PATCH /c\#define OPENTELEMETRY_VERSION_PATCH ${patch}" "$(pwdscip-shell system . . pwd.)/api/include/opentelemetry/version.h"
49 gitscip-shell system . . git. add "$(pwdscip-shell system . . pwd.)/api/include/opentelemetry/version.h"
50
51 # Update sdk version.cc
52 catscip-shell system . . cat. > "$(pwdscip-shell system . . pwd.)/sdk/src/version/version.cc" <<END
53 // Copyright The OpenTelemetry Authors
54 // SPDX-License-Identifier: Apache-2.0
55
56 // Please DONOT touch this file.
57 // Any changes done here would be overwritten by pre-commit git hook
58
59 #include "opentelemetry/sdk/version/version.h"
60
61 OPENTELEMETRY_BEGIN_NAMESPACE
62 namespace sdk
63 {
64 namespace version
65 {
66 const int major_version = ${major};
67 const int minor_version = ${minor};
68 const int patch_version = ${patch};
69 const char *pre_release = "${pre_release}";
70 const char *build_metadata = "${build_metadata}";
71 const char *short_version = "${short_version}";
72 const char *full_version = "${full_version}";
73 const char *build_date = "$(datescip-shell system . . date. -u)";
74 } // namespace version
75 } // namespace sdk
76 OPENTELEMETRY_END_NAMESPACE
77 END
78 gitscip-shell system . . git. add "$(pwdscip-shell system . . pwd.)/sdk/src/version/version.cc"
79
80 # Update documentation version
81 sedscip-shell system . . sed. -i "/^release =/crelease = \"${short_version}\"" "$(pwdscip-shell system . . pwd.)/docs/public/conf.py"
82 gitscip-shell system . . git. add "$(pwdscip-shell system . . pwd.)/docs/public/conf.py"