bundlewrap/bundles/sshmon/files/check_github_for_new_release

31 lines
847 B
Python

#!/usr/bin/env python3
from requests import get
from sys import argv, exit
assert len(argv) == 3, 'Usage: check_github_for_new_release <repo> <version>'
repo = argv[1]
current_version = argv[2]
try:
r = get('https://api.github.com/repos/{}/releases/latest'.format(repo), headers={'Accept': 'application/json'}).json()
except Exception as e:
print(repr(e))
exit(3)
newest_release = r['name']
if newest_release != current_version:
print('There is a newer version available: {} (currently installed: {})'.format(newest_release, current_version))
if r['prerelease'] or r['draft']:
print('Please note this is only a prerelease/draft.')
# Don't alert people for prereleases.
exit(0)
else:
exit(2)
else:
print('Currently installed version matches newest release on github')
exit(0)