This repository has been archived by the owner on Jan 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·153 lines (126 loc) · 4.21 KB
/
install.sh
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
set -o errexit # exit script if a command fails
set -o nounset # exit when script uses undeclared vars
set -o pipefail
#set -o xtrace
action="install"
install_dir="$HOME/.vstest"
install_version=""
verbosity=0
function _log() {
printf "%s\\n" "$*"
}
function _log_debug() {
if [[ $verbosity == 1 ]]; then
printf "DEBUG: %s\\n" "$*" 1>&2
fi
}
function _log_error() {
printf "%s\\n" "$*" 1>&2
}
function verify_dependencies() {
_log_debug "Verify dependencies"
depends=(curl cp grep mktemp unzip)
for tool in "${depends[@]}"; do
if ! [ -x "$(command -v "$tool")" ]; then
_log_error "Required command '${tool}' is not available."
return 1
fi
done
}
function install_vstest() {
_log_debug "Installing vstest"
url="https://www.nuget.org/api/v2/package/Microsoft.TestPlatform.Portable"
tmpdir=$(mktemp -d 2> /dev/null || mktemp -d -t 'vstest')
nupkg=$tmpdir/Microsoft.TestPlatform.Portable.nupkg
if ! [ -d "$install_dir" ]; then
_log "Installation directory '$install_dir' does not exist. We'll create it."
mkdir "$install_dir"
_log_debug "Created install directory at '$install_dir'"
fi
if ! [ -z $install_version ]; then
_log_debug "Version is not supported yet. We'll download latest."
fi
_log "Downloading package to '$tmpdir'..."
curl --fail --location --silent --show-error --output "$nupkg" "$url"
_log_debug "Extracting nuget package in '$tmpdir'..."
unzip -oq "$nupkg" -d "$tmpdir"
_log "Installing test runner to '$install_dir'..."
cp -r "$tmpdir/tools/." "$install_dir"
_log "Installation complete"
}
function verify_install() {
_log_debug "Verifying vstest install"
console_runner="$install_dir/net451/vstest.console.exe"
console_runner_core="$install_dir/netcoreapp2.0/vstest.console.dll"
if [ -f "$console_runner" ] && [ -f "$console_runner_core" ]; then
_log "You can invoke the test runner based on target runtime..."
_log " # .NET 4.x desktop framework"
_log " > mono $console_runner </path/to/test.dll>"
_log " # .NET core framework"
_log " > dotnet $console_runner_core </path/to/test.dll>"
else
_log "Error: unable to find test runners at (all or any of) following locations..."
_log " $console_runner"
_log " $console_runner_core"
fi
}
function list_vstest_versions() {
_log_debug "available vstest versions"
info_url="https://api.nuget.org/v3-flatcontainer/Microsoft.TestPlatform.Portable/index.json"
_log "Available vstest versions:"
curl --silent $info_url --stderr - | grep -o -P "^.*\"\\d.*\""
}
function show_usage() {
printf "Usage: install.sh [OPTION]... [DIRECTORY]\\n"
printf "Install vstest runner to DIRECTORY (installs to ~/.vstest by default).\\n"
printf "\\n"
printf "Available options:\\n"
printf " -v, --version fetch the specified version of vstest runner\\n"
printf " -l, --list list available versions of vstest runner\\n"
printf " --help display this help and exit\\n"
printf "\\n"
printf "Full documentation at <https://spekt.github.io/vstest-get>.\\n"
printf "Please report any issues at <https://github.com/spekt/vstest-get/issues>.\\n"
}
function do_action() {
case "$1" in
install)
install_vstest && verify_install
;;
list)
list_vstest_versions
;;
help)
show_usage
;;
esac
}
while [[ $# -ne 0 ]]; do
case "$1" in
-l|--list)
shift
action="list"
;;
-v|--version)
install_version=$2
shift
shift
;;
--help)
shift
action="help"
;;
*)
if [[ "$1" == -* ]]; then
_log_error "install.sh: invalid option '$1'"
printf "Try 'install.sh --help' for more information."
action="error"
else
install_dir=$1
action="install"
fi
break
esac
done
verify_dependencies && do_action $action