This repository was archived by the owner on Mar 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrelease.py
More file actions
80 lines (69 loc) · 2.24 KB
/
release.py
File metadata and controls
80 lines (69 loc) · 2.24 KB
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
#!/usr/bin/env python
"""
This is just a script to help automate the release of the Go binary, nothing
to see here!
"""
import hashlib
import os
import re
import shutil
import subprocess as sp
from string import Template
from zipfile import ZipFile
brew_formula_template = Template("""
# This file was generated by release.py
require 'formula'
class Ws < Formula
homepage 'https://github.com/yhat/ws'
version '${version}'
if Hardware.is_64_bit?
url 'https://github.com/yhat/ws/releases/download/v${version}/ws_darwin_amd64.zip'
sha1 '${darwin_amd64_sha1}'
else
url 'https://github.com/yhat/ws/releases/download/v${version}/ws_darwin_386.zip'
sha1 '${darwin_386_sha1}'
end
def install
bin.install 'ws'
end
end
""".strip())
version_re = re.compile(r'\nconst VERSION = \"([0-9\.]+)\"\n')
if __name__ == "__main__":
with open("main.go", "r") as f:
version = version_re.findall(f.read())
assert len(version) == 1, "[-] Failed to find current version %s" % (version,)
version = version[0]
print "[+] Version found:", version
if os.path.isdir("./dist"):
print "[+] Directory 'dist' exists. Removing it."
shutil.rmtree("./dist")
print "[+] Cross-compiling ws."
sp.check_call(["gox", "-output", "dist/{{.Dir}}_{{.OS}}_{{.Arch}}"])
print "[+] Zipping executables."
sha1sums = {}
for fi in os.listdir("./dist"):
exe = os.path.join("dist", "ws")
zipname = os.path.join("dist", fi)
if fi.endswith(".exe"):
exe += ".exe"
zipname = zipname.rstrip(".exe")
zipname += ".zip"
os.rename(os.path.join("dist", fi), exe)
with ZipFile(zipname, "w") as z:
z.write(exe, os.path.basename(exe))
os.remove(exe)
h = hashlib.sha1()
with open(zipname, "r") as z:
h.update(z.read())
sha1sum = h.hexdigest()
print "[+] %s: %s" % (sha1sum, zipname,)
sha1sums[zipname] = sha1sum
t = brew_formula_template.substitute(
version=version,
darwin_amd64_sha1 = sha1sums["dist/ws_darwin_amd64.zip"],
darwin_386_sha1 = sha1sums["dist/ws_darwin_386.zip"],
)
print "[+] Updating brew formula."
with open("ws.rb", "w") as f:
f.write(t)