Skip to content

Commit 24ff668

Browse files
committed
Add cross-platform Python versions of shell scripts
1 parent 003c019 commit 24ff668

3 files changed

Lines changed: 130 additions & 0 deletions

File tree

devgetchanges.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import shutil
3+
4+
os.chdir(os.path.expanduser("~"))
5+
6+
dst_path = os.path.join("Documents", "workspace", "microting", "eform-service-workflow-plugin", "ServiceWorkflowPlugin")
7+
src_path = os.path.join("Documents", "workspace", "microting", "eform-debian-service", "Plugins", "ServiceWorkflowPlugin")
8+
9+
if os.path.exists(dst_path):
10+
shutil.rmtree(dst_path)
11+
12+
shutil.copytree(src_path, dst_path)

devinstall.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import shutil
3+
4+
os.chdir(os.path.expanduser("~"))
5+
6+
dst_path = os.path.join("Documents", "workspace", "microting", "eform-debian-service", "Plugins", "ServiceWorkflowPlugin")
7+
src_path = os.path.join("Documents", "workspace", "microting", "eform-service-workflow-plugin", "ServiceWorkflowPlugin")
8+
9+
if os.path.exists(dst_path):
10+
shutil.rmtree(dst_path)
11+
12+
os.makedirs(os.path.dirname(dst_path), exist_ok=True)
13+
14+
shutil.copytree(src_path, dst_path)

upgradeeformnugets.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
72+
current_number_of_commits = get_commit_count()
73+
74+
os.chdir("ServiceWorkflowPlugin")
75+
packages = [
76+
'Microting.eForm', 'Microting.eFormApi.BasePn', 'Microting.eFormWorkflowBase',
77+
'Microting.eFormAngularFrontendBase', 'Microsoft.Extensions.DependencyModel',
78+
'System.ComponentModel.Composition', 'SendGrid', 'Sentry'
79+
]
80+
process_repository('ServiceWorkflowPlugin.csproj', packages, 'eform-service-workflow-plugin')
81+
82+
os.chdir("..")
83+
os.chdir("ServiceWorkflowPlugin.Integration.Test")
84+
packages = [
85+
'Microsoft.NET.Test.Sdk', 'NUnit', 'NUnit3TestAdapter', 'NUnit.Analyzers'
86+
]
87+
process_repository('ServiceWorkflowPlugin.Integration.Test.csproj', packages, 'eform-service-workflow-plugin')
88+
89+
new_number_of_commits = get_commit_count()
90+
if new_number_of_commits > current_number_of_commits:
91+
new_version = update_git_version()
92+
print(f"Updated Microting eForm and pushed new version {new_version}")
93+
os.chdir("..")
94+
run_command(f"github_changelog_generator -u microting -p eform-service-workflow-plugin -t {os.getenv('CHANGELOG_GITHUB_TOKEN')}", shell=True)
95+
run_command(["git", "add", "CHANGELOG.md"])
96+
run_command(["git", "commit", "-m", "Updating changelog"])
97+
run_command(["git", "push"])
98+
else:
99+
print("Nothing to do, everything is up to date.")
100+
else:
101+
print("Working tree is not clean, so we are not going to upgrade. Clean before doing upgrade!")
102+
103+
if __name__ == "__main__":
104+
main()

0 commit comments

Comments
 (0)