-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdev.sh
executable file
·187 lines (157 loc) · 3.8 KB
/
dev.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
set -e
build_envs=(
linux-x64
linux-arm64
osx-x64
osx-arm64
win-x64
)
help () {
cat <<EOF
$0 <command> [build_env]
help show this help message
docker docker container for development
build <build_env> build
envs show build envs
run <build_env> run the command line
EOF
}
if [ "$#" -lt 1 ]; then
help
fi
invalid_env () {
echo "Error: '$1' must be one of '${build_envs[@]}'"
help
}
command=$1;
build () {
if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters"
help
exit 1
fi
build_env=$1
if ! [[ ${build_envs[@]} =~ $build_env ]]; then
invalid_env $build_env
exit 1
fi
case "$build_env" in
"linux-x64")
dotnet publish --framework net8.0 -c Release -r linux-x64 -p:IncludeNativeLibrariesForSelfExtract=true -p:InvariantGlobalization=true OOXMLValidator.sln
;;
"linux-arm64")
dotnet publish --framework net8.0 -c Release -r linux-arm64 -p:IncludeNativeLibrariesForSelfExtract=true -p:InvariantGlobalization=true OOXMLValidator.sln
;;
"osx-x64")
dotnet publish --framework net8.0 -c Release -r osx-x64 OOXMLValidator.sln
;;
"osx-arm64")
dotnet publish --framework net8.0 -c Release -r osx-arm64 OOXMLValidator.sln
;;
"win-x64")
dotnet publish --framework net8.0 -c Release -r win-x64 OOXMLValidator.sln
;;
esac
if ! [[ "$build_env" =~ "win-" ]]; then
chmod +x "./OOXMLValidatorCLI/bin/Release/net8.0/${build_env}/publish/OOXMLValidatorCLI"
fi
}
run () {
if [ "$#" -lt 1 ]; then
echo "Illegal number of parameters"
help
exit 1
fi
build_env=$1
if ! [[ ${build_envs[@]} =~ $build_env ]]; then
invalid_env "$build_env"
exit 1
fi
if [[ "$build_env" =~ "win-" ]]; then
ext=".exe"
fi
"./OOXMLValidatorCLI/bin/Release/net8.0/${build_env}/publish/OOXMLValidatorCLI${ext}" ${*:2}
exit 0
}
test () {
if [ "$#" -lt 1 ]; then
echo "Illegal number of parameters"
help
exit 1
fi
build_env=$1
if ! [[ ${build_envs[@]} =~ $build_env ]]; then
invalid_env "$build_env"
exit 1
fi
if [[ "$build_env" =~ "win-" ]]; then
ext=".exe"
fi
shell_cmd="./${CI_SHELL_OVERRIDE:-"OOXMLValidatorCLI/bin/Release/net8.0/${build_env}/publish"}/OOXMLValidatorCLI${ext}"
echo $shell_cmd
chmod +x "${shell_cmd}"
output="$($shell_cmd)"
if [[ "$output" == "Value cannot be null." ]]; then
echo "success"
exit 0
else
echo "error:"
echo "$output"
exit 2
fi
}
envs () {
echo "${build_envs[@]}"
}
docker () {
if [[ "$DOCKER_RUNNING" == "true" ]]; then
echo "Error: Already running inside container"
help
exit 1
fi
cleanup() {
rm .build-files/Dockerfile || true
rm .build-files/compose.yaml || true
rmdir .build-files || true
}
trap cleanup EXIT
mkdir .build-files
cat << EOF > .build-files/Dockerfile
FROM ubuntu
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y dotnet-sdk-8.0
WORKDIR /code
EOF
cat << EOF > .build-files/compose.yaml
services:
dev:
build:
dockerfile: ./Dockerfile
environment:
- DOCKER_RUNNING=true
volumes:
- ../:/code
EOF
docker-compose -f .build-files/compose.yaml run dev bash
}
case "$command" in
"docker")
docker
;;
"build")
build $2
;;
"run")
run ${*:2}
;;
"envs")
envs
;;
"help")
help
;;
"test")
test $2
;;
esac