aboutsummaryrefslogtreecommitdiffstats
path: root/bin/build
blob: 7c76b824cc60e50739985506e7eb39df5904f1cf (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
set -e

web_only=false
dotnet_only=false
skip_tests=false
tag=$(git describe --tags)
sha=$(git rev-parse --short HEAD)
version=$tag-$sha

while test $# -gt 0; do
  case "$1" in
    -h|--help)
      echo 'options:'
      echo '-h, --help          show help'
      echo '--web-only          skip dotnet build'
      echo '--dotnet-only       skip web build'
      echo '--skip-tests        skip execution of npm and dotnet tests'
      echo '--version-suffix    version suffix for the binary. defaults to current git SHA'
      exit 0
      ;;
    --web-only)
      web_only=true
      shift
      ;;
    --dotnet-only)
      dotnet_only=true
      shift
      ;;
    --skip-tests)
      skip_tests=true
      shift
      ;;
    --version)
      shift
      version=$1
      shift
      ;;
    *)
      break
      ;;
  esac
done

if [ "$dotnet_only" == true ]; then
  echo $'\nweb build skipped\n'
else 
  # build web
  cd src/web

  echo $'\n> pwd\n'
  pwd

  echo $'\n> npm ci\n'
  npm ci

  if [ "$skip_tests" == true ]; then
      echo $'\nweb tests skipped\n'
  else
      echo $'\n> npm run test-unattended\n'
      npm run test-unattended
  fi

  echo $'\n> npm run build\n'
  npm run build

  # remove old build, but keep .gitkeep
  rm -rf ../slskd/wwwroot
  mkdir ../slskd/wwwroot
  touch ../slskd/wwwroot/.gitkeep

  # copy new files
  echo $'\n> cp -r build/* ../slskd/wwwroot/\n'
  cp -r build/* ../slskd/wwwroot/

  cd ../..
fi

if [ "$web_only" == true ]; then
    echo $'\ndotnet build skipped\n'
else
    # build api + web
    cd src/slskd

    echo $'\n> pwd\n'
    pwd

    echo $'\n> dotnet build --no-incremental --nologo --configuration Release -p:Version '$version$'\n'
    dotnet build --no-incremental --nologo --configuration Release -p:Version=$version

    if [ "$skip_tests" == true ]; then
        echo $'\ndotnet tests skipped\n'
    else
        echo $'\n> dotnet test --configuration Release ../../tests/slskd.Tests.Unit'
        dotnet test --configuration Release ../../tests/slskd.Tests.Unit

        echo $'\n> dotnet test --configuration Release ../../tests/slskd.Tests.Integration'
        dotnet test --configuration Release ../../tests/slskd.Tests.Integration
    fi
fi

echo $'\nbuild succeded.'