chore(deps): update asf-ui digest to 28133ae
[ArchiSteamFarm.git] / cc.sh
blob44182dce734721f905205afa7457ed592effd6c2
1 #!/usr/bin/env sh
2 set -eu
4 MAIN_PROJECT="ArchiSteamFarm"
5 STEAM_TOKEN_DUMPER_NAME="${MAIN_PROJECT}.OfficialPlugins.SteamTokenDumper"
6 TESTS_PROJECT="${MAIN_PROJECT}.Tests"
7 SOLUTION="${MAIN_PROJECT}.sln"
8 CONFIGURATION="Release"
9 OUT="out"
10 OUT_ASF="${OUT}/result"
11 PLUGINS="${MAIN_PROJECT}.OfficialPlugins.ItemsMatcher ${MAIN_PROJECT}.OfficialPlugins.MobileAuthenticator"
13 ANALYSIS=1
14 ASF_UI=1
15 CLEAN=0
16 PULL=1
17 SHARED_COMPILATION=1
18 TEST=1
20 PRINT_USAGE() {
21 echo "Usage: $0 [--clean] [--no-analysis] [--no-asf-ui] [--no-pull] [--no-shared-compilation] [--no-test] [debug/release]"
24 OS_TYPE="$(uname -s)"
26 case "$OS_TYPE" in
27 "Darwin") SCRIPT_PATH="$(readlink "$0")" ;;
28 "FreeBSD") SCRIPT_PATH="$(readlink -f "$0")" ;;
29 "Linux") SCRIPT_PATH="$(readlink -f "$0")" ;;
30 *) echo "ERROR: Unknown OS type: ${OS_TYPE}. If you believe that our script should work on your machine, please let us know."; exit 1
31 esac
33 SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
35 cd "$SCRIPT_DIR"
37 for ARG in "$@"; do
38 case "$ARG" in
39 debug|Debug) CONFIGURATION="Debug" ;;
40 release|Release) CONFIGURATION="Release" ;;
41 --analysis) ANALYSIS=1 ;;
42 --no-analysis) ANALYSIS=0 ;;
43 --asf-ui) ASF_UI=1 ;;
44 --no-asf-ui) ASF_UI=0 ;;
45 --clean) CLEAN=1 ;;
46 --no-clean) CLEAN=0 ;;
47 --pull) PULL=1 ;;
48 --no-pull) PULL=0 ;;
49 --shared-compilation) SHARED_COMPILATION=1 ;;
50 --no-shared-compilation) SHARED_COMPILATION=0 ;;
51 --test) TEST=1 ;;
52 --no-test) TEST=0 ;;
53 --help) PRINT_USAGE; exit 0 ;;
54 *) PRINT_USAGE; exit 1
55 esac
56 done
58 trap "trap - TERM && kill -- -$$" INT TERM
60 if ! command -v dotnet >/dev/null; then
61 echo "ERROR: dotnet CLI tools are not installed!"
62 exit 1
65 dotnet --info
67 if [ "$PULL" -eq 1 ] && [ -d ".git" ] && command -v git >/dev/null; then
68 git pull --recurse-submodules=on-demand || true
71 if [ ! -f "$SOLUTION" ]; then
72 echo "ERROR: $SOLUTION could not be found!"
73 exit 1
76 case "$OS_TYPE" in
77 "Darwin") os_type="osx" ;;
78 "FreeBSD") os_type="freebsd" ;;
79 "Linux") os_type="linux" ;;
80 *) echo "ERROR: Unknown OS type: ${OS_TYPE}. If you believe that our script should work on your machine, please let us know."; exit 1
81 esac
83 cpu_architecture="$(uname -m)"
85 case "$cpu_architecture" in
86 "aarch64") cpu_architecture="arm64" ;;
87 "amd64") cpu_architecture="x64" ;;
88 "arm64") ;;
89 "armv7l") cpu_architecture="arm" ;;
90 "x86_64") cpu_architecture="x64" ;;
91 *) echo "ERROR: Unknown CPU architecture: ${cpu_architecture}. If you believe that our script should work on your machine, please let us know."; exit 1
92 esac
94 echo "INFO: Detected ${os_type}-${cpu_architecture} machine."
96 if [ "$ASF_UI" -eq 1 ]; then
97 if [ -f "ASF-ui/package.json" ] && command -v npm >/dev/null; then
98 echo "INFO: Building ASF-ui..."
100 # ASF-ui doesn't clean itself after old build
101 rm -rf "ASF-ui/dist"
103 npm ci --no-progress --prefix ASF-ui
104 npm run-script deploy --no-progress --prefix ASF-ui
106 # ASF's output www folder needs cleaning as well
107 rm -rf "${OUT_ASF}/www"
108 else
109 echo "WARNING: ASF-ui dependencies are missing, skipping build of ASF-ui..."
113 DOTNET_FLAGS="-c $CONFIGURATION -p:ContinuousIntegrationBuild=true -p:UseAppHost=false --nologo"
114 PUBLISH_FLAGS="-r ${os_type}-${cpu_architecture} --no-self-contained"
116 if [ "$ANALYSIS" -eq 0 ]; then
117 DOTNET_FLAGS="$DOTNET_FLAGS -p:AnalysisMode=AllDisabledByDefault"
120 if [ "$SHARED_COMPILATION" -eq 0 ]; then
121 DOTNET_FLAGS="$DOTNET_FLAGS -p:UseSharedCompilation=false"
124 if [ "$CLEAN" -eq 1 ]; then
125 dotnet clean $DOTNET_FLAGS
126 rm -rf "$OUT"
129 if [ "$TEST" -eq 1 ]; then
130 dotnet test "$TESTS_PROJECT" $DOTNET_FLAGS
133 echo "INFO: Building ${MAIN_PROJECT}..."
135 dotnet publish "$MAIN_PROJECT" -o "$OUT_ASF" $DOTNET_FLAGS $PUBLISH_FLAGS
137 if [ -n "${STEAM_TOKEN_DUMPER_TOKEN-}" ] && [ -f "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs" ] && command -v git >/dev/null; then
138 git checkout -- "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs"
139 sed "s/STEAM_TOKEN_DUMPER_TOKEN/${STEAM_TOKEN_DUMPER_TOKEN}/g" "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs" > "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs.new";
140 mv "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs.new" "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs"
142 echo "INFO: Building ${STEAM_TOKEN_DUMPER_NAME}..."
144 dotnet publish "$STEAM_TOKEN_DUMPER_NAME" -o "${OUT_ASF}/plugins/${STEAM_TOKEN_DUMPER_NAME}" $DOTNET_FLAGS $PUBLISH_FLAGS
145 git checkout -- "${STEAM_TOKEN_DUMPER_NAME}/SharedInfo.cs"
146 else
147 echo "WARNING: ${STEAM_TOKEN_DUMPER_NAME} dependencies are missing, skipping build of ${STEAM_TOKEN_DUMPER_NAME}..."
150 for plugin in $PLUGINS; do
151 echo "INFO: Building ${plugin}..."
153 dotnet publish "$plugin" -o "${OUT_ASF}/plugins/${plugin}" $DOTNET_FLAGS $PUBLISH_FLAGS
154 done
156 echo
157 echo "SUCCESS: Compilation finished successfully! :)"