diff --git a/.github/validate_mod_json.py b/.github/validate_mod_json.py index 6fbeaf3..f4df1b7 100644 --- a/.github/validate_mod_json.py +++ b/.github/validate_mod_json.py @@ -3,6 +3,7 @@ import os import sys import urllib.request +from io import StringIO from ignore_json import ignore @@ -11,8 +12,10 @@ for filename in glob.glob(os.path.join('.', '*.json')): if filename not in ignore: print(f"Opening: {filename}") - filecontent = open(filename, "r").read() - + + with open(filename, "r") as file: + filecontent = file.read() + try: modlist = jstyleson.loads(filecontent) except Exception as err: @@ -23,6 +26,7 @@ for mod, data in modlist.items(): url = data["mod"].replace(" ", "%20") print(f"{mod}: {url}") + try: response = urllib.request.urlopen(url) print(f"✅ Download successful") @@ -31,16 +35,16 @@ print(f"❌ Download failed: {err}") continue - filecontent = response.read() - try: - jstyleson.loads(filecontent) + filecontent = response.read().decode("utf-8") + jstyleson.load(StringIO(filecontent)) print(f"✅ JSON valid") except Exception as err: error = True print(f"❌ JSON invalid:") print(str(err)) continue + if error: sys.exit(os.EX_SOFTWARE) else: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7dfc86f..fdd1de1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,9 +19,15 @@ jobs: shell: bash steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Python environment + run: sudo apt update && sudo apt install -y python3 python3-pip + - name: Install jstyleson + run: pip3 install jstyleson - name: Validate json - run: | - python3 .github/validate_json.py + run: python3 .github/validate_json.py + validate_mod_json: needs: validate_json runs-on: ubuntu-latest @@ -30,9 +36,11 @@ jobs: shell: bash steps: - uses: actions/checkout@v3 + - name: Install jstyleson + run: pip3 install jstyleson - name: Validate mod json - run: | - python3 .github/validate_mod_json.py + run: python3 .github/validate_mod_json.py + update_size: needs: validate_json runs-on: ubuntu-latest @@ -41,12 +49,33 @@ jobs: shell: bash steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Install jstyleson + run: pip3 install jstyleson + - name: Update size + run: python3 .github/update_size.py + + - name: Determine branch and switch + id: branch_info run: | - python3 .github/update_size.py - - name: Commit changes + if [ -z "$GITHUB_HEAD_REF" ]; then + branch_name=$(git symbolic-ref --short HEAD) + else + branch_name=$GITHUB_HEAD_REF + fi + echo "branch_name=$branch_name" >> $GITHUB_ENV + git checkout $branch_name || git checkout -b $branch_name + echo "Checked out branch: $branch_name" + + - name: Set upstream for branch + run: git push --set-upstream origin $branch_name + + - name: Commit changes to the correct branch uses: EndBug/add-and-commit@v9 with: default_author: github_actions message: Update sizes add: '*.json' + push: --force diff --git a/vcmi-1.6.json b/vcmi-1.6.json index a91b3f9..51f3a3b 100644 --- a/vcmi-1.6.json +++ b/vcmi-1.6.json @@ -289,8 +289,9 @@ "mod" : "https://raw.githubusercontent.com/vcmi-mods/haven-town/vcmi-1.6/haven-town/mod.json", "download" : "https://github.com/vcmi-mods/haven-town/archive/refs/heads/vcmi-1.6.zip", "screenshots" : [ - "https://raw.githubusercontent.com/vcmi-mods/haven-town/vcmi-1.5/screenshots/screen1.png", - "https://raw.githubusercontent.com/vcmi-mods/haven-town/vcmi-1.5/screenshots/screen2.png" + "https://raw.githubusercontent.com/vcmi-mods/haven-town/vcmi-1.6/screenshots/screen1.png", + "https://raw.githubusercontent.com/vcmi-mods/haven-town/vcmi-1.6/screenshots/screen2.png", + "https://raw.githubusercontent.com/vcmi-mods/haven-town/vcmi-1.6/screenshots/screen3.png" ], "downloadSize" : 12.409 },