common.bash 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. set -euo pipefail
  3. # Copyright (C) 2016 The Syncthing Authors.
  4. #
  5. # This Source Code Form is subject to the terms of the Mozilla Public
  6. # License, v. 2.0. If a copy of the MPL was not distributed with this file,
  7. # You can obtain one at http://mozilla.org/MPL/2.0/.
  8. ulimit -t 600 || true
  9. ulimit -d 1024000 || true
  10. ulimit -m 1024000 || true
  11. export CGO_ENABLED=0
  12. export GO386=387
  13. export GOARM=5
  14. function init {
  15. echo Initializing
  16. export GOPATH=$(pwd)
  17. export WORKSPACE="${WORKSPACE:-$GOPATH}"
  18. go version
  19. rm -f *.tar.gz *.zip *.deb *.snap
  20. cd src/github.com/syncthing/syncthing
  21. version=$(go run build.go version)
  22. echo "Building $version"
  23. echo
  24. }
  25. function clean {
  26. echo Cleaning
  27. rm -rf "$GOPATH/pkg"
  28. git clean -fxd
  29. echo
  30. }
  31. function fetchExtra {
  32. echo Fetching extra resources
  33. mkdir extra
  34. curl -s -o extra/Getting-Started.pdf https://docs.syncthing.net/pdf/Getting-Started.pdf
  35. curl -s -o extra/FAQ.pdf https://docs.syncthing.net/pdf/FAQ.pdf
  36. echo
  37. }
  38. function checkAuthorsCopyright {
  39. echo Basic metadata checks
  40. go run script/check-authors.go
  41. go run script/check-copyright.go lib/ cmd/ script/
  42. echo
  43. }
  44. function build {
  45. echo Build
  46. go run build.go
  47. echo
  48. }
  49. function test {
  50. echo Test with race
  51. CGO_ENABLED=1 go run build.go -race test
  52. echo
  53. }
  54. function testWithCoverage {
  55. echo Test with coverage
  56. CGO_ENABLED=1 ./build.sh test-cov
  57. notCovered=$(egrep -c '\s0$' coverage.out)
  58. total=$(wc -l coverage.out | awk '{print $1}')
  59. coverPct=$(awk "BEGIN{print (1 - $notCovered / $total) * 100}")
  60. echo "$coverPct" > "coverage.txt"
  61. echo "Test coverage is $coverPct%%"
  62. echo
  63. }
  64. function buildSource {
  65. echo Archiving source
  66. echo "$version" > RELEASE
  67. pushd .. >/dev/null
  68. tar c -z -f "$WORKSPACE/syncthing-source-$version.tar.gz" --exclude .git syncthing
  69. popd >/dev/null
  70. echo
  71. }