forked from pantsbuild/binaries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-bintray.sh
executable file
·95 lines (82 loc) · 2.4 KB
/
sync-bintray.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
#!/usr/bin/env bash
API_HOST=api.bintray.com
ORG=pantsbuild
REPOSITORY=bin
PACKAGE=pants-support-binaries
VERSION=0.0.2
REPO_KEY="${ORG}/${REPOSITORY}/${PACKAGE}"
function check_netrc {
[[ -f ~/.netrc && -n "$(grep -E "^\s*machine\s+${API_HOST}\s*$" ~/.netrc)" ]]
}
if ! check_netrc
then
echo "In order to publish bintray binaries you need an account"
echo "with membership in the ${ORG} org [1]."
echo
echo "This account will need to be added to a ~/.netrc entry as follows:"
echo
echo "machine ${API_HOST}"
echo " login <bintray username>"
echo " password <bintray api key [2]>"
echo
echo "[1] https://bintray.com/${ORG}"
echo "[2] https://bintray.com/docs/interacting/interacting_apikeys.html"
exit 1
fi
echo "Uploading artifacts to https://dl.bintray.com/${ORG}/${REPOSITORY}"
echo
echo "Press CTRL-C at any time to discard the uploaded artifacts; otherwise,"
echo "the artifacts will be finalized and published en-masse just before the"
echo "script completes."
echo
function hash_local_files() {
git ls-files | \
grep -v -E ".sha1$" | \
xargs openssl sha1 | \
sed -E "s/^SHA1\(([^)]+)\)= ([0-9a-f]+)$/\1 \2/"
}
function hash_remote_files() {
curl --netrc -sS https://${API_HOST}/packages/${REPO_KEY}/files | \
python2.7 -c '
import json
import sys
for entry in json.load(sys.stdin):
print("{} {}".format(entry["path"], entry["sha1"]))
'
}
files=($(comm -2 -3 <(hash_local_files | sort) <(hash_remote_files | sort) | cut -d' ' -f1))
if [[ -n "${FILTER}" ]]
then
all_files="${files[@]}"
files=()
for file in ${all_files}
do
if echo ${file} | grep "${FILTER}"
then
files+=(${file})
fi
done
fi
if (( ${#files[@]} > 0 ))
then
# NB: Archives sent to bintray for exploding must not have directory entries inside, just the
# file entries; thus the --no-dir-entries argument to zip below is critical.
archive_dir=$(mktemp -dt "repo.XXXXXX") && \
trap "rm -rf ${archive_dir}" EXIT && \
archive="${archive_dir}/repo.zip" && \
echo "${files[@]}" | xargs zip -q --no-dir-entries ${archive} && \
(
echo "A zip with the following contents will be uploaded:"
echo "=="
zipinfo -1 ${archive}
) | less && \
curl \
--fail \
--netrc \
--upload-file ${archive} \
-o /dev/null \
--progress-bar \
-# \
"https://${API_HOST}/content/${REPO_KEY}/${VERSION}/repo.zip?override=1&explode=1&publish=1"
fi
echo "Bintray is up to date!"