-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcross_compile.sh
executable file
·99 lines (77 loc) · 2.42 KB
/
cross_compile.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
#!/bin/bash
dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
mkdir -p $dir/out/
rm -f $dir/out/*
platforms=(
"linux/arm"
"linux/amd64"
"linux/arm64"
"linux/386"
"darwin/amd64"
"darwin/arm64"
"windows/386"
"windows/amd64"
"windows/arm64")
projects=(
"cli"
"backend")
VER="$(go run ./utils/print_version.go)"
RELEASE_NOTES_FILE="$dir/out/RELEASE_NOTES.txt"
RELEASE_NOTES_LINK="https://github.com/benbusby/yeetfile/releases/download/v$VER"
cat >$RELEASE_NOTES_FILE <<EOL
___
Linux, macOS, and Windows binaries for the CLI app and for the server are included below. These archives contain a single executable that you can run on your machine.
EOL
capitalize()
{
printf '%s' "$1" | head -c 1 | tr [:lower:] [:upper:]
printf '%s' "$1" | tail -c '+2'
}
for project in "${projects[@]}"
do
project_name=$project
if [ $project = "cli" ]; then
project_name=$(echo $project_name | tr '[a-z]' '[A-Z]')
else
project_name=$(capitalize $project)
fi
printf -- "### $project_name\n\n" >> $RELEASE_NOTES_FILE
for platform in "${platforms[@]}"
do
echo "Compiling $project for $platform..."
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
os_name=$(capitalize $GOOS)
arch_name=$GOARCH
if [ $project = "cli" ]; then
output_name="yeetfile"
else
output_name="yeetfile-server"
fi
if [ $GOARCH = "arm" ]; then
arch_name="arm32"
fi
tar_name="${output_name}_${GOOS}_${arch_name}_${VER}.tar.gz"
if [ $GOOS = "darwin" ]; then
os_name="macOS"
tar_name="${output_name}_macos_${arch_name}_${VER}.tar.gz"
fi
if [ $GOOS = "windows" ]; then
output_name+=".exe"
fi
compile_cmd="GOOS=$GOOS GOARCH=$GOARCH go build -ldflags='-s -w' -o $output_name ./$project"
echo "└ $compile_cmd"
eval $compile_cmd
if [ $? -ne 0 ]; then
echo "An error has occurred! Aborting the script execution..."
exit 1
fi
tar -czvf out/$tar_name $output_name
rm -f $output_name
full_link="$RELEASE_NOTES_LINK/$tar_name"
printf -- "- $os_name (\`$arch_name\`): [$tar_name]($full_link)\n" >> $RELEASE_NOTES_FILE
done
printf "\n" >> $RELEASE_NOTES_FILE
done
cat $RELEASE_NOTES_FILE