artifact.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 <keir.xen@gmail.com>
  5. import re, sys
  6. import requests
  7. # Latest artifact webpage:
  8. # https://nightly.link/keirf/FlashFloppy/workflows/ci/master
  9. # Github Actions artifact link and corrsponding public link:
  10. # https://github.com/keirf/FlashFloppy/suites/1623687905/artifacts/29859161
  11. # https://nightly.link/keirf/FlashFloppy/actions/artifacts/29859161
  12. def print_usage():
  13. print('artifact.py [-d] <github_artifact_url>')
  14. sys.exit(0)
  15. if not(2 <= len(sys.argv) <= 3):
  16. print_usage()
  17. if len(sys.argv) == 3:
  18. if sys.argv[1] != '-d':
  19. print_usage()
  20. download = True
  21. url = sys.argv[2]
  22. else:
  23. download = False
  24. url = sys.argv[1]
  25. url = re.sub('github.com', 'nightly.link', url)
  26. url = re.sub('suites/\d+', 'actions', url)
  27. url += '.zip'
  28. print(url)
  29. if download:
  30. res = requests.get(url)
  31. content_disposition = res.headers['Content-Disposition']
  32. zipname = re.search('filename=([^ ]+.zip);', content_disposition).group(1)
  33. print('Downloading to: ' + zipname)
  34. with open(zipname, 'wb') as f:
  35. f.write(res.content)