Add buildType support to version update workflow

This commit is contained in:
amd64fox 2025-11-14 07:01:40 +03:00
parent e6d3f0c76e
commit 902b6f1223
2 changed files with 19 additions and 9 deletions

View file

@ -8,7 +8,11 @@ on:
required: true
version:
description: 'Another version parameter'
required: true
required: true
buildType:
description: 'Build type (e.g., Master, Release)'
required: false
default: 'false'
jobs:
update-version:
runs-on: ubuntu-latest
@ -29,7 +33,8 @@ jobs:
- name: Update version in versions.json
run: |
data="${{ github.event.inputs.datajson }}"
python3 update_version.py "$data"
build_type="${{ github.event.inputs.buildType }}"
python3 update_version.py "$data" "$build_type"
- name: Commit changes
run: |

View file

@ -4,15 +4,19 @@ import re
import sys
def update_version(data_json: str, version_file: str = "versions.json") -> bool:
def update_version(data_json: str, build_type: str = None, version_file: str = "versions.json") -> bool:
try:
data = json.loads(data_json)
version_key = list(data.keys())[0]
version_data = data[version_key]
if build_type and build_type.lower() != 'false':
version_data = {'buildType': build_type, **version_data}
with open(version_file, 'r', encoding='utf-8') as f:
file_data = json.load(f)
version_key = list(data.keys())[0]
file_data[version_key] = data[version_key]
file_data[version_key] = version_data
sorted_data = dict(
sorted(
@ -44,13 +48,14 @@ def update_version(data_json: str, version_file: str = "versions.json") -> bool:
def main():
if len(sys.argv) < 2:
print("Usage: python update_version.py '<json_data>' [version_file]", file=sys.stderr)
print("Usage: python update_version.py '<json_data>' [build_type] [version_file]", file=sys.stderr)
sys.exit(1)
data_json = sys.argv[1]
version_file = sys.argv[2] if len(sys.argv) > 2 else "versions.json"
build_type = sys.argv[2] if len(sys.argv) > 2 else None
version_file = sys.argv[3] if len(sys.argv) > 3 else "versions.json"
success = update_version(data_json, version_file)
success = update_version(data_json, build_type, version_file)
sys.exit(0 if success else 1)