Skip to content

Commit 997e812

Browse files
committed
Add cross-platform Python versions of shell scripts
1 parent 1743387 commit 997e812

File tree

4 files changed

+261
-0
lines changed

4 files changed

+261
-0
lines changed

devgetchanges.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os
2+
import shutil
3+
4+
# Change directory to the user's home directory
5+
os.chdir(os.path.expanduser("~"))
6+
7+
# Define paths
8+
src_base = os.path.join("Documents", "workspace", "microting", "eform-angular-frontend")
9+
dst_base = os.path.join("Documents", "workspace", "microting", "eform-angular-outer-inner-resource-plugin")
10+
11+
# Remove and copy main directories
12+
paths = [
13+
(os.path.join("eform-client", "src", "app", "plugins", "modules", "outer-inner-resource-pn"),
14+
os.path.join("eform-client", "src", "app", "plugins", "modules", "outer-inner-resource-pn")),
15+
(os.path.join("eFormAPI", "Plugins", "OuterInnerResource.Pn"),
16+
os.path.join("eFormAPI", "Plugins", "OuterInnerResource.Pn")),
17+
]
18+
19+
for dst_rel_path, src_rel_path in paths:
20+
dst_path = os.path.join(dst_base, dst_rel_path)
21+
src_path = os.path.join(src_base, src_rel_path)
22+
23+
if os.path.exists(dst_path):
24+
shutil.rmtree(dst_path)
25+
26+
shutil.copytree(src_path, dst_path)
27+
28+
# List of test files and directories to remove
29+
test_files_to_remove = [
30+
os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-settings"),
31+
os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-general"),
32+
os.path.join("eform-client", "e2e", "Page objects", "OuterInnerResource"),
33+
os.path.join("eform-client", "wdio-headless-plugin-step2.conf.ts"),
34+
]
35+
36+
# Remove the test files and directories
37+
for rel_path in test_files_to_remove:
38+
full_path = os.path.join(dst_base, rel_path)
39+
if os.path.exists(full_path):
40+
if os.path.isdir(full_path):
41+
shutil.rmtree(full_path)
42+
else:
43+
os.remove(full_path)
44+
45+
# List of test files and directories to copy
46+
test_files_to_copy = [
47+
(os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-settings"),
48+
os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-settings")),
49+
(os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-general"),
50+
os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-general")),
51+
(os.path.join("eform-client", "e2e", "Page objects", "OuterInnerResource"),
52+
os.path.join("eform-client", "e2e", "Page objects", "OuterInnerResource")),
53+
(os.path.join("eform-client", "wdio-headless-plugin-step2.conf.ts"),
54+
os.path.join("eform-client", "wdio-headless-plugin-step2.conf.ts")),
55+
]
56+
57+
# Copy the test files and directories
58+
for src_rel_path, dst_rel_path in test_files_to_copy:
59+
src_path = os.path.join(src_base, src_rel_path)
60+
dst_path = os.path.join(dst_base, dst_rel_path)
61+
62+
if os.path.isdir(src_path):
63+
shutil.copytree(src_path, dst_path)
64+
else:
65+
shutil.copy2(src_path, dst_path)

devinstall.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
import shutil
3+
4+
# Change directory to the user's home directory
5+
os.chdir(os.path.expanduser("~"))
6+
7+
# Print the current working directory
8+
print("Current working directory:", os.getcwd())
9+
10+
# Define paths
11+
src_base = os.path.join("Documents", "workspace", "microting", "eform-angular-outer-inner-resource-plugin")
12+
dst_base = os.path.join("Documents", "workspace", "microting", "eform-angular-frontend")
13+
14+
# Remove and copy directories
15+
paths = [
16+
(os.path.join("eform-client", "src", "app", "plugins", "modules", "outer-inner-resource-pn"),
17+
os.path.join("eform-client", "src", "app", "plugins", "modules", "outer-inner-resource-pn")),
18+
(os.path.join("eFormAPI", "Plugins", "OuterInnerResource.Pn"),
19+
os.path.join("eFormAPI", "Plugins", "OuterInnerResource.Pn")),
20+
]
21+
22+
# Removing and copying files
23+
for dst_rel_path, src_rel_path in paths:
24+
dst_path = os.path.join(dst_base, dst_rel_path)
25+
src_path = os.path.join(src_base, src_rel_path)
26+
27+
if os.path.exists(dst_path):
28+
shutil.rmtree(dst_path)
29+
30+
shutil.copytree(src_path, dst_path)
31+
32+
# List of test files and directories to remove
33+
test_files_to_remove = [
34+
os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-settings"),
35+
os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-general"),
36+
os.path.join("eform-client", "e2e", "Page objects", "OuterInnerResource"),
37+
os.path.join("eform-client", "wdio-plugin-step2.conf.ts"),
38+
]
39+
40+
# Remove the test files and directories
41+
for rel_path in test_files_to_remove:
42+
full_path = os.path.join(dst_base, rel_path)
43+
if os.path.exists(full_path):
44+
if os.path.isdir(full_path):
45+
shutil.rmtree(full_path)
46+
else:
47+
os.remove(full_path)
48+
49+
# List of test files and directories to copy
50+
test_files_to_copy = [
51+
(os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-settings"),
52+
os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-settings")),
53+
(os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-general"),
54+
os.path.join("eform-client", "e2e", "Tests", "outer-inner-resource-general")),
55+
(os.path.join("eform-client", "e2e", "Page objects", "OuterInnerResource"),
56+
os.path.join("eform-client", "e2e", "Page objects", "OuterInnerResource")),
57+
(os.path.join("eform-client", "wdio-headless-plugin-step2.conf.ts"),
58+
os.path.join("eform-client", "wdio-headless-plugin-step2.conf.ts")),
59+
]
60+
61+
# Copy the test files and directories
62+
for src_rel_path, dst_rel_path in test_files_to_copy:
63+
src_path = os.path.join(src_base, src_rel_path)
64+
dst_path = os.path.join(dst_base, dst_rel_path)
65+
66+
if os.path.isdir(src_path):
67+
shutil.copytree(src_path, dst_path)
68+
else:
69+
shutil.copy2(src_path, dst_path)

testinginstallpn.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import re
2+
import os
3+
4+
# Path to the file to be modified
5+
file_path = os.path.join("src", "app", "plugins", "plugins.routing.ts")
6+
7+
# Read the content of the file
8+
with open(file_path, "r") as file:
9+
content = file.read()
10+
11+
# Define the replacements
12+
replacements = [
13+
(r"// INSERT ROUTES HERE", " {\n// INSERT ROUTES HERE"),
14+
(r"// INSERT ROUTES HERE", " path: 'outer-inner-resource-pn',\n// INSERT ROUTES HERE"),
15+
(r"// INSERT ROUTES HERE", " loadChildren: () => import('./modules/outer-inner-resource-pn/outer-inner-resource-pn.module')\n// INSERT ROUTES HERE"),
16+
(r"// INSERT ROUTES HERE", " .then(m => m.OuterInnerResourcePnModule)\n// INSERT ROUTES HERE"),
17+
(r"// INSERT ROUTES HERE", " },\n// INSERT ROUTES HERE"),
18+
]
19+
20+
# Apply each replacement in sequence
21+
for pattern, replacement in replacements:
22+
content = re.sub(pattern, replacement, content, count=1)
23+
24+
# Write the modified content back to the file
25+
with open(file_path, "w") as file:
26+
file.write(content)

upgradeeformnugets.py

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

0 commit comments

Comments
 (0)