-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo-task_gh_build.py
127 lines (110 loc) · 3.96 KB
/
go-task_gh_build.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import logging
import subprocess
import checksum
import tempfile
import sys
import os
import zipfile
import tarfile
from pathlib import Path
from common.common import abort_on_nonzero
from common.events import on_new_git_release
from common.common import get_correct_release_asset
from common.common import find_and_replace_templates_new
def main():
logger = logging.getLogger("Task GitHub Builds")
logger.setLevel(logging.DEBUG)
for rel in on_new_git_release("go-task", "go-task/Task"):
# correlate assets
is_tar = False
asset = get_correct_release_asset(
rel.get_assets(), "windows_386.zip", "linux_386.zip"
)
asset64 = get_correct_release_asset(
rel.get_assets(), "windows_amd64.zip", "linux_amd64.zip"
)
if asset is None or asset64 is None:
is_tar = True
asset = get_correct_release_asset(
rel.get_assets(), "Windows_i386.tar.gz", "Linux_i386.tar.gz"
)
asset64 = get_correct_release_asset(
rel.get_assets(), "Windows_x86_64.tar.gz", "Linux_x86_64.tar.gz"
)
if asset is None or asset64 is None:
logger.warn(
"Versioned release missing required assets, therefore, ineligible for packaging, skipping."
)
continue
# download and hash
url = asset.browser_download_url
url64 = asset64.browser_download_url
archive = asset.name
archive64 = asset64.name
abort_on_nonzero(subprocess.call(["wget", url, "--output-document", archive]))
abort_on_nonzero(
subprocess.call(["wget", url64, "--output-document", archive64])
)
copydir = tempfile.mkdtemp()
copydir64 = tempfile.mkdtemp()
if is_tar is False:
f = zipfile.ZipFile(archive)
f.extractall(copydir)
f.close()
os.remove(archive)
f64 = zipfile.ZipFile(archive64)
f64.extractall(copydir64)
f64.close()
os.remove(archive64)
else:
f = tarfile.open(archive, "r:gz")
f.extractall(copydir)
f.close()
os.remove(archive)
f64 = tarfile.open(archive64, "r:gz")
f64.extractall(copydir64)
f64.close()
os.remove(archive64)
i686_artifact_path = os.path.join(copydir, "task.exe")
amd64_artifact_path = os.path.join(copydir64, "task.exe")
chksum = checksum.get_for_file(i686_artifact_path, "sha512")
chksum64 = checksum.get_for_file(amd64_artifact_path, "sha512")
fname = "task.exe"
fname64 = fname
# assemble information
relnotes = rel.body
if rel.body is None:
relnotes = ""
else:
relnotes = (
relnotes.replace("<", "<")
.replace(">", ">")
.replace("&", "&")
.replace("\u200b", "")
) # zero-width space
version = rel.tag_name.replace("v", "")
gittag = rel.tag_name
d = dict(
url=url,
url64=url64,
version=version,
tag=gittag,
checksum=chksum,
fname=fname,
checksum64=chksum64,
fname64=fname64,
notes=relnotes,
)
# template and pack
tmpdir = tempfile.mkdtemp()
find_and_replace_templates_new("go-task", tmpdir, d)
# HACK: Python is dumb and won't recursively create directories sometimes, why...
os.mkdir(Path(tmpdir) / "tools/x86")
os.mkdir(Path(tmpdir) / "tools/x64")
os.rename(i686_artifact_path, os.path.join(tmpdir, "tools/x86/", fname))
os.rename(amd64_artifact_path, os.path.join(tmpdir, "tools/x64/", fname64))
abort_on_nonzero(
subprocess.call(["choco", "pack", Path(tmpdir) / "go-task.nuspec"])
)
if __name__ == "__main__":
main()