-
Notifications
You must be signed in to change notification settings - Fork 58
pypi-release git tags automation #88
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
Merged
cumason123
merged 13 commits into
cloudevents:v1.0.0-dev
from
cumason123:create-git-tag-automation
Aug 11, 2020
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d55752b
added pypi_packaging
d4b21da
reverted pypi-release
783fa63
added pypi_package workflow
f804a1f
added gitpython dependency
d77ca25
added git import in createTag function
a0da1a3
Updated RELEASING.md and implemented pypi_config in pypi_packaging.pg
d5aead7
Fixed some docs
bd03dcc
Update .github/workflows/pypi-release.yml
cumason123 6738d93
added __version__
31c0922
lint change
ab0173c
reinstalling cloudevents in workflow
af73fbb
added cloudevents to publish.txt
fc5ac2f
removed old release_doc
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "1.0.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GitPython==3.1.7 | ||
cloudevents |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.