Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pypi-release git tags automation #88

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ jobs:
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
- name: Install GitPython and cloudevents for pypi_packaging
run: pip install -U -r requirements/publish.txt
- name: Create Tag
run: python pypi_packaging.py
20 changes: 14 additions & 6 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
# Releasing CloudEvents SDK for Python

This repository is configured to automatically publish the corresponding [PyPI
package](https://pypi.org/project/cloudevents/) via GitHub Actions.
package](https://pypi.org/project/cloudevents/) and GitHub Tag via GitHub Actions.

To release a new CloudEvents SDK, contributors should bump the `version` in
[setup.py](setup.py)) to reflect the new release version. On merge, the action
To release a new CloudEvents SDK, contributors should bump `__version__` in
[cloudevents](cloudevents/__init__.py) to reflect the new release version. On merge, the action
will automatically build and release to PyPI using
[this PyPI GitHub Action](https://github.com/pypa/gh-action-pypi-publish). This
action gets called on all pushes to master (such as a version branch being merged
into master), but only releases a new version when the version number has changed.
into master), but only releases a new version when the version number has changed. Note,
this action assumes pushes to master are version updates. Consequently,
[pypi-release.yml](.github/workflows/pypi-release.yml) will fail if you attempt to
push to master without updating `__version__` in
[cloudevents](cloudevents/__init__.py) so don't forget to do so.

After a version update is merged, maintainers are expected to manually create a
corresponding tag/release.
After a version update is merged, the script [pypi_packaging.py](pypi_packaging.py)
will create a GitHub tag for the new cloudevents version using `__version__`.
The script fails if `__version__` and the local pypi version for
cloudevents are out of sync. For this reason, [pypi-release.yml](.github/workflows/pypi-release.yml)
first must upload the new cloudevents pypi package, and then download the recently updated pypi
cloudevents package for [pypi_packaging.py](pypi_packaging.py) not to fail.

View the GitHub workflow [pypi-release.yml](.github/workflows/pypi-release.yml) for
more information.
1 change: 1 addition & 0 deletions cloudevents/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.0.0"
57 changes: 57 additions & 0 deletions pypi_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import codecs

import pkg_resources
import os


def read(rel_path):
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, rel_path), "r") as fp:
return fp.read()


def get_version(rel_path):
for line in read(rel_path).splitlines():
if line.startswith("__version__"):
delim = '"' if '"' in line else "'"
return line.split(delim)[1]
else:
raise RuntimeError("Unable to find version string.")


# FORMAT: 1.x.x
pypi_config = {
"version_target": get_version("cloudevents/__init__.py"),
"package_name": "cloudevents",
}


def createTag():
from git import Repo

# Get local pypi cloudevents version
published_pypi_version = pkg_resources.get_distribution(
pypi_config["package_name"]
).version

# Ensure pypi and local package versions match
if pypi_config["version_target"] == published_pypi_version:
# Create local git tag
repo = Repo(os.getcwd())
repo.create_tag(pypi_config["version_target"])

# Push git tag to remote master
origin = repo.remote()
origin.push(pypi_config["version_target"])

else:
# PyPI publish likely failed
print(
f"Expected {pypi_config['package_name']}=={pypi_config['version_target']} "
f"but found {pypi_config['package_name']}=={published_pypi_version}"
)
exit(1)


if __name__ == "__main__":
createTag()
63 changes: 0 additions & 63 deletions release_doc.md

This file was deleted.

2 changes: 2 additions & 0 deletions requirements/publish.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GitPython==3.1.7
cloudevents
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from pypi_packaging import pypi_config

import setuptools
from setuptools import setup, find_packages

import pathlib


here = pathlib.Path(__file__).parent.resolve()
long_description = (here / "README.md").read_text(encoding="utf-8")

setuptools.setup(
name="cloudevents",
setup(
name=pypi_config["package_name"],
summary="CloudEvents SDK Python",
long_description_content_type="text/markdown",
long_description=long_description,
Expand All @@ -38,7 +39,6 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
package_dir={"": "cloudevents"},
packages=["http", "sdk"],
version="1.0.0",
packages=find_packages(exclude=["cloudevents.tests"]),
version=pypi_config["version_target"],
cumason123 marked this conversation as resolved.
Show resolved Hide resolved
)
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ usedevelop = True
deps =
-r{toxinidir}/requirements/test.txt
-r{toxinidir}/requirements/docs.txt
-r{toxinidir}/requirements/publish.txt
setenv =
PYTESTARGS = -v -s --tb=long --cov=cloudevents
commands = pytest {env:PYTESTARGS} {posargs}
Expand Down