Skip to content

Commit 4a71026

Browse files
committed
Add cross-platform Python version of upgradeeformnugets.sh
1 parent 89ded8d commit 4a71026

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

upgradeeformnugets.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import os
2+
import subprocess
3+
import re
4+
import requests
5+
import json
6+
7+
def run_command(command, shell=False, capture_output=False):
8+
return subprocess.run(command, shell=shell, check=True, capture_output=capture_output, text=True).stdout.strip()
9+
10+
def get_git_status():
11+
return run_command("git status | grep 'nothing to commit, working tree clean' | wc -l", shell=True, capture_output=True)
12+
13+
def get_commit_count():
14+
return int(run_command("git log --oneline | wc -l", shell=True, capture_output=True))
15+
16+
def get_package_version(package_name, project_name):
17+
output = run_command(f"dotnet list {project_name} package | grep '{package_name} '", shell=True)
18+
match = re.search(r'(\d+\.\d+\.\d+)', output)
19+
return match.group(0) if match else None
20+
21+
def bump_package_version(project_name, package_name, old_version, new_version, repository):
22+
issue_data = {
23+
"title": f"Bump {package_name} from {old_version} to {new_version}",
24+
"body": "TBD",
25+
"assignees": ["renemadsen"],
26+
"labels": [".NET", "backend", "enhancement"]
27+
}
28+
29+
headers = {
30+
"Authorization": f"token {os.getenv('CHANGELOG_GITHUB_TOKEN')}",
31+
"Content-Type": "application/json"
32+
}
33+
34+
response = requests.post(
35+
f"https://api.github.com/repos/microting/{repository}/issues",
36+
headers=headers,
37+
data=json.dumps(issue_data)
38+
)
39+
40+
issue_number = response.json().get("number")
41+
run_command(["git", "add", "."])
42+
run_command(["git", "commit", "-a", "-m", f"closes #{issue_number}"])
43+
44+
def get_git_version():
45+
return run_command("git tag --sort=-creatordate | head -n 1", shell=True).replace('v', '')
46+
47+
def update_git_version():
48+
current_version = get_git_version()
49+
major, minor, build = map(int, current_version.split('.'))
50+
new_version = f"v{major}.{minor}.{build + 1}"
51+
run_command(["git", "tag", new_version])
52+
run_command(["git", "push", "--tags"])
53+
run_command(["git", "push"])
54+
return new_version
55+
56+
def process_repository(project_name, packages, repository):
57+
for package_name in packages:
58+
old_version = get_package_version(package_name, project_name)
59+
run_command(["dotnet", "add", project_name, "package", package_name])
60+
new_version = get_package_version(package_name, project_name)
61+
62+
if new_version and new_version != old_version:
63+
bump_package_version(project_name, package_name, old_version, new_version, repository)
64+
65+
def main():
66+
os.chdir(os.path.expanduser("~"))
67+
68+
if int(get_git_status()) > 0:
69+
run_command("git checkout master", shell=True)
70+
run_command("git pull", shell=True)
71+
current_number_of_commits = get_commit_count()
72+
73+
os.chdir("eFormAPI/Plugins/ItemsPlanning.Pn/ItemsPlanning.Pn")
74+
packages = [
75+
'Microting.eForm', 'Microting.eFormApi.BasePn', 'Microting.ItemsPlanningBase', 'Sentry'
76+
]
77+
process_repository('ItemsPlanning.Pn.csproj', packages, 'eform-angular-items-planning-plugin')
78+
79+
os.chdir("..")
80+
os.chdir("ItemsPlanning.Pn.Test")
81+
packages = [
82+
'Microsoft.NET.Test.Sdk', 'NSubstitute', 'NUnit', 'NUnit3TestAdapter',
83+
'NUnit.Analyzers', 'Testcontainers', 'Testcontainers.Mariadb'
84+
]
85+
process_repository('ItemsPlanning.Pn.Test.csproj', packages, 'eform-angular-items-planning-plugin')
86+
87+
new_number_of_commits = get_commit_count()
88+
if new_number_of_commits > current_number_of_commits:
89+
new_version = update_git_version()
90+
print(f"Updated Microting eForm and pushed new version {new_version}")
91+
os.chdir(os.path.join("..", "..", "..", ".."))
92+
run_command(f"github_changelog_generator -u microting -p eform-angular-items-planning-plugin -t {os.getenv('CHANGELOG_GITHUB_TOKEN')}", shell=True)
93+
run_command(["git", "add", "CHANGELOG.md"])
94+
run_command(["git", "commit", "-m", "Updating changelog"])
95+
run_command(["git", "push"])
96+
else:
97+
print("Nothing to do, everything is up to date.")
98+
else:
99+
print("Working tree is not clean, so we are not going to upgrade. Clean before doing upgrade!")
100+
101+
if __name__ == "__main__":
102+
main()

0 commit comments

Comments
 (0)