Skip to content

Commit

Permalink
Added script to prepare release PRs (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
owais authored Jun 1, 2021
1 parent 0c41211 commit 2255f66
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 62 deletions.
14 changes: 7 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## [Unreleased]

### Added

Expand All @@ -20,14 +20,14 @@
- Deprecated `splunk-py-trace` and `splunk-py-trace-bootstrap` commands.
[#79](https://github.com/signalfx/splunk-otel-python/pull/79)

## 0.14.0 (05-20-2021)
## [0.14.0] - 05-20-2021

### Changed

- Renamed `exporters` argument `span_exporter_factories` for `start_tracing()` function.
[#71](https://github.com/signalfx/splunk-otel-python/pull/71)

## 0.13.0 (05-17-2021)
## [0.13.0] - 05-17-2021

### Added

Expand Down Expand Up @@ -62,14 +62,14 @@
Please use `OTEL_SERVICE_NAME=<my-service-name>` instead.
[#57](https://github.com/signalfx/splunk-otel-python/pull/57)

## 0.12.0 (04-21-2021)
## [0.12.0] - 04-21-2021

### Added

- Added support trace response headers.
[#44](https://github.com/signalfx/splunk-otel-python/pull/44)

## 0.11.0 (03-29-2021)
## [0.11.0] - 03-29-2021

### Added

Expand All @@ -93,7 +93,7 @@
[#34](https://github.com/signalfx/splunk-otel-python/pull/34)


## 0.10.0 (03-27-2021)
## [0.10.0] - 03-27-2021

### Changed

Expand All @@ -110,7 +110,7 @@
- `start_tracing()` now accepts an argument called `endpoint` instead of `url`.
([#29](https://github.com/signalfx/splunk-otel-python/pull/29))

## 0.9.0 (03-13-2021)
## [0.9.0] - 03-13-2021

### Changed

Expand Down
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,27 @@ make develop DEV_ENV=/path/to/test/project/venv
This will install an editable version of the package in the test project. Any
changes made to the library will automatically reflect in the test project
without the need to install the package again.

## Releasing

Assuming the latest version is 0.14.0 and you want to releaase 0.15.0,

1. Run `make prepare-release VERSION=0.15.0`
This will bump the version where neccesary, update the changelog and commit
all the changes to a new branch with name `release/v0.15.0`.
2. Submit a GitHub PR for the new branch and merge it once it is approved.
3. Switch to the main branch and pull the newly merged changes. Make sure you have the same commit
checked out that was auto-generated in step 1.
4. Tag the commit with the version number
```shell
git tag -s v0.15.0
```
5. Push the new tag to bot GitHub and GitLab
```shell
git push github v0.15.0
git push gitlab v0.15.0
```
This will kickoff a Gitlab release job which will publish packages to pypi.org
and create a new GitHub release.
6. You should review the GitHub release and add
additional information to it if required.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DEV_VENV?=""
VERSION?=""

.PHONY: deps
deps:
Expand Down Expand Up @@ -79,3 +80,14 @@ test-with-cov:
.PHONY: create-github-release
ci-create-github-release:
poetry run python scripts/create_gh_release.py --dry-run=false

.PHONY: prepare-release
prepare-release:
ifeq ($(VERSION),"")
@echo "Usage: make prepare-release VERSION=<version_number>"
else
git checkout -B release/v$(VERSION)
python scripts/prepare_release.py --version $(VERSION)
git add -A .
git commit -m"Preparing release v$(VERSION)"
endif
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
</p>

<p align="center">
<a href="https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.2.0">
<img alt="OpenTelemetry Python Version" src="https://img.shields.io/badge/otel-1.2.0-blueviolet?style=for-the-badge">
</a>
<span class="otel-version-badge"><a href="https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.2.0"><img alt="OpenTelemetry Python Version" src="https://img.shields.io/badge/otel-1.2.0-blueviolet?style=for-the-badge"/></a></span>
<a href="https://github.com/signalfx/splunk-otel-python/releases">
<img alt="GitHub release (latest SemVer)" src="https://img.shields.io/github/v/release/signalfx/splunk-otel-python?style=for-the-badge">
</a>
Expand Down Expand Up @@ -41,9 +39,7 @@
</p>

---

The documentation below refers to the in development version of this package. Docs for the latest version ([v0.14.0](https://github.com/signalfx/splunk-otel-python/releases/tag/v0.14.0)) can be found [here](https://github.com/signalfx/splunk-otel-python/blob/v0.14.0/README.md).

<span class="docs-version-header">The documentation below refers to the in development version of this package. Docs for the latest version ([v0.14.0](https://github.com/signalfx/splunk-otel-python/releases/tag/v0.14.0)) can be found [here](https://github.com/signalfx/splunk-otel-python/blob/v0.14.0/README.md).</span>
---

# Splunk Distribution of OpenTelemetry Python
Expand Down Expand Up @@ -160,12 +156,12 @@ Documentation on how to manually instrument a Python application is available
To extend the instrumentation with the OpenTelemetry Instrumentation for Python,
you have to use a compatible API version.

<!-- IMPORTANT: do not change comments or break those lines below -->
The Splunk Distribution of OpenTelemetry Python version <!--SPLUNK_VERSION-->0.12.0<!--SPLUNK_VERSION--> is compatible
The Splunk Distribution of OpenTelemetry Python version <span class="splunk-version">0.14.0</span> is compatible
with:

* OpenTelemetry API version <!--OTEL_VERSION-->1.2.0<!--OTEL_VERSION-->
* OpenTelemetry Instrumentation for Python version <!--OTEL_INSTRUMENTATION_VERSION-->0.21b0<!--OTEL_INSTRUMENTATION_VERSION-->
* OpenTelemetry API version <span class="otel-api-version">1.2.0</span>
* OpenTelemetry SDK version <span class="otel-sdk-version">1.2.0</span>
* OpenTelemetry Instrumentation for Python version <span class="otel-instrumentation-version">0.21b0</span>

## Correlating traces with logs

Expand Down
62 changes: 17 additions & 45 deletions scripts/create_gh_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import subprocess
from os import path

import click
import keepachangelog
from github_release import gh_release_create
from splunk_packaging import changelog_path, get_versions, root_path

root = path.dirname(path.abspath(path.dirname(__file__)))
pyproject_path = path.join(root, "pyproject.toml")
changelog_path = path.join(root, "CHANGELOG.md")
relase_template_path = path.join(root, "scripts", "gh_release_template.md")
artifacts_path = path.join(root, "dist/*")
relase_template_path = path.join(root_path, "scripts", "gh_release_template.md")
artifacts_path = path.join(root_path, "dist/*")


def _get_package_version(package):
return (
subprocess.check_output(
["poetry", "show", package], cwd=root, universal_newlines=True
)
.split("\n")[1]
.split()[2]
)


def _get_otel_versions():
return {
"api": _get_package_version("opentelemetry-api"),
"sdk": _get_package_version("opentelemetry-sdk"),
"instrumentation": _get_package_version("opentelemetry-instrumentation"),
}


def _get_version() -> str:
return subprocess.check_output(
["poetry", "version"], cwd=root, universal_newlines=True
).split()[1]


def _render_changelog(version):
def render_changelog(version):
return keepachangelog.to_raw_dict(changelog_path).get(version, {}).get("raw", "")


def _render_release_notes(**kwargs):
def render_release_notes(**kwargs):
with open(relase_template_path, "r") as tmpl:
notes = tmpl.read().format(**kwargs)
return notes


def _print_release_details(**kwargs):
def print_release_details(**kwargs):
print(
"""
Run with --dry-run=false to create the following release
Expand All @@ -85,28 +58,27 @@ def _print_release_details(**kwargs):
help="Print out the release details instead of actually creating one",
)
def main(dry_run):
version = _get_version()
otel_versions = _get_otel_versions()

changelog = _render_changelog(version)
release_notes = _render_release_notes(
version=version,
api_version=otel_versions["api"],
sdk_version=otel_versions["sdk"],
instrumentation_version=otel_versions["instrumentation"],
versions = get_versions()

changelog = render_changelog(versions.distro)
release_notes = render_release_notes(
version=versions.distro,
api_version=versions.api,
sdk_version=versions.sdk,
instrumentation_version=versions.instrumentation,
changelog=changelog,
)

git_tag = "v{}".format(version)
git_tag = "v{}".format(versions.distro)

action = _print_release_details
action = print_release_details
if not dry_run:
action = gh_release_create
action(
repo_name="signalfx/splunk-otel-python",
tag_name=git_tag,
publish=True,
name=version,
name=versions.distro,
body=release_notes,
asset_pattern=artifacts_path,
)
Expand Down
82 changes: 82 additions & 0 deletions scripts/prepare_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from os import path

import click
import keepachangelog
from splunk_packaging import bump_version, changelog_path, get_versions, root_path

readme_path = path.join(root_path, "README.md")
otel_badge_span = (
'<span class="otel-version-badge">'
'<a href="https://github.com/open-telemetry/opentelemetry-python/releases/tag/v{0}">'
'<img alt="OpenTelemetry Python Version" '
'src="https://img.shields.io/badge/otel-{0}-blueviolet?style=for-the-badge"/>'
"</a></span>"
)
docs_version_span = (
'<span class="docs-version-header">The documentation below refers to the '
"in development version of this package. Docs for the latest version "
"([v{0}](https://github.com/signalfx/splunk-otel-python/releases/tag/v{0})) "
"can be found [here](https://github.com/signalfx/splunk-otel-python/blob"
"/v{0}/README.md).</span>"
)
splunk_version_span = '<span class="splunk-version">{0}</span>'
otel_api_version_span = '<span class="otel-api-version">{0}</span>'
otel_sdk_version_span = '<span class="otel-sdk-version">{0}</span>'
otel_instrumentation_version_span = (
'<span class="otel-instrumentation-version">{0}</span>'
)
regexp = '<span class="{0}">.*</span>'


def update_docs(versions):
variables = {
"splunk-version": splunk_version_span.format(versions.distro),
"otel-api-version": otel_api_version_span.format(versions.api),
"otel-sdk-version": otel_sdk_version_span.format(versions.sdk),
"otel-instrumentation-version": otel_instrumentation_version_span.format(
versions.instrumentation
),
"docs-version-header": docs_version_span.format(versions.distro),
"otel-version-badge": otel_badge_span.format(versions.sdk),
}

markdown = ""
with open(readme_path, "r") as readme:
markdown = readme.read()

for name, value in variables.items():
markdown = re.sub(regexp.format(name), value, markdown)

with open(readme_path, "w") as readme:
readme.write(markdown)


@click.command()
@click.option(
"--version",
help="New version number that you'd like to release",
)
def main(version):
bump_version(version)
versions = get_versions()
update_docs(versions)
keepachangelog.release(changelog_path, versions.distro)


if __name__ == "__main__":
main() # pylint: disable=E1120
51 changes: 51 additions & 0 deletions scripts/splunk_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import subprocess
from collections import namedtuple
from os import path

Versions = namedtuple("Versions", ("api", "sdk", "instrumentation", "distro"))

root_path = path.dirname(path.abspath(path.dirname(__file__)))
changelog_path = path.join(root_path, "CHANGELOG.md")


def bump_version(version):
subprocess.run(["poetry", "version", version], cwd=root_path, check=True)


def get_package_version(package):
return (
subprocess.check_output(
["poetry", "show", package], cwd=root_path, universal_newlines=True
)
.split("\n")[1]
.split()[2]
)


def get_distro_version() -> str:
return subprocess.check_output(
["poetry", "version"], cwd=root_path, universal_newlines=True
).split()[1]


def get_versions():
return Versions(
api=get_package_version("opentelemetry-api"),
sdk=get_package_version("opentelemetry-sdk"),
instrumentation=get_package_version("opentelemetry-instrumentation"),
distro=get_distro_version(),
)

0 comments on commit 2255f66

Please sign in to comment.