Automate releases (#3732)

* Test custom action with custom input

* Run test workflow on push

* Automated release configuration
This commit is contained in:
Bert Blommers 2021-03-03 09:06:22 +00:00 committed by GitHub
commit 562d0eef69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 12 deletions

View file

@ -4,6 +4,9 @@ Adapted from https://github.com/pygame/pygameweb/blob/master/pygameweb/builds/up
For updating the version from git.
__init__.py contains a __version__ field.
Update that.
If the user supplies "patch" as a CLi argument, we want to bump the existing patch version
If the user supplied the full version as a CLI argument, we want to use that version.
Otherwise,
If we are on master, we want to update the version as a pre-release.
git describe --tags
With these:
@ -22,6 +25,8 @@ import io
import os
import re
import subprocess
import sys
from packaging.version import Version
def migrate_source_attribute(attr, to_this, target_file, regex):
@ -49,7 +54,7 @@ def migrate_version(target_file, new_version):
regex = r"['\"](.*)['\"]"
migrate_source_attribute(
"__version__",
"'{new_version}'".format(new_version=new_version),
"\"{new_version}\"".format(new_version=new_version),
target_file,
regex,
)
@ -114,6 +119,15 @@ def get_version():
raise RuntimeError("Unable to find version string.")
def increase_patch_version(old_version):
"""
:param old_version: 2.0.1
:return: 2.0.2.dev
"""
v = Version(old_version)
return "{}.{}.{}.dev".format(v.major, v.minor, v.micro + 1)
def release_version_correct():
"""Makes sure the:
- prerelease verion for master is correct.
@ -142,4 +156,16 @@ def release_version_correct():
if __name__ == "__main__":
release_version_correct()
new_version = None
if len(sys.argv) == 1:
release_version_correct()
elif len(sys.argv) == 2:
for _, arg in enumerate(sys.argv):
new_version = arg
if new_version == "patch":
new_version = increase_patch_version(get_version())
initpy = os.path.abspath("moto/__init__.py")
migrate_version(initpy, new_version)
else:
print("Invalid usage. Supply 0 or 1 arguments. "
"Argument can be either a version '1.2.3' or 'patch' if you want to increase the patch-version (1.2.3 -> 1.2.4.dev)")