-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathentrypoint.py
executable file
·44 lines (39 loc) · 1.33 KB
/
entrypoint.py
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
#!/usr/bin/env python3
from github import Github
import os
# Try to get options from enviroment and from inputs as fallback
wanted_release = os.getenv('type', os.getenv('INPUT_TYPE'))
repository = os.getenv('repository', os.getenv('INPUT_REPOSITORY'))
token = os.getenv('token', os.getenv('INPUT_TOKEN', None))
# Init class
G = Github(token) if token else Github()
repo = G.get_repo(repository)
releases = repo.get_releases()
# Output formatting function
def output(release):
outfile = open(os.getenv('GITHUB_OUTPUT'), 'w')
outfile.write(f'release={release.tag_name}\n')
outfile.write(f'release_id={release.id}\n')
assets = release.get_assets()
dl_url = assets[0].browser_download_url if assets.totalCount > 0 else '""'
outfile.write(f'browser_download_url={dl_url}\n')
outfile.close()
# Releases parsing
for release in releases:
if wanted_release == 'stable':
if release.prerelease == 0 and release.draft == 0:
output(release)
break
elif wanted_release == 'prerelease':
if release.prerelease == 1:
output(release)
break
elif wanted_release == 'latest':
output(release)
break
elif wanted_release == 'nodraft':
if release.draft == 0:
output(release)
break
else:
print('Can\'t get release')