Skip to content

Commit 584e775

Browse files
authored
Merge pull request #13 from enpm611/development
Minor release with changes to the delivery logic
2 parents 1fbfcd0 + 39d40b8 commit 584e775

19 files changed

+727
-226
lines changed

.github/workflows/autotag.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/autotest.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/triage_issues.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,35 @@
1212
"coverage-gutters.showLineCoverage": true,
1313
"python.testing.pytestArgs": [
1414
"tests"
15-
]
15+
],
16+
"files.exclude": {
17+
"**/.git": true,
18+
"**/.svn": true,
19+
"**/.hg": true,
20+
"**/CVS": true,
21+
"**/.DS_Store": true,
22+
"**/Thumbs.db": true,
23+
"**/*.pyc": {
24+
"when": "$(basename).py"
25+
},
26+
"**/__pycache__": true,
27+
"**/app.egg-info": true,
28+
"**/env": true,
29+
"**/.env.dist": true,
30+
"**/*.log": true,
31+
"**/.0": true
32+
},
33+
"workbench.colorCustomizations": {
34+
"tab.activeBorder": "#ff0000",
35+
"tab.unfocusedActiveBorder": "#000000",
36+
"tab.activeBackground": "#045980"
37+
},
38+
"workbench.editor.wrapTabs": true,
39+
"debug.toolBarLocation": "docked",
40+
"python.formatting.provider": "autopep8",
41+
"editor.formatOnSave": true,
42+
"[python]": {
43+
"editor.defaultFormatter": "ms-python.autopep8"
44+
},
45+
"python.REPL.enableREPLSmartSend": false
1646
}

README.md

Lines changed: 245 additions & 53 deletions
Large diffs are not rendered by default.

__version__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# coding: utf-8
2+
3+
__title__ = 'enpm611-ghactions'
4+
__version__ = '1.4.0'
5+
__author__ = 'ENPM611'
6+
__url__ = 'https://github.com/enpm611/github-actions'
7+
__description__ = ("Exercise to use GitHub Actions for CI/CD task.")

app/string_utils.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

config/issue-rules.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
3+
import os
4+
import re
5+
from datetime import datetime
6+
from pathlib import Path
7+
8+
9+
def get_current_version() -> str:
10+
# Read version file
11+
VERSION_FILE = Path("__version__.py")
12+
version_text = VERSION_FILE.read_text()
13+
# Extract current version string
14+
match = re.search(r"__version__\s*=\s*['\"](\d+\.\d+\.\d+)['\"]", version_text)
15+
if not match:
16+
raise ValueError("Could not find __version__ in file.")
17+
return match.group(1)
18+
19+
20+
def update_release_notes() -> None:
21+
22+
# Read the environment variables that were passed in from
23+
# the GitHub Action workflow.
24+
pr_title: str = os.environ.get("PR_TITLE", "").strip()
25+
pr_body: str = os.environ.get("PR_BODY", "").strip()
26+
# Check for missing environment variables
27+
if not pr_title:
28+
raise ValueError("PR_TITLE environment variable is missing.")
29+
30+
# Get current version from version file
31+
version: str = get_current_version()
32+
33+
# Create release note entry
34+
date_str: str = datetime.utcnow().strftime("%Y-%m-%d")
35+
entry_lines: list[str] = [
36+
"",
37+
f"## Release Notes — v{version}{pr_title} ({date_str})",
38+
"",
39+
pr_body,
40+
"",
41+
]
42+
43+
# Append to README
44+
with open("README.md", "a", encoding="utf-8") as f:
45+
f.write("\n".join(entry_lines))
46+
47+
print("README updated with release notes.")
48+
49+
if __name__ == "__main__":
50+
update_release_notes()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
"""
3+
Bumps the version number in the `__version__.py` file when a Pull
4+
Request is created.
5+
"""
6+
7+
8+
import re
9+
import os
10+
from pathlib import Path
11+
from typing import Any, Literal
12+
13+
14+
def get_current_version(version_text:str) -> str:
15+
# Extract current version string
16+
match = re.search(r"__version__\s*=\s*['\"](\d+\.\d+\.\d+)['\"]", version_text)
17+
if not match:
18+
raise ValueError("Could not find __version__ in file.")
19+
return match.group(1)
20+
21+
def get_release_type() -> Literal["patch", "minor", "major"]:
22+
""" Determine the type of release based on the PR title """
23+
24+
# Read release title from env
25+
pr_title: str = os.environ.get("PR_TITLE", "").strip()
26+
# Determine release type based on terms in title
27+
if "minor" in pr_title.lower():
28+
return "minor"
29+
elif "major" in pr_title.lower():
30+
return "major"
31+
else:
32+
return "patch"
33+
34+
def bump_version():
35+
36+
# Read version file
37+
VERSION_FILE = Path("__version__.py")
38+
version_text = VERSION_FILE.read_text()
39+
40+
old_version: str = get_current_version(version_text)
41+
major, minor, patch = map(int, old_version.split("."))
42+
43+
# Increment based on the requested level
44+
level: Literal['patch', 'minor', 'major'] = get_release_type()
45+
if level == "patch":
46+
patch += 1
47+
elif level == "minor":
48+
minor += 1
49+
patch = 0
50+
elif level == "major":
51+
major += 1
52+
minor = 0
53+
patch = 0
54+
else:
55+
raise ValueError("level must be 'major', 'minor', or 'patch'")
56+
57+
new_version = f"{major}.{minor}.{patch}"
58+
59+
# Replace the version string in the file
60+
new_text = version_text.replace(old_version,new_version)
61+
62+
VERSION_FILE.write_text(new_text)
63+
print(f"Version bumped to {new_version}")
64+
return new_version
65+
66+
67+
68+
69+
if __name__ == "__main__":
70+
bump_version()

0 commit comments

Comments
 (0)