-
Notifications
You must be signed in to change notification settings - Fork 8
/
release.sh
executable file
·137 lines (121 loc) · 4.45 KB
/
release.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
#!/bin/bash
set -e
set -x
RUST_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd )"
source "$RUST_DIR/scripts/gzip-and-sum.sh"
ARTIFACTS_DIR=${ARTIFACTS_DIR:-"$RUST_DIR/release_artifacts"}
mkdir -p "$ARTIFACTS_DIR"
export CARGO_TARGET_DIR=${CARO_TARGET_DIR:-"$RUST_DIR/target"}
if [ $# -lt 2 ]
then
echo "Usage : $0 <Linux|Windows|macOS> <release version> <cargo flags>"
exit
fi
APP=pact-protobuf-plugin
OS=$1
shift;
VERSION=$1
shift;
echo Building Release for "$OS"
# All flags passed to this script are passed to cargo.
cargo_flags=( "$@" )
build_manifest() {
NEXT=$(echo "$VERSION" | sed 's/^refs\/tags\/v-//')
# get latest release tag, if NEXT still contains refs
if [[ "${NEXT}" =~ "refs"* ]]; then
CRATE_VERSION=$(cat Cargo.toml| grep 'version = ".*"' -m1 | cut -d '"' -f 2)
echo "defaulting NEXT=$VERSION to version from Cargo.toml $CRATE_VERSION"
NEXT=$CRATE_VERSION
# LATEST_RELEASE=$(echo $(curl -s https://api.github.com/repos/pact-foundation/pact-stub-server/releases/latest | jq -r '.name') | sed 's/v//')
# echo "defaulting NEXT=$VERSION to latest release $LATEST_RELEASE"
# NEXT=$LATEST_RELEASE
fi
sed -e 's/\"version\": \".*\"/\"version\": \"'${NEXT}'\"/' "$RUST_DIR/pact-plugin.json" > "$ARTIFACTS_DIR/pact-plugin.json"
sed -e 's/VERSION=\".*\"/VERSION=\"'${NEXT}'\"/' "$RUST_DIR/scripts/install-plugin.sh" > "$ARTIFACTS_DIR/install-plugin.sh"
openssl dgst -sha256 -r $ARTIFACTS_DIR/install-plugin.sh > "$ARTIFACTS_DIR/install-plugin.sh.sha256"
}
install_cross() {
cargo install cross@0.2.5
}
build_linux_x86_64() {
install_cross
cargo clean
cross build --target=x86_64-unknown-linux-musl "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-linux-x86_64.gz"
# cargo clean
fi
}
build_linux_aarch64() {
install_cross
cargo clean
cross build --target=aarch64-unknown-linux-musl "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-linux-aarch64.gz"
fi
}
# Build the x86_64 darwin release
build_macos_x86_64() {
cargo build --target x86_64-apple-darwin "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-osx-x86_64.gz"
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-macos-x86_64.gz"
fi
}
# Build the aarch64 darwin release
build_macos_aarch64() {
cargo build --target aarch64-apple-darwin "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-osx-aarch64.gz"
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/${APP}" \
"$ARTIFACTS_DIR/${APP}-macos-aarch64.gz"
fi
}
# Build the x86_64 windows release
build_windows_x86_64() {
cargo build --target x86_64-pc-windows-msvc "${cargo_flags[@]}"
# If --release in cargo flags, then gzip and sum the release artifacts
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/x86_64-pc-windows-msvc/release/${APP}.exe" \
"$ARTIFACTS_DIR/${APP}-windows-x86_64.exe.gz"
fi
}
# Build the aarch64 windows release
build_windows_aarch64() {
cargo build --target aarch64-pc-windows-msvc "${cargo_flags[@]}"
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then
gzip_and_sum \
"$CARGO_TARGET_DIR/aarch64-pc-windows-msvc/release/${APP}.exe" \
"$ARTIFACTS_DIR/${APP}-windows-aarch64.exe.gz"
fi
}
case "$OS" in
Linux) echo "Building for Linux"
build_linux_x86_64
build_linux_aarch64
build_manifest
;;
Windows) echo "Building for windows"
build_windows_x86_64
build_windows_aarch64
;;
macOS) echo "Building for macos"
build_macos_x86_64
build_macos_aarch64
;;
*) echo "$OS is not a recognised OS"
exit 1
;;
esac