[apps-v2]: fix source apps updater

This commit is contained in:
Magesh K
2024-12-18 12:09:53 +05:30
parent 893c628e80
commit a2a199d64e
3 changed files with 105 additions and 89 deletions

View File

@@ -235,7 +235,6 @@ jobs:
- name: Publish to SideStore/apps-v2.json
run: |
# Copy and execute the update script
cp ./update_apps_json.sh SideStore/apps-v2.json/
pushd SideStore/apps-v2.json/
# Configure Git user (committer details)
@@ -243,8 +242,7 @@ jobs:
git config user.email "github-actions@github.com"
# Make the update script executable and run it
chmod +x ./update_apps_json.sh
./update_apps_json.sh "./_includes/source.json"
python3 ../../update_apps.py "./_includes/source.json"
# Commit changes and push using SSH
git add ./_includes/source.json

104
update_apps.py Executable file
View File

@@ -0,0 +1,104 @@
#!/usr/bin/env python3
import os
import json
import sys
# Set environment variables with default values
VERSION_IPA = os.getenv("VERSION_IPA", "0.0.0")
VERSION_DATE = os.getenv("VERSION_DATE", "2000-12-18T00:00:00Z")
BETA = os.getenv("BETA", "true").lower() == "true" # Convert to boolean
COMMIT_ID = os.getenv("COMMIT_ID", "1234567")
SIZE = int(os.getenv("SIZE", "0")) # Convert to integer
SHA256 = os.getenv("SHA256", "")
LOCALIZED_DESCRIPTION = os.getenv("LOCALIZED_DESCRIPTION", "Invalid Update")
DOWNLOAD_URL = os.getenv("DOWNLOAD_URL", "https://github.com/SideStore/SideStore/releases/download/0.0.0/SideStore.ipa")
BUNDLE_IDENTIFIER = os.getenv("BUNDLE_IDENTIFIER", "com.SideStore.SideStore")
# Check if input file is provided
if len(sys.argv) < 2:
print("Usage: python3 update_apps.py <input_file>")
sys.exit(1)
input_file = sys.argv[1]
print(f"Input File: {input_file}")
# Debugging the environment variables
print("Version:", VERSION_IPA)
print("Version Date:", VERSION_DATE)
print("Beta:", BETA)
print("Commit ID:", COMMIT_ID)
print("Size:", SIZE)
print("Sha256:", SHA256)
print("Localized Description:", LOCALIZED_DESCRIPTION)
print("Download URL:", DOWNLOAD_URL)
# Read the input JSON file
try:
with open(input_file, "r") as file:
data = json.load(file)
except Exception as e:
print(f"Error reading the input file: {e}")
sys.exit(1)
# Process the JSON data
updated = False
for app in data.get("apps", []):
if app.get("bundleIdentifier") == BUNDLE_IDENTIFIER:
# Update app-level metadata
app.update({
"version": VERSION_IPA,
"versionDate": VERSION_DATE,
"beta": BETA,
"commitID": COMMIT_ID,
"size": SIZE,
"sha256": SHA256,
"localizedDescription": LOCALIZED_DESCRIPTION,
"downloadURL": DOWNLOAD_URL,
})
# Process the versions array
versions = app.get("versions", [])
if not versions or not (versions[0].get("version") == VERSION_IPA and versions[0].get("beta") == BETA):
# Prepend a new version if no matching version exists
new_version = {
"version": VERSION_IPA,
"date": VERSION_DATE,
"localizedDescription": LOCALIZED_DESCRIPTION,
"downloadURL": DOWNLOAD_URL,
"beta": BETA,
"commitID": COMMIT_ID,
"size": SIZE,
"sha256": SHA256,
}
versions.insert(0, new_version)
else:
# Update the existing version object
versions[0].update({
"version": VERSION_IPA,
"date": VERSION_DATE,
"localizedDescription": LOCALIZED_DESCRIPTION,
"downloadURL": DOWNLOAD_URL,
"beta": BETA,
"commitID": COMMIT_ID,
"size": SIZE,
"sha256": SHA256,
})
app["versions"] = versions
updated = True
break
if not updated:
print("No app with the specified bundle identifier found.")
sys.exit(1)
# Save the updated JSON to the input file
try:
print("\nUpdated Sources File:\n")
print(json.dumps(data, indent=2, ensure_ascii=False))
with open(input_file, "w", encoding="utf-8") as file:
json.dump(data, file, indent=2, ensure_ascii=False)
print("JSON successfully updated.")
except Exception as e:
print(f"Error writing to the file: {e}")
sys.exit(1)

View File

@@ -1,86 +0,0 @@
#!/bin/bash
# Set environment variables with default values if not already set
export VERSION_IPA="${VERSION_IPA:-0.0.0}"
export VERSION_DATE="${VERSION_DATE:-2000-12-18T00:00:00Z}"
export BETA="${BETA:-true}"
export COMMIT_ID="${COMMIT_ID:-1234567}"
export SIZE="${SIZE:-0}"
export SHA256="${SHA256:-}"
export LOCALIZED_DESCRIPTION="${LOCALIZED_DESCRIPTION:-Invalid Update}"
export DOWNLOAD_URL="${DOWNLOAD_URL:-https://github.com/SideStore/SideStore/releases/download/0.0.0/SideStore.ipa}"
echo "Input File: $1"
# Debugging the environment variables
echo "Version: $VERSION_IPA"
echo "Version Date: $VERSION_DATE"
echo "Beta: $BETA"
echo "Commit ID: $COMMIT_ID"
echo "Size: $SIZE"
echo "Sha256: $SHA256"
echo "Localized Description: $LOCALIZED_DESCRIPTION"
echo "Download URL: $DOWNLOAD_URL"
# Perform jq operation
UPDATED_JSON=$(cat "${1}" | jq --arg bundleIdentifier "com.SideStore.SideStore" \
--arg version "$VERSION_IPA" \
--arg versionDate "$VERSION_DATE" \
--arg beta "$BETA" \
--arg commitID "$COMMIT_ID" \
--arg size "$SIZE" \
--arg sha256 "$SHA256" \
--arg localizedDescription "$(echo $LOCALIZED_DESCRIPTION | jq -Rs .)" \
--arg downloadURL "$DOWNLOAD_URL" \
--arg versionDescription "$(echo $VERSION_DESCRIPTION | jq -Rs .)" \
'
.apps |= map(
if .bundleIdentifier == $bundleIdentifier then
.version = $version |
.versionDate = $versionDate |
.beta = ($beta == "true") |
.commitID = $commitID |
.size = ($size | tonumber) |
.sha256 = $sha256 |
.localizedDescription = $localizedDescription |
.downloadURL = $downloadURL |
if (.versions | length > 0) and
((.versions[0].version != $version) or (.versions[0].beta != ($beta == "true"))) then
.versions |= (
[{ "version": $version,
"date": $versionDate,
"localizedDescription": $localizedDescription,
"downloadURL": $downloadURL,
"beta": ($beta == "true"),
"commitID": $commitID,
"size": ($size | tonumber),
"sha256": $sha256
}] +
.
# | map(
# if .sha256 == null then
# (. + {sha256: $sha256})
# else
# .
# end
# )
)
else
.
end
else
.
end
)
'
)
# Check if jq failed and print result
if [ $? -eq 0 ]; then
echo "Updated JSON:"
echo "$UPDATED_JSON"
echo "$UPDATED_JSON" > "${1}"
else
echo "Error in jq processing."
fi