-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_version
executable file
·62 lines (50 loc) · 2.27 KB
/
check_version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
"""Check if we need to update the QMK release.
"""
from os import environ
from pathlib import Path
import requests
# Pull in environment vars
gh_user = environ.get('GH_USERNAME', 'qmk-bot')
gh_pat = environ.get('QMK_BOT_TOKEN', '')
gh_repo_owner = environ.get('REPO_OWNER', 'qmk')
gh_repo_name = environ.get('REPO_NAME', 'qmk_fpm')
gh_ref = environ.get('GITHUB_REF', 'main')
gh_workflow_id = environ.get('WORKFLOW_ID', '')
gh_api_url = environ.get('GITHUB_API_URL', 'https://api.github.com')
gh_workflow_endpoint = environ.get('GH_WORKFLOW_ENDPOINT', f'{gh_api_url}/repos/{gh_repo_owner}/{gh_repo_name}/actions/workflows/{gh_workflow_id}/dispatches')
gh_workflow_args = {'ref': gh_ref}
gh_workflow_headers = {'Accept': 'application/vnd.github.v3+json'}
# Get the pypi version
pypi_qmk = requests.get('https://pypi.org/pypi/qmk/json')
if pypi_qmk.status_code != 200:
print(f'Could not fetch pypi json: {pypi_qmk.status_code}: {pypi_qmk.text}')
exit(1)
pypi_qmk_json = pypi_qmk.json()
qmk_pypi_version = pypi_qmk_json['info']['version']
# Get the Debian version
qmk_deb_version = None
os_release = Path('/etc/os-release').read_text()
version_codename='unknown'
for line in os_release.split('\n'):
if line.startswith('VERSION_CODENAME='):
version_codename=line.split('=', 1)[1]
break
qmk_deb_release = requests.get(f'https://linux.qmk.fm/dists/{version_codename}/main/binary-amd64/Packages')
if qmk_deb_release.status_code != 200:
print(f'Could not fetch %s Packages file: {qmk_deb_release.status_code}: {qmk_deb_release.text}')
exit(1)
for line in qmk_deb_release.text.split('\n'):
if line.startswith('Version: '):
qmk_deb_version = line.split(' ', 1)[1].split('-')[0]
break
# If the versions don't match start the update job
if qmk_pypi_version != qmk_deb_version:
print(f'{version_codename.title()} packages are out of date!')
print(f'Triggering {gh_workflow_id} workflow at: {gh_workflow_endpoint}')
workflow_dispatch = requests.post(gh_workflow_endpoint, headers=gh_workflow_headers, json=gh_workflow_args, auth=(gh_user, gh_pat))
if workflow_dispatch.status_code != 204:
print(f'Error from GitHub API, status_code {workflow_dispatch.status_code}!')
print(workflow_dispatch.text)
exit(1)
exit(0)