jenkins: Add scripts for automated builds (Linux & Mac)

This commit is contained in:
Jakob Borg 2016-08-14 22:48:11 +02:00 committed by Jakob Borg
parent 7990ffcc60
commit abb0cfde72
4 changed files with 185 additions and 1 deletions

View File

@ -642,7 +642,9 @@ func ldflags() string {
func rmr(paths ...string) {
for _, path := range paths {
log.Println("rm -r", path)
if debug {
log.Println("rm -r", path)
}
os.RemoveAll(path)
}
}

60
jenkins/build-linux.bash Executable file
View File

@ -0,0 +1,60 @@
#!/bin/bash
set -euo pipefail
# Copyright (C) 2016 The Syncthing Authors.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# This script should be run by Jenkins as './src/github.com/syncthing/syncthing/jenkins/build-linux.bash',
# that is, it should be run from $GOPATH.
. src/github.com/syncthing/syncthing/jenkins/common.bash
init
# after init we are in the source directory
clean
fetchExtra
buildSource
build
test
testWithCoverage
platforms=(
dragonfly-amd64
freebsd-amd64 freebsd-386
linux-amd64 linux-386 linux-arm linux-arm64 linux-ppc64 linux-ppc64le
netbsd-amd64 netbsd-386
openbsd-amd64 openbsd-386
solaris-amd64
)
echo Building
for plat in "${platforms[@]}"; do
echo Building "$plat"
goos="${plat%-*}"
goarch="${plat#*-}"
go run build.go -goos "$goos" -goarch "$goarch" tar
mv *.tar.gz "$WORKSPACE"
echo
done
go run build.go -goarch amd64 deb
fakeroot sh -c 'chown -R root:root deb ; dpkg-deb -b deb .'
mv *.deb "$WORKSPACE"
go run build.go -goarch i386 deb
fakeroot sh -c 'chown -R root:root deb ; dpkg-deb -b deb .'
mv *.deb "$WORKSPACE"
go run build.go -goarch armel deb
fakeroot sh -c 'chown -R root:root deb ; dpkg-deb -b deb .'
mv *.deb "$WORKSPACE"
go run build.go -goarch armhf deb
fakeroot sh -c 'chown -R root:root deb ; dpkg-deb -b deb .'
mv *.deb "$WORKSPACE"

37
jenkins/build-macos.bash Executable file
View File

@ -0,0 +1,37 @@
#!/bin/bash
set -euo pipefail
# Copyright (C) 2016 The Syncthing Authors.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# This script should be run by Jenkins as './src/github.com/syncthing/syncthing/jenkins/build-macos.bash',
# that is, it should be run from $GOPATH.
. src/github.com/syncthing/syncthing/jenkins/common.bash
init
# after init we are in the source directory
clean
fetchExtra
build
test
platforms=(
darwin-amd64 darwin-386
)
echo Building
for plat in "${platforms[@]}"; do
echo Building "$plat"
goos="${plat%-*}"
goarch="${plat#*-}"
go run build.go -goos "$goos" -goarch "$goarch" tar
mv *.tar.gz "$WORKSPACE"
echo
done

85
jenkins/common.bash Normal file
View File

@ -0,0 +1,85 @@
#!/bin/bash
set -euo pipefail
# Copyright (C) 2016 The Syncthing Authors.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
ulimit -t 600 || true
ulimit -d 1024000 || true
ulimit -m 1024000 || true
export CGO_ENABLED=0
export GO386=387
export GOARM=5
function init {
echo Initializing
export GOPATH=$(pwd)
export WORKSPACE="${WORKSPACE:-$GOPATH}"
go version
rm -f *.tar.gz *.zip *.deb
cd src/github.com/syncthing/syncthing
version=$(git describe)
echo "Building $version"
echo
}
function clean {
echo Cleaning
rm -rf "$GOPATH/pkg"
git clean -fxd
git fetch --prune
echo
}
function fetchExtra {
echo Fetching extra resources
mkdir extra
curl -s -o extra/Getting-Started.pdf http://docs.syncthing.net/pdf/Getting-Started.pdf
curl -s -o extra/FAQ.pdf http://docs.syncthing.net/pdf/FAQ.pdf
echo
}
function checkAuthorsCopyright {
echo Basic metadata checks
go run script/check-authors.go
go run script/check-copyright.go lib/ cmd/ script/
echo
}
function build {
echo Build
go run build.go
echo
}
function test {
echo Test with race
CGO_ENABLED=1 go run build.go -race test
echo
}
function testWithCoverage {
echo Test with coverage
CGO_ENABLED=1 ./build.sh test-cov
notCovered=$(egrep -c '\s0$' coverage.out)
total=$(wc -l coverage.out | awk '{print $1}')
coverPct=$(awk "BEGIN{print (1 - $notCovered / $total) * 100}")
echo "$coverPct" > "coverage.txt"
echo "Test coverage is $coverPct%%"
echo
}
function buildSource {
echo Archiving source
echo "$version" > RELEASE
pushd .. >/dev/null
tar c -z -f "$WORKSPACE/syncthing-source-$version.tar.gz" --exclude .git syncthing
popd >/dev/null
echo
}