From 4e490a7b72a8fe5c0f3a49b84db3098c796622ed Mon Sep 17 00:00:00 2001 From: David Goffredo Date: Fri, 31 Mar 2023 08:11:46 -0400 Subject: [PATCH] version-checking release script (#27) * bin/check-version * add release script --- bin/check-version | 34 ++++++++++++++++++++++++++++++++++ bin/release | 8 ++++++++ src/datadog/version.cpp | 6 ++++-- src/datadog/version.h | 4 ++-- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100755 bin/check-version create mode 100755 bin/release diff --git a/bin/check-version b/bin/check-version new file mode 100755 index 00000000..c8b76a60 --- /dev/null +++ b/bin/check-version @@ -0,0 +1,34 @@ +#!/bin/sh + +set -e + +desired="$1" +pattern='^v[0-9]\+\.[0-9]\.[0-9]\+$' +if echo "$desired" | grep -v "$pattern" >/dev/null 2>&1; then + >&2 echo "Specified version \"$desired\" does not match the grep pattern $pattern" + exit 1 +fi + +scratch=$(mktemp -d) +version_cpp="$(dirname "$0")/../src/datadog/version.cpp" +cp "$version_cpp" "$scratch" +cp "${version_cpp%.cpp}.h" "$scratch" +>"$scratch/print_version.cpp" cat <<'END_CPP' + +#include "version.h" +#include + +int main() { + std::cout << datadog::tracing::tracer_version; +} +END_CPP + +/usr/bin/c++ -o "$scratch/print_version" "$scratch"/*.cpp +actual=$("$scratch/print_version") +rm -r "$scratch" + +if [ "$actual" != "$desired" ]; then + version_cpp="$(realpath --relative-to="$(pwd)" "$version_cpp")" + >&2 echo "Desired release version \"$desired\" is different from that in $version_cpp: \"$actual\"" + exit 1 +fi diff --git a/bin/release b/bin/release new file mode 100755 index 00000000..a089be01 --- /dev/null +++ b/bin/release @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +version="$1" +bin="$(dirname "$0")" +"$bin"/check-version "$version" || exit +gh release create "$version" --prerelease --draft diff --git a/src/datadog/version.cpp b/src/datadog/version.cpp index 4ba211ce..a4886fbb 100644 --- a/src/datadog/version.cpp +++ b/src/datadog/version.cpp @@ -3,8 +3,10 @@ namespace datadog { namespace tracing { -const char* const tracer_version = "v0.1.5"; -const char* const tracer_version_string = "[dd-trace-cpp version v0.1.5]"; +#define VERSION "v0.1.8" + +const char* const tracer_version = VERSION; +const char* const tracer_version_string = "[dd-trace-cpp version " VERSION "]"; } // namespace tracing } // namespace datadog diff --git a/src/datadog/version.h b/src/datadog/version.h index 413e3fb3..25cbd233 100644 --- a/src/datadog/version.h +++ b/src/datadog/version.h @@ -2,12 +2,12 @@ // This component provides the release version of this library. -#include "string_view.h" - namespace datadog { namespace tracing { // The release version at or before this code revision, e.g. "v0.1.1". +// That is, this code is at least as recent as `tracer_version`, but may be +// more recent. extern const char *const tracer_version; // A string literal that contains `tracer_version` but also is easier to `grep`