create_release.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_gtk2 = False;
  42. found_linux_appimage_gtk3 = False;
  43. found_macos = False;
  44. found_macos_arm = False;
  45. print("there is "+ str(artifacts["total_count"])+ " artifacts in the repo");
  46. for entry in artifacts["artifacts"]:
  47. if entry["name"] == "rc_win64" and not found_win:
  48. found_win = True;
  49. print("ask for: "+entry["archive_download_url"]);
  50. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  51. print("win: " +str(resp));
  52. z = zipfile.ZipFile(io.BytesIO(resp.content))
  53. base_name = release_path+"/"+program_name+"_"+version+"_win64_"+date_str;
  54. z.extractall(base_name);
  55. try:
  56. ret = subprocess.check_output([path_7zip, "a", "-tzip", base_name+".zip", base_name]);
  57. except:
  58. print("Failed to zip the win directory, do it yourself");
  59. if entry["name"] == "rc_macos.dmg" and not found_macos:
  60. found_macos = True;
  61. print("ask for: "+entry["archive_download_url"]);
  62. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  63. print("macos: " +str(resp));
  64. z = zipfile.ZipFile(io.BytesIO(resp.content));
  65. z.extractall(release_path);
  66. os.rename(release_path+"/"+program_name+".dmg", release_path+"/"+program_name+"_"+version+"_macos_"+date_str+".dmg");
  67. # if entry["name"] == "rc_arm_macos.dmg" and not found_macos_arm:
  68. # found_macos_arm = True;
  69. # print("ask for: "+entry["archive_download_url"]);
  70. # resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  71. # print("macos-arm: " +str(resp));
  72. # z = zipfile.ZipFile(io.BytesIO(resp.content));
  73. # z.extractall(release_path);
  74. # os.rename(release_path+"/"+program_name+".dmg", release_path+"/"+program_name+"_"+version+"_macos_arm_"+date_str+".dmg");
  75. if entry["name"] == "rc-"+program_name+"-gtk2.AppImage" and not found_linux_appimage_gtk2:
  76. found_linux_appimage_gtk2 = True;
  77. print("ask for: "+entry["archive_download_url"]);
  78. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  79. print("gtk2 appimage: " +str(resp));
  80. z = zipfile.ZipFile(io.BytesIO(resp.content));
  81. z.extractall(release_path);
  82. os.rename(release_path+"/"+program_name+"_ubu64.AppImage", release_path+"/"+program_name+"-ubuntu_18.04-gtk2-" + version + ".AppImage");
  83. if entry["name"] == "rc-"+program_name+"-gtk3.AppImage" and not found_linux_appimage_gtk3:
  84. found_linux_appimage_gtk3 = True;
  85. print("ask for: "+entry["archive_download_url"]);
  86. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  87. print("gtk3 appimage: " +str(resp));
  88. z = zipfile.ZipFile(io.BytesIO(resp.content));
  89. z.extractall(release_path);
  90. os.rename(release_path+"/"+program_name+"_ubu64.AppImage", release_path+"/"+program_name+"-ubuntu_18.04-" + version + ".AppImage");
  91. if entry["name"] == "rc_linux_gtk3.tar" and not found_linux:
  92. found_linux = True;
  93. print("ask for: "+entry["archive_download_url"]);
  94. resp = requests.get(entry["archive_download_url"], headers={'Authorization': 'token ' + github_auth_token,}, allow_redirects=True);
  95. print("gtk3 archive: " +str(resp));
  96. z = zipfile.ZipFile(io.BytesIO(resp.content));
  97. z.extractall(release_path);
  98. base_path = release_path+"/"+program_name+"_" + version + "_linux64_" + date_str;
  99. os.rename(release_path+"/"+program_name+".tar", base_path+".tar");
  100. try:
  101. subprocess.check_output([path_7zip, "a", "-tzip", base_path+".tar.zip", base_path+".tar"]);
  102. os.remove(base_path+".tar");
  103. except:
  104. with zipfile.ZipFile(base_path+"_bof.tar.zip", 'w') as myzip:
  105. myzip.write(base_path+".tar");
  106. print("DONT FORGET TO PUSH YOUR MASTER");