-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathupload
executable file
·79 lines (66 loc) · 2.23 KB
/
upload
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# This file is automatically generated by fs-package
import os
import dropbox
import requests
package_data = {}
with open("PACKAGE.FS", "r") as f:
for line in f:
try:
key, value = line.strip().split("=", 1)
package_data[key] = value
except ValueError:
pass
def execute_discord_webhook(name, link):
webhook_url = os.getenv("DISCORD_WEBHOOK_URL")
if not webhook_url:
return
content = (
f"`{name}` was built and uploaded to a Dropbox "
f"[shared folder]({link})"
)
requests.post(webhook_url, {"content": content, "username": "Builder"})
def upload_branch_name():
ref = os.getenv("GITHUB_REF", "")
try:
branch = ref.split("refs/heads/", 1)[1]
except IndexError:
return None
if "/" in branch:
return None
return branch[0].upper() + branch[1:]
def upload(dbx, package, version, path):
print("Upload", path)
name = os.path.basename(path)
assert package.lower() in name.lower()
assert version in name
branch = upload_branch_name()
if not branch:
print("No upload branch name, skipping upload")
return
dst = f"/Builds/CI/{package}/{branch}/{version}/{name}"
with open(path, "rb") as f:
dbx.files_upload(f.read(), dst)
print("Uploaded ->", dst)
if os.getenv("DISCORD_WEBHOOK_URL"):
result = dbx.sharing_list_shared_links(f"/Builds/CI/{package}")
for link in result.links:
if link.path_lower == f"/Builds/CI/{package}".lower():
url = link.url
print("Found Dropbox shared link:", url)
break
else:
# Fallback URL, use first result returned
url = result.links[0].url
print("Found Dropbox shared (fallback) link:", url)
execute_discord_webhook(name, url)
def main():
dist_dir = "fsbuild/_dist"
upload_items = os.listdir(dist_dir)
dbx = dropbox.Dropbox(os.getenv("DROPBOX_ACCESS_TOKEN"))
package = package_data["PACKAGE_NAME_PRETTY"]
version = package_data["PACKAGE_VERSION"]
for item in upload_items:
upload(dbx, package, version, os.path.join(dist_dir, item))
if __name__ == "__main__":
main()