Debian Codegraph @

scripts/misc/artifact.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 # Create a public download link for any of my Github Actions artifacts.
3 # Optionally download the zip file.
4 # Written & released by Keir Fraser <[email protected]>
5
6 import re, sys
7 import requests
8
9 # Latest artifact webpage:
10 # https://nightly.link/keirf/FlashFloppy/workflows/ci/master
11
12 # Github Actions artifact link and corrsponding public link:
13 # https://github.com/keirf/FlashFloppy/suites/1623687905/artifacts/29859161
14 # https://nightly.link/keirf/FlashFloppy/actions/artifacts/29859161
15
16 def print_usage():
17 print('artifact.py [-d] <github_artifact_url>')
18 sys.exit(0)
19
20 if not(2 <= len(sys.argv) <= 3):
21 print_usage()
22 if len(sys.argv) == 3:
23 if sys.argv[1] != '-d':
24 print_usage()
25 download = True
26 url = sys.argv[2]
27 else:
28 download = False
29 url = sys.argv[1]
30
31 url = re.sub(r'github.com', 'nightly.link', url)
32 url = re.sub(r'suites/\d+', 'actions', url)
33 url += '.zip'
34 print(url)
35
36 if download:
37 res = requests.get(url)
38 content_disposition = res.headers['Content-Disposition']
39 zipname = re.search(r'filename=([^ ]+.zip);', content_disposition).group(1)
40 print('Downloading to: ' + zipname)
41 with open(zipname, 'wb') as f:
42 f.write(res.content)