download_codecov_cli.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python3
  2. import os
  3. import subprocess
  4. import urllib.request
  5. def download_file(url, filename):
  6. chunk_size = 1024 * 1024 # 1 MB chunks
  7. with urllib.request.urlopen(url) as response:
  8. with open(filename, "wb") as out_file:
  9. while True:
  10. chunk = response.read(chunk_size)
  11. if not chunk:
  12. break
  13. out_file.write(chunk)
  14. def run_command(command):
  15. # check true so if the command fails the entire script fails
  16. subprocess.run(command, check=True)
  17. def main():
  18. key_url = "https://keybase.io/codecovsecurity/pgp_keys.asc"
  19. cli_url = "https://cli.codecov.io/latest/linux/codecov"
  20. sha256sum_url = "https://cli.codecov.io/latest/linux/codecov.SHA256SUM"
  21. sha256sig_url = "https://cli.codecov.io/latest/linux/codecov.SHA256SUM.sig"
  22. download_file(key_url, "pgp_keys.asc")
  23. run_command(
  24. ["gpg", "--no-default-keyring", "--keyring", "trustedkeys.gpg", "--import", "pgp_keys.asc"]
  25. )
  26. download_file(cli_url, "codecov")
  27. download_file(sha256sum_url, "codecov.SHA256SUM")
  28. download_file(sha256sig_url, "codecov.SHA256SUM.sig")
  29. run_command(["gpgv", "codecov.SHA256SUM.sig", "codecov.SHA256SUM"])
  30. run_command(["shasum", "-a", "256", "-c", "codecov.SHA256SUM"])
  31. os.chmod("codecov", 0o755)
  32. if __name__ == "__main__":
  33. main()