mirror of
https://github.com/zen-browser/www.git
synced 2025-07-07 17:05:32 +02:00
Update twilight-to-stable.py
Error handling: - try-except blocks for file operations and JSON parsing - Specific handling for FileNotFoundError and JSONDecodeError Data and input validation
This commit is contained in:
parent
20e516f62a
commit
10f0b5945e
1 changed files with 49 additions and 26 deletions
|
@ -7,37 +7,60 @@ TWILIGHT_RELEASE_NOTES = "./src/release-notes/twilight.json"
|
||||||
STABLE_RELEASE_NOTES = "./src/release-notes/stable.json"
|
STABLE_RELEASE_NOTES = "./src/release-notes/stable.json"
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 2:
|
|
||||||
print("Usage: python scripts/twilight-to-stable.py <workflow-id>")
|
if len(sys.argv) != 2:
|
||||||
sys.exit(1)
|
print("Usage: python scripts/twilight-to-stable.py <workflow-id>")
|
||||||
|
sys.exit(1)
|
||||||
workflow_id = int(sys.argv[1])
|
|
||||||
|
try:
|
||||||
|
workflow_id = int(sys.argv[1])
|
||||||
|
if workflow_id < 0:
|
||||||
|
raise ValueError("Workflow ID must be a non-negative integer")
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"Error: Invalid workflow-id - {str(e)}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
with open(TWILIGHT_RELEASE_NOTES, "r") as f:
|
try:
|
||||||
twilight = json.load(f)
|
with open(TWILIGHT_RELEASE_NOTES, "r") as f:
|
||||||
|
twilight = json.load(f)
|
||||||
|
with open(STABLE_RELEASE_NOTES, "r") as f:
|
||||||
|
stable = json.load(f)
|
||||||
|
|
||||||
with open(STABLE_RELEASE_NOTES, "r") as f:
|
if not isinstance(twilight.get("version"), str):
|
||||||
stable = json.load(f)
|
raise ValueError("Twilight version must be a string")
|
||||||
|
|
||||||
twilight["workflowId"] = workflow_id
|
twilight["workflowId"] = workflow_id
|
||||||
twilight["image"] = False
|
twilight["image"] = False
|
||||||
twilight["version"] = twilight["version"].replace("t", "b")
|
twilight["version"] = twilight["version"].replace("t", "b")
|
||||||
twilight["date"] = datetime.datetime.now().strftime("%d/%m/%Y")
|
twilight["date"] = datetime.datetime.now().strftime("%d/%m/%Y")
|
||||||
stable.append(twilight)
|
|
||||||
|
if not isinstance(stable, list):
|
||||||
|
stable = [stable]
|
||||||
|
stable.append(twilight)
|
||||||
|
|
||||||
with open(STABLE_RELEASE_NOTES, "w") as f:
|
with open(STABLE_RELEASE_NOTES, "w") as f:
|
||||||
json.dump(stable, f, indent=2)
|
json.dump(stable, f, indent=2)
|
||||||
|
|
||||||
with open(TWILIGHT_RELEASE_NOTES, "w") as f:
|
with open(TWILIGHT_RELEASE_NOTES, "w") as f:
|
||||||
json.dump({
|
json.dump({
|
||||||
"version": "xxx",
|
"version": "xxx",
|
||||||
"image": False,
|
"image": False,
|
||||||
"extra": "",
|
"extra": "",
|
||||||
"fixes": [],
|
"fixes": [],
|
||||||
"features": [],
|
"features": [],
|
||||||
}, f, indent=2)
|
}, f, indent=2)
|
||||||
|
|
||||||
print("Twilight release notes merged into stable release notes.")
|
print("Twilight release notes merged into stable release notes.")
|
||||||
|
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
print(f"Error: Could not find file - {str(e)}")
|
||||||
|
sys.exit(1)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
print(f"Error: Invalid JSON format in release notes - {str(e)}")
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: An unexpected error occurred - {str(e)}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue