common.bash 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 https://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. rm -rf parts # created by snapcraft, contains git repo so not cleaned by git above
  30. echo
  31. }
  32. function fetchExtra {
  33. echo Fetching extra resources
  34. mkdir extra
  35. curl -s -o extra/Getting-Started.pdf https://docs.syncthing.net/pdf/Getting-Started.pdf
  36. curl -s -o extra/FAQ.pdf https://docs.syncthing.net/pdf/FAQ.pdf
  37. echo
  38. }
  39. function checkAuthorsCopyright {
  40. echo Basic metadata checks
  41. go run script/check-authors.go
  42. go run script/check-copyright.go lib/ cmd/ script/
  43. echo
  44. }
  45. function build {
  46. echo Build
  47. go run build.go
  48. echo
  49. }
  50. function test {
  51. echo Test with race
  52. CGO_ENABLED=1 go run build.go -race test
  53. echo
  54. }
  55. function testWithCoverage {
  56. echo Test with coverage
  57. CGO_ENABLED=1 ./build.sh test-cov
  58. notCovered=$(egrep -c '\s0$' coverage.out)
  59. total=$(wc -l coverage.out | awk '{print $1}')
  60. coverPct=$(awk "BEGIN{print (1 - $notCovered / $total) * 100}")
  61. echo "$coverPct" > "coverage.txt"
  62. echo "Test coverage is $coverPct%%"
  63. echo
  64. }
  65. function buildSource {
  66. echo Archiving source
  67. echo "$version" > RELEASE
  68. pushd .. >/dev/null
  69. tar c -z -f "$WORKSPACE/syncthing-source-$version.tar.gz" --exclude .git syncthing
  70. popd >/dev/null
  71. echo
  72. }