-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_versioning.py
More file actions
55 lines (44 loc) · 1.5 KB
/
update_versioning.py
File metadata and controls
55 lines (44 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import requests
import json
import pathlib
# Github repo information
SCRIPT_DIR = pathlib.Path(__file__).parent.resolve()
GITHUB_API_URL = "https://api.github.com/repos/DeepWaterExploration/DWE_OS_2/tags"
VERSION_FILE_PATH = f"{SCRIPT_DIR}/frontend/package.json"
def get_latest_tag():
# Fetch the latest tags from GitHub API
response = requests.get(GITHUB_API_URL)
if response.status_code == 200:
tags = response.json()
if tags:
return tags[0]['name'] # The latest tag is the first one
return None
def get_new_tag():
try:
new_tag = input('Enter a new tag name: ')
if new_tag == "":
return None
return new_tag
except EOFError:
return None
def update_version_json(new_version):
# Load the current package.json file
with open(VERSION_FILE_PATH, 'r') as f:
data = json.load(f)
# Update the version string
data['version'] = new_version
# Write the new version back to the json file
with open(VERSION_FILE_PATH, 'w') as f:
# need newline at end of file
data_str = json.dumps(data, indent=4) + '\n'
f.write(data_str)
if __name__ == "__main__":
# Get a new tag
latest_tag = get_new_tag()
if latest_tag:
print(f"Latest tag found: {latest_tag}")
# Update the package.json file
update_version_json(latest_tag)
print("package.json updated successfully.")
else:
print("No tags found or failed to fetch the latest tag.")