Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haven screenshots #73

Merged
merged 13 commits into from
Feb 1, 2025
14 changes: 9 additions & 5 deletions .github/validate_mod_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import urllib.request
from io import StringIO

from ignore_json import ignore

Expand All @@ -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:
Expand All @@ -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")
Expand All @@ -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:
Expand Down
41 changes: 35 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
5 changes: 3 additions & 2 deletions vcmi-1.6.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
Loading