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

refactor: Put current verification code into function #30

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions .github/verify_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@
from urllib.request import urlopen
import json

# Load local manifesto file
f = open('verified-mods.json')
manifesto = json.load(f)
def verify_all_mod_versions():
# Load local manifesto file
f = open('verified-mods.json')
manifesto = json.load(f)

for mod in manifesto:
print('Verifying "{}":'.format(mod))
for mod in manifesto:
print('Verifying "{}":'.format(mod))

# Build GitHub API link and fetch distant tags list
words = manifesto[mod]['Repository'].split('/')
tags_url = "https://api.github.com/repos/{}/{}/tags".format(words[-2], words[-1])
response = urlopen(tags_url)
tags_data = json.loads(response.read())
# Build GitHub API link and fetch distant tags list
words = manifesto[mod]['Repository'].split('/')
tags_url = "https://api.github.com/repos/{}/{}/tags".format(words[-2], words[-1])
response = urlopen(tags_url)
tags_data = json.loads(response.read())

# Check all mod versions one-by-one
for version in manifesto[mod]['Versions']:
local_hash = version['CommitHash']
matching_distant_versions = list(filter(lambda v: v['name'] == version['Version'], tags_data))
# Check all mod versions one-by-one
for version in manifesto[mod]['Versions']:
local_hash = version['CommitHash']
matching_distant_versions = list(filter(lambda v: v['name'] == version['Version'], tags_data))

# There should be only one matching version
if len(matching_distant_versions) != 1:
sys.exit(' ❌ v{} (unknown distant version)'.format(version['Version']))

# Compare manifesto commit hash with repository hash
distant_version = matching_distant_versions[0]
if local_hash == distant_version['commit']['sha']:
print(' ✔️ v{}'.format(version['Version']))
else:
sys.exit(' ❌ v{} (hash comparison failed)'.format(version['Version']))
# There should be only one matching version
if len(matching_distant_versions) != 1:
sys.exit(' ❌ v{} (unknown distant version)'.format(version['Version']))

# Compare manifesto commit hash with repository hash
distant_version = matching_distant_versions[0]
if local_hash == distant_version['commit']['sha']:
print(' ✔️ v{}'.format(version['Version']))
else:
sys.exit(' ❌ v{} (hash comparison failed)'.format(version['Version']))

if __name__ == "__main__":
verify_all_mod_versions()
Loading