-
Notifications
You must be signed in to change notification settings - Fork 5
/
release-carthage.sh
executable file
·124 lines (80 loc) · 3.3 KB
/
release-carthage.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
#!/bin/bash
function output () {
echo "$@"
}
function output_error () {
>&2 echo "$@"
}
function fail () {
>&2 echo "$@"
exit 1
}
function usage {
fail "Usage: $BASH_SOURCE <version>"
}
function real_base_name () {
target=$1
(
while true; do
cd "$(dirname "$target")"
target=$(basename "$target")
link=$(readlink "$target")
test "$link" || break
target=$link
done
echo "$(pwd -P)"
)
}
if [ "$#" -ne 1 ]; then
usage
fi
if [ -z "$BINTRAY_API_KEY" ]; then
fail "Please set the BINTRAY_API_KEY environment variable"
fi
RAW_VERSION="$1"
SCRIPT_DIR=$(real_base_name "$0")
VERSION="${RAW_VERSION}+nsoperations"
TEMP_DIR=$(mktemp -d)
BOTTLE_OUTPUT="$TEMP_DIR/bottle.txt"
FORMULA_FILE="$SCRIPT_DIR/Formula/carthage.rb"
trap "rm -rf ${TEMP_DIR}" INT TERM EXIT
output "Using temporary directory $TEMP_DIR"
cd "$TEMP_DIR" || fail "Could not change directories to $TEMP_DIR"
git clone https://github.com/nsoperations/carthage carthage || fail "Could not clone nsoperations/carthage from github"
cd carthage > /dev/null
git checkout master || fail "Could not checkout master branch"
TAG_EXISTS=$(git tag -l | grep "$VERSION")
if [ -n "$TAG_EXISTS" ]; then
git checkout "$VERSION"
else
git tag -a -m "Tagged version $VERSION" "$VERSION" || fail "Could not tag version $VERSION"
git push --tags || fail "Could not push tags"
fi
COMMIT_HASH=$(git rev-parse HEAD)
output "Tagged version $VERSION with commit hash $COMMIT_HASH"
cd "$SCRIPT_DIR"
git pull || fail "Could not pull from remote"
sed -i "" -E "s/^(.*:tag[[:space:]]*=>[[:space:]]*\")(.*)(\".*)$/\1${VERSION}\3/g" "$FORMULA_FILE"
sed -i "" -E "s/^(.*:version[[:space:]]*=>[[:space:]]*\")(.*)(\".*)$/\1${RAW_VERSION}\3/g" "$FORMULA_FILE"
sed -i "" -E "s/^(.*:revision[[:space:]]*=>[[:space:]]*\")(.*)(\".*)$/\1${COMMIT_HASH}\3/g" "$FORMULA_FILE"
brew uninstall carthage
brew install --build-bottle "$FORMULA_FILE" || fail "Build bottle failed"
INSTALLED_VERSION=$(/usr/local/bin/carthage version)
if [ "$INSTALLED_VERSION" != "$VERSION" ]; then
fail "The carthage version does not match the tag specified. Did you forget to update CarthageKitVersion.swift?"
fi
brew bottle --force-core-tap "$FORMULA_FILE" > "$BOTTLE_OUTPUT" || fail "Export of bottle failed"
BINARY_HASH="$(cat "$BOTTLE_OUTPUT" | sed -n -E -e 's/sha256[[:space:]]*"(.*)".*/\1/p' | tr -d '[:space:]')"
if [ -z "$BINARY_HASH" ]; then
fail "Could not extract binary hash"
fi
sed -i "" -E "s/^(.*sha256[[:space:]]*\")(.*)(\".*)$/\1${BINARY_HASH}\3/g" "$FORMULA_FILE"
output "Uploading to bintray..."
curl --show-error --fail -s --request PUT --user "werner77:${BINTRAY_API_KEY}" --header "X-Checksum-Sha2: ${BINARY_HASH}" --header "X-Bintray-Package: Carthage" --header "X-Bintray-Version: ${VERSION}" --header "X-Bintray-Publish: 1" --upload-file "./carthage--${RAW_VERSION}.mojave.bottle.tar.gz" "https://api.bintray.com/content/nsoperations/bottles-formulas/carthage-${RAW_VERSION}.mojave.bottle.tar.gz" || fail "Could not upload package to bintray"
output "Pushing updated formula"
git commit -a -m "Updated carthage formula" || fail "Could not commit formula"
git push || fail "Could not push formula to remote"
output "Testing whether install works"
brew uninstall carthage
brew install nsoperations/formulas/carthage || fail "Could not install carthage"
output "Done."