Improve error handling in update_version.py script
This commit is contained in:
parent
bffdc39cca
commit
4e0009ce26
2 changed files with 13 additions and 2 deletions
4
.github/workflows/update_versions.yml
vendored
4
.github/workflows/update_versions.yml
vendored
|
|
@ -27,7 +27,9 @@ jobs:
|
|||
python-version: 3.12.2
|
||||
|
||||
- name: Update version in versions.json
|
||||
run: python3 update_version.py '${{ github.event.inputs.datajson }}'
|
||||
run: |
|
||||
data="${{ github.event.inputs.datajson }}"
|
||||
python3 update_version.py "$data"
|
||||
|
||||
- name: Commit changes
|
||||
run: |
|
||||
|
|
|
|||
|
|
@ -28,14 +28,23 @@ def update_version(data_json: str, version_file: str = "versions.json") -> bool:
|
|||
with open(version_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(sorted_data, f, indent=2)
|
||||
|
||||
print(f"Version {version_key} added to {version_file}")
|
||||
return True
|
||||
|
||||
except:
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"JSON parse error: {e}", file=sys.stderr)
|
||||
return False
|
||||
except FileNotFoundError:
|
||||
print(f"File {version_file} not found", file=sys.stderr)
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Error: {e}", file=sys.stderr)
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python update_version.py '<json_data>' [version_file]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
data_json = sys.argv[1]
|
||||
|
|
|
|||
Loading…
Reference in a new issue