mirror of
https://github.com/ericchiang/pup
synced 2025-01-14 17:50:59 +00:00
update release script to build in a container
This commit is contained in:
parent
0e201e701a
commit
c1c3dc36d0
77
release.py
77
release.py
@ -1,77 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
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 Pup < Formula
|
||||
homepage 'https://github.com/EricChiang/pup'
|
||||
version '${version}'
|
||||
|
||||
if Hardware.is_64_bit?
|
||||
url 'https://github.com/EricChiang/pup/releases/download/v${version}/pup_darwin_amd64.zip'
|
||||
sha1 '${darwin_amd64_sha1}'
|
||||
else
|
||||
url 'https://github.com/EricChiang/pup/releases/download/v${version}/pup_darwin_386.zip'
|
||||
sha1 '${darwin_386_sha1}'
|
||||
end
|
||||
|
||||
def install
|
||||
bin.install 'pup'
|
||||
end
|
||||
end
|
||||
""".strip())
|
||||
|
||||
version_re = re.compile(r'\nvar VERSION string = \"([0-9\.]+)\"\n')
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("pup.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 pup."
|
||||
sp.check_call(["gox", "-output", "dist/{{.Dir}}_{{.OS}}_{{.Arch}}"])
|
||||
|
||||
print "[+] Zipping executables."
|
||||
sha1sums = {}
|
||||
for fi in os.listdir("./dist"):
|
||||
exe = os.path.join("dist", "pup")
|
||||
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/pup_darwin_amd64.zip"],
|
||||
darwin_386_sha1 = sha1sums["dist/pup_darwin_386.zip"],
|
||||
)
|
||||
print "[+] Updating brew formula."
|
||||
with open("pup.rb", "w") as f:
|
||||
f.write(t)
|
65
release.sh
Executable file
65
release.sh
Executable file
@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
VERSION="0.4.0"
|
||||
|
||||
rm -rf dist
|
||||
mkdir dist
|
||||
|
||||
for ENV in $( go tool dist list | grep -v 'android' | grep -v 'darwin/arm' | grep -v 's390x' | grep -v 'plan9/arm'); do
|
||||
eval $( echo $ENV | tr '/' ' ' | xargs printf 'export GOOS=%s; export GOARCH=%s\n' )
|
||||
|
||||
GOOS=${GOOS:-linux}
|
||||
GOARCH=${GOARCH:-amd64}
|
||||
|
||||
BIN="pup"
|
||||
if [ ${GOOS} == "windows" ]; then
|
||||
BIN="pup.exe"
|
||||
fi
|
||||
|
||||
mkdir -p dist
|
||||
|
||||
echo "Building for GOOS=$GOOS GOARCH=$GOARCH"
|
||||
|
||||
sudo rkt run \
|
||||
--set-env=GOOS=${GOOS} \
|
||||
--set-env=GOARCH=${GOARCH} \
|
||||
--set-env=CGO_ENABLED=0 \
|
||||
--volume pup,kind=host,source=${PWD} \
|
||||
--mount volume=pup,target=/go/src/github.com/ericchiang/pup \
|
||||
--insecure-options=image \
|
||||
docker://golang:1.6.3 \
|
||||
--exec go -- build -v -a \
|
||||
-o /go/src/github.com/ericchiang/pup/dist/${BIN} \
|
||||
github.com/ericchiang/pup
|
||||
|
||||
sudo rkt gc --grace-period=0s
|
||||
|
||||
zip dist/pup_v${VERSION}_${GOOS}_${GOARCH}.zip -j dist/${BIN}
|
||||
rm -f dist/${BIN}
|
||||
done
|
||||
|
||||
DARWIN_AMD64=pup_v${VERSION}_darwin_amd64.zip
|
||||
DARWIN_386=pup_v${VERSION}_darwin_386.zip
|
||||
|
||||
cat << EOF > pup.rb
|
||||
# This file was generated by release.sh
|
||||
require 'formula'
|
||||
class Pup < Formula
|
||||
homepage 'https://github.com/ericchiang/pup'
|
||||
version '0.4.0'
|
||||
|
||||
if Hardware.is_64_bit?
|
||||
url 'https://github.com/ericchiang/pup/releases/download/${VERSION}/${DARWIN_AMD64}'
|
||||
sha256 '$( sha256sum dist/${DARWIN_AMD64} | awk '{ print $1 }' | xargs printf )'
|
||||
else
|
||||
url 'https://github.com/ericchiang/pup/releases/download/${VERSION}/${DARWIN_386}'
|
||||
sha256 '$( sha256sum dist/${DARWIN_386} | awk '{ print $1 }' | xargs printf )'
|
||||
end
|
||||
|
||||
def install
|
||||
bin.install 'pup'
|
||||
end
|
||||
end
|
||||
EOF
|
Loading…
Reference in New Issue
Block a user