-
Notifications
You must be signed in to change notification settings - Fork 36
add release script and workflow #41
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
Merged
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion
2
.github/workflows/build_release.yml → .github/workflows/build_publish.yml
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,4 +1,4 @@ | ||
name: Build and Release | ||
name: Build and Publish | ||
|
||
on: | ||
pull_request: | ||
|
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,26 @@ | ||
name: Release | ||
|
||
on: | ||
schedule: | ||
# every weekday at 9:00 AM | ||
- cron: '0 9 * * 1-5' | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Setup Python 3.7 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
- name: Install Dependencies | ||
run: pip install tox | ||
- name: Unit Tests | ||
run: tox -e py37 -- tests/unit | ||
env: | ||
AWS_DEFAULT_REGION: us-west-2 | ||
- name: Create Release | ||
run: tox -e release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Invoke development tasks. | ||
""" | ||
from subprocess import check_output | ||
from version import next_version_from_current_version | ||
from subject_parser import SubjectParser | ||
from release_manager import ReleaseManager | ||
|
||
|
||
def recent_changes_to_src(last_version): | ||
stdout = check_output(["git", "log", "{}..HEAD".format(last_version), "--name-only", "--pretty=format: master"]) | ||
stdout = stdout.decode("utf-8") | ||
lines = stdout.splitlines() | ||
src_lines = filter(lambda l: l.startswith("src"), lines) | ||
return src_lines | ||
|
||
|
||
def get_changes(last_version): | ||
stdout = check_output(["git", "log", "{}..HEAD".format(last_version), "--pretty=format:%s"]) | ||
stdout = stdout.decode("utf-8") | ||
changes = list(map(lambda line: line.strip(), stdout.splitlines())) | ||
print(f"{len(changes)} changes since last release {last_version}") | ||
return changes | ||
|
||
|
||
def get_next_version(last_version, increment_type): | ||
# remove the 'v' prefix | ||
last_version = last_version[1:] | ||
return next_version_from_current_version(last_version, increment_type) | ||
|
||
|
||
def get_version_increment_type(last_version): | ||
stdout = check_output(["git", "log", "{}..HEAD".format(last_version), "--pretty=format:%s"]) | ||
stdout = stdout.decode("utf-8") | ||
subjects = stdout.splitlines() | ||
parsed_subjects = SubjectParser(subjects) | ||
return parsed_subjects.increment_type() | ||
|
||
|
||
def release(): | ||
"""Creates a github release.""" | ||
|
||
# get the last release tag | ||
stdout = check_output(["git", "describe", "--abbrev=0", "--tags"]) | ||
stdout = stdout.decode("utf-8") | ||
last_version = stdout.strip() | ||
|
||
if not recent_changes_to_src(last_version): | ||
print("Nothing to release.") | ||
return | ||
|
||
changes = get_changes(last_version) | ||
|
||
increment_type = get_version_increment_type(last_version) | ||
|
||
next_version = get_next_version(last_version, increment_type) | ||
|
||
manager = ReleaseManager(str(next_version), changes) | ||
manager.create_release() | ||
|
||
|
||
def main(): | ||
release() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,26 @@ | ||
from github import Github | ||
import os | ||
from pathlib import Path | ||
|
||
|
||
class ReleaseManager: | ||
def __init__(self, version, changes): | ||
self._version = version | ||
self._changes = changes | ||
self._token = os.getenv("GITHUB_TOKEN") | ||
self._repo = os.getenv("GITHUB_REPOSITORY") | ||
if not self._token or not self._repo: | ||
raise ValueError("Missing required environment variables.") | ||
|
||
def create_release(self): | ||
tag = "v" + self._version | ||
name = f"Sagemaker Experiment SDK {tag}" | ||
template_text = Path(__file__).parent.joinpath("release_template.rst").read_text(encoding="UTF-8") | ||
change_list_content = "\n".join(list(map(lambda c: f"- {c}", self._changes))) | ||
message = template_text.format(version=tag, changes=change_list_content) | ||
g = Github(self._token) | ||
repo = g.get_repo(self._repo) | ||
# keep draft=True release script manually verified working | ||
repo.create_git_release(tag=tag, name=name, message=message, draft=True, prerelease=False) | ||
print(f"Created release {name}") | ||
print(f"See it at https://github.com/{self._repo}/releases") |
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,8 @@ | ||
SageMaker Experiments {version} release! | ||
|
||
Changes: | ||
{changes} | ||
|
||
You can upgrade from PyPI via: | ||
|
||
pip install -U sagemaker-experiments |
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,69 @@ | ||
import logging | ||
import re | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SubjectParser: | ||
""" | ||
Parses git commit subject lines to determine the type of change (breaking, feature, fix, etc...) | ||
""" | ||
|
||
# order must be aligned with associated increment_type (major...post) | ||
_CHANGE_TYPES = ["breaking", "deprecation", "feature", "fix", "documentation", "infrastructure"] | ||
|
||
_PARSE_SUBJECT_REGEX = re.compile( | ||
r""" | ||
(?:(?P<label>break(?:ing)?|feat(?:ure)?|depr(?:ecation)?|change|fix|doc(?:umentation)?)\s*:)? | ||
""", | ||
re.VERBOSE | re.IGNORECASE, | ||
) | ||
|
||
_CANONICAL_LABELS = { | ||
"break": "breaking", | ||
"feat": "feature", | ||
"depr": "deprecation", | ||
"change": "fix", | ||
"doc": "documentation", | ||
} | ||
|
||
_CHANGE_TO_INCREMENT_TYPE_MAP = { | ||
"breaking": "major", | ||
"feature": "minor", | ||
"deprecation": "minor", | ||
"fix": "patch", | ||
"change": "patch", | ||
"documentation": "patch", | ||
} | ||
|
||
_DEFAULT_LABEL = "fix" | ||
|
||
def __init__(self, subjects): | ||
self._groups = {} | ||
self._add_subjects(subjects) | ||
|
||
def _add_subjects(self, subjects): | ||
for subject in subjects: | ||
self._parse_subject(subject) | ||
|
||
def _parse_subject(self, subject): | ||
label = None | ||
match = SubjectParser._PARSE_SUBJECT_REGEX.search(subject) | ||
|
||
if match: | ||
label = match.group("label") or SubjectParser._DEFAULT_LABEL | ||
label = SubjectParser._CANONICAL_LABELS.get(label, label) | ||
else: | ||
print(f"no match {subject}") | ||
label = SubjectParser._DEFAULT_LABEL | ||
|
||
if label in self._groups: | ||
self._groups[label].append(subject) | ||
|
||
def increment_type(self): | ||
for change_type in SubjectParser._CHANGE_TYPES: | ||
if change_type in self._groups: | ||
return SubjectParser._CHANGE_TO_INCREMENT_TYPE_MAP[change_type] | ||
|
||
return "patch" |
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,56 @@ | ||
import re | ||
|
||
|
||
# a subset of PEP 440 | ||
_VERSION_REGEX = re.compile( | ||
r""" | ||
^\s* | ||
v? | ||
(?P<major>\d+) | ||
(?:\.(?P<minor>\d+))? | ||
(?:\.(?P<patch>\d+))? | ||
\s*$ | ||
""", | ||
re.VERBOSE | re.IGNORECASE, | ||
) | ||
|
||
|
||
class Version: | ||
""" | ||
Represents a major.minor.patch version string | ||
""" | ||
|
||
def __init__(self, major, minor=0, patch=0): | ||
self.major = major | ||
self.minor = minor | ||
self.patch = patch | ||
|
||
self.tag = f"v{str(self)}" | ||
|
||
def __str__(self): | ||
parts = [str(x) for x in [self.major, self.minor, self.patch]] | ||
|
||
return ".".join(parts).lower() | ||
|
||
def increment(self, increment_type): | ||
incr = None | ||
if increment_type == "major": | ||
incr = Version(self.major + 1) | ||
elif increment_type == "minor": | ||
incr = Version(self.major, self.minor + 1) | ||
elif increment_type == "patch": | ||
incr = Version(self.major, self.minor, self.patch + 1) | ||
|
||
return incr | ||
|
||
|
||
def parse(version): | ||
match = _VERSION_REGEX.search(version) | ||
if not match: | ||
raise ValueError(f"invalid version: {version}") | ||
|
||
return Version(int(match.group("major") or 0), int(match.group("minor") or 0), int(match.group("patch") or 0),) | ||
|
||
|
||
def next_version_from_current_version(current_version, increment_type): | ||
return parse(current_version).increment(increment_type) |
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.