From 89f4423ea1ded8b7df9d199ef9c28b1223e9bd9b Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:19:28 +0100 Subject: [PATCH 01/13] Haven screenshots --- vcmi-1.6.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 }, From 68ad655ca6064d9bea2fe0808910f2f80463d57a Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:26:53 +0100 Subject: [PATCH 02/13] Update main.yml with jstyleson --- .github/workflows/main.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7dfc86f..1078efc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,9 +19,13 @@ jobs: shell: bash steps: - uses: actions/checkout@v3 + - name: Install dependencies + run: | + pip3 install jstyleson - name: Validate json run: | python3 .github/validate_json.py + validate_mod_json: needs: validate_json runs-on: ubuntu-latest @@ -30,9 +34,13 @@ jobs: shell: bash steps: - uses: actions/checkout@v3 + - name: Install dependencies + run: | + pip3 install jstyleson - name: Validate mod json run: | python3 .github/validate_mod_json.py + update_size: needs: validate_json runs-on: ubuntu-latest @@ -41,6 +49,9 @@ jobs: shell: bash steps: - uses: actions/checkout@v3 + - name: Install dependencies + run: | + pip3 install jstyleson - name: Update size run: | python3 .github/update_size.py From 6c16569a365e69a737942d17eae9d3f4b047ae3b Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:34:13 +0100 Subject: [PATCH 03/13] Update validate_mod_json.py --- .github/validate_mod_json.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/validate_mod_json.py b/.github/validate_mod_json.py index 6fbeaf3..e1d9575 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: From e265d91f344650cc945839da2ff48ba6a5438af4 Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:36:17 +0100 Subject: [PATCH 04/13] Update validate_mod_json.py --- .github/validate_mod_json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/validate_mod_json.py b/.github/validate_mod_json.py index e1d9575..f4df1b7 100644 --- a/.github/validate_mod_json.py +++ b/.github/validate_mod_json.py @@ -36,7 +36,7 @@ continue try: - filecontent = response.read().decode("utf-8") + filecontent = response.read().decode("utf-8") jstyleson.load(StringIO(filecontent)) print(f"✅ JSON valid") except Exception as err: From 866ff9679d5f62bc8d888266ecbcb49147d302b4 Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:51:40 +0100 Subject: [PATCH 05/13] Update update_size.py --- .github/update_size.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/update_size.py b/.github/update_size.py index f80f076..e9de87b 100644 --- a/.github/update_size.py +++ b/.github/update_size.py @@ -1,31 +1,53 @@ -import json +import jstyleson import glob import os import sys import urllib.request +from io import StringIO from ignore_json import ignore for filename in glob.glob(os.path.join('.', '*.json')): if filename not in ignore: print(f"Opening: {filename}") - filecontent = open(filename, "r").read() - modlist = json.loads(filecontent) + + with open(filename, "r") as file: + filecontent = file.read() + + try: + jstyleson.load(StringIO(filecontent)) + modlist = jstyleson.loads(filecontent) + except Exception as err: + print(f"❌ Error reading JSON file {filename}: {err}") + sys.exit(os.EX_SOFTWARE) + for mod, data in modlist.items(): url = data["download"].replace(" ", "%20") print(f"Download {mod}: {url}") + try: response = urllib.request.urlopen(url) - except: - print("Error: download failed!") + print(f"✅ Download successful") + except Exception as err: + print(f"❌ Download failed: {err}") sys.exit(os.EX_SOFTWARE) - filesize = round(len(response.read()) / 1024 / 1024, 3) + + try: + filecontent = response.read().decode("utf-8") + jstyleson.load(StringIO(filecontent)) + print(f"✅ JSON valid") + except Exception as err: + print(f"❌ JSON invalid: {err}") + sys.exit(os.EX_SOFTWARE) + + filesize = round(len(filecontent.encode('utf-8')) / 1024 / 1024, 3) print(f"Size: {filesize}") data["downloadSize"] = filesize resultcontent = json.dumps(modlist, indent='\t', separators=(',', ' : ')) + "\n" if filecontent != resultcontent: - open(filename, "w").write(resultcontent) + with open(filename, "w") as file: + file.write(resultcontent) sys.exit(os.EX_OK) From 5c4d65b9f293849c708b45acdf31c5088b80cd35 Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:54:24 +0100 Subject: [PATCH 06/13] Update update_size.py --- .github/update_size.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/update_size.py b/.github/update_size.py index e9de87b..b33f206 100644 --- a/.github/update_size.py +++ b/.github/update_size.py @@ -3,7 +3,6 @@ import os import sys import urllib.request -from io import StringIO from ignore_json import ignore @@ -15,7 +14,6 @@ filecontent = file.read() try: - jstyleson.load(StringIO(filecontent)) modlist = jstyleson.loads(filecontent) except Exception as err: print(f"❌ Error reading JSON file {filename}: {err}") @@ -27,21 +25,14 @@ try: response = urllib.request.urlopen(url) + filecontent = response.read() print(f"✅ Download successful") except Exception as err: print(f"❌ Download failed: {err}") sys.exit(os.EX_SOFTWARE) - try: - filecontent = response.read().decode("utf-8") - jstyleson.load(StringIO(filecontent)) - print(f"✅ JSON valid") - except Exception as err: - print(f"❌ JSON invalid: {err}") - sys.exit(os.EX_SOFTWARE) - - filesize = round(len(filecontent.encode('utf-8')) / 1024 / 1024, 3) - print(f"Size: {filesize}") + filesize = round(len(filecontent) / 1024 / 1024, 3) + print(f"Size: {filesize} MB") data["downloadSize"] = filesize resultcontent = json.dumps(modlist, indent='\t', separators=(',', ' : ')) + "\n" From e0162c50cb1ed5e1fffb5f66a3f2e159a8576dd8 Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 21:57:43 +0100 Subject: [PATCH 07/13] Update update_size.py --- .github/update_size.py | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/update_size.py b/.github/update_size.py index b33f206..6d2855a 100644 --- a/.github/update_size.py +++ b/.github/update_size.py @@ -1,4 +1,5 @@ import jstyleson +import json import glob import os import sys From 04c72a4015127f49cd8e8d06bd747e4373d6f8a0 Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 22:09:01 +0100 Subject: [PATCH 08/13] Update main.yml --- .github/workflows/main.yml | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1078efc..db2cfdc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,27 +19,14 @@ jobs: shell: bash steps: - uses: actions/checkout@v3 - - name: Install dependencies - run: | - pip3 install jstyleson + 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 - - validate_mod_json: - needs: validate_json - runs-on: ubuntu-latest - defaults: - run: - shell: bash - steps: - - uses: actions/checkout@v3 - - name: Install dependencies - run: | - pip3 install jstyleson - - name: Validate mod json - run: | - python3 .github/validate_mod_json.py + run: python3 .github/validate_json.py update_size: needs: validate_json @@ -49,12 +36,15 @@ jobs: shell: bash steps: - uses: actions/checkout@v3 - - name: Install dependencies - run: | - pip3 install jstyleson + with: + fetch-depth: 0 + - name: Install jstyleson + run: pip3 install jstyleson - name: Update size + run: python3 .github/update_size.py + - name: Switch to develop branch run: | - python3 .github/update_size.py + git checkout develop - name: Commit changes uses: EndBug/add-and-commit@v9 with: From 3ade062b565325055b4e5e10b0cc1ea9ec70e62e Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 22:11:29 +0100 Subject: [PATCH 09/13] Update main.yml --- .github/workflows/main.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index db2cfdc..cf83a87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,6 +28,19 @@ jobs: - name: Validate json run: python3 .github/validate_json.py + validate_mod_json: + needs: validate_json + runs-on: ubuntu-latest + defaults: + run: + 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 + update_size: needs: validate_json runs-on: ubuntu-latest @@ -37,7 +50,7 @@ jobs: steps: - uses: actions/checkout@v3 with: - fetch-depth: 0 + fetch-depth: 0 - name: Install jstyleson run: pip3 install jstyleson - name: Update size From 8da3776ef2483eb686700d5e9eb6425719692e97 Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 22:37:29 +0100 Subject: [PATCH 10/13] Update main.yml --- .github/workflows/main.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cf83a87..f142c6e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,17 +50,27 @@ jobs: steps: - uses: actions/checkout@v3 with: - fetch-depth: 0 + fetch-depth: 0 - name: Install jstyleson run: pip3 install jstyleson - name: Update size run: python3 .github/update_size.py - - name: Switch to develop branch + + - name: Determine branch and switch + id: branch_info run: | - git checkout develop - - 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 + echo "Switched to branch: $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 From a4574a9b168ee9eb053c32fb5e41edafeef5644c Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 22:49:31 +0100 Subject: [PATCH 11/13] Update main.yml --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f142c6e..380128e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,6 +53,7 @@ jobs: fetch-depth: 0 - name: Install jstyleson run: pip3 install jstyleson + - name: Update size run: python3 .github/update_size.py @@ -65,7 +66,8 @@ jobs: branch_name=$GITHUB_HEAD_REF fi echo "branch_name=$branch_name" >> $GITHUB_ENV - echo "Switched to branch: $branch_name" + git checkout $branch_name || git checkout -b $branch_name + echo "Checked out branch: $branch_name" - name: Commit changes to the correct branch uses: EndBug/add-and-commit@v9 From 6840dc764bfd149bb6a1b113c349f72f1e2a992f Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 23:02:32 +0100 Subject: [PATCH 12/13] Update main.yml --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 380128e..fdd1de1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,6 +69,9 @@ jobs: 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: From 6b01bf44baf4c57b43d7fa6d9af73047a89044a2 Mon Sep 17 00:00:00 2001 From: George King <98261225+GeorgeK1ng@users.noreply.github.com> Date: Sat, 1 Feb 2025 23:15:22 +0100 Subject: [PATCH 13/13] Update update_size.py --- .github/update_size.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/.github/update_size.py b/.github/update_size.py index 6d2855a..f80f076 100644 --- a/.github/update_size.py +++ b/.github/update_size.py @@ -1,4 +1,3 @@ -import jstyleson import json import glob import os @@ -10,36 +9,23 @@ for filename in glob.glob(os.path.join('.', '*.json')): if filename not in ignore: print(f"Opening: {filename}") - - with open(filename, "r") as file: - filecontent = file.read() - - try: - modlist = jstyleson.loads(filecontent) - except Exception as err: - print(f"❌ Error reading JSON file {filename}: {err}") - sys.exit(os.EX_SOFTWARE) - + filecontent = open(filename, "r").read() + modlist = json.loads(filecontent) for mod, data in modlist.items(): url = data["download"].replace(" ", "%20") print(f"Download {mod}: {url}") - try: response = urllib.request.urlopen(url) - filecontent = response.read() - print(f"✅ Download successful") - except Exception as err: - print(f"❌ Download failed: {err}") + except: + print("Error: download failed!") sys.exit(os.EX_SOFTWARE) - - filesize = round(len(filecontent) / 1024 / 1024, 3) - print(f"Size: {filesize} MB") + filesize = round(len(response.read()) / 1024 / 1024, 3) + print(f"Size: {filesize}") data["downloadSize"] = filesize resultcontent = json.dumps(modlist, indent='\t', separators=(',', ' : ')) + "\n" if filecontent != resultcontent: - with open(filename, "w") as file: - file.write(resultcontent) + open(filename, "w").write(resultcontent) sys.exit(os.EX_OK)