create_release.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import os
  2. from shutil import rmtree
  3. from urllib.request import Request, urlopen, urlretrieve
  4. import json
  5. try:
  6. import requests
  7. except ImportError:
  8. print("you need to do 'python -m pip install requests'");
  9. exit(0);
  10. import zipfile
  11. import io
  12. import time
  13. from datetime import date
  14. import tarfile
  15. import subprocess
  16. repo = "supermerill/SuperSlicer"
  17. program_name = "SuperSlicer"
  18. path_7zip = r"C:\Program Files\7-Zip\7z.exe"
  19. github_auth_token = "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"
  20. def get_version():
  21. settings_stream = open("./version.inc", mode="r", encoding="utf-8");
  22. lines = settings_stream.read().splitlines();
  23. for line in lines:
  24. if("SLIC3R_VERSION_FULL" in line):
  25. elems = line.split("\"");
  26. return elems[1];
  27. return "";
  28. date_str = date.today().strftime('%y%m%d');
  29. version = get_version();
  30. print("create release for: " + str(version));
  31. release_path = "./build/release_"+str(version);
  32. if(os.path.isdir(release_path)):
  33. rmtree(release_path);
  34. print("deleting old directory");
  35. os.mkdir(release_path);
  36. #urllib.urlretrieve ("https://api.github.com/repos/"+repo+"/actions/artifacts", release_path+"artifacts.json");
  37. with urlopen("https://api.github.com/repos/"+repo+"/actions/artifacts") as f:
  38. artifacts = json.loads(f.read().decode('utf-8'));
  39. found_win = False;
  40. found_linux = False;
  41. found_linux_appimage = False;
  42. found_macos = False;
  43. print("there is "+ str(artifacts["total_count"])+ " artifacts in the repo");
  44. for entry in artifacts["artifacts"]:
  45. if entry["name"] == "rc_win64" and not found_win:
  46. found_win = True;
  47. print("ask for: "+entry["archive_download_url"]);
  48. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  49. print("win: " +str(resp));
  50. z = zipfile.ZipFile(io.BytesIO(resp.content))
  51. base_name = release_path+"/"+program_name+"_"+version+"_win64_"+date_str;
  52. z.extractall(base_name);
  53. try:
  54. ret = subprocess.check_output([path_7zip, "a", "-tzip", base_name+".zip", base_name]);
  55. except:
  56. print("Failed to zip the win directory, do it yourself");
  57. if entry["name"] == "rc_macos.dmg" and not found_macos:
  58. found_macos = True;
  59. print("ask for: "+entry["archive_download_url"]);
  60. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  61. print("macos: " +str(resp));
  62. z = zipfile.ZipFile(io.BytesIO(resp.content));
  63. z.extractall(release_path);
  64. os.rename(release_path+"/"+program_name+".dmg", release_path+"/"+program_name+"_"+version+"_macos_"+date_str+".dmg");
  65. if entry["name"] == "rc-"+program_name+"-AppImage.tar" and not found_linux_appimage:
  66. found_linux_appimage = True;
  67. print("ask for: "+entry["archive_download_url"]);
  68. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  69. print("appimage: " +str(resp));
  70. z = zipfile.ZipFile(io.BytesIO(resp.content));
  71. z.extractall(release_path);
  72. my_tar = tarfile.open(release_path+"/"+program_name+"_ubu64.AppImage.tar");
  73. my_tar.extractall(release_path);
  74. my_tar.close();
  75. os.rename(release_path+"/"+program_name+"_ubu64.AppImage", release_path+"/"+program_name+"-ubuntu_18.04-" + version + ".AppImage");
  76. if entry["name"] == "rc_linux.tar" and not found_linux:
  77. found_linux = True;
  78. print("ask for: "+entry["archive_download_url"]);
  79. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  80. print("appimage: " +str(resp));
  81. z = zipfile.ZipFile(io.BytesIO(resp.content));
  82. z.extractall(release_path);
  83. base_path = release_path+"/"+program_name+"_" + version + "_linux64_" + date_str;
  84. os.rename(release_path+"/"+program_name+".tar", base_path+".tar");
  85. try:
  86. subprocess.check_output([path_7zip, "a", "-tzip", base_path+".tar.zip", base_path+".tar"]);
  87. except:
  88. with zipfile.ZipFile(base_path+"_bof.tar.zip", 'w') as myzip:
  89. myzip.write(base_path+".tar");