-
Notifications
You must be signed in to change notification settings - Fork 9
/
homebrew_bottle_pullrequest.bash
57 lines (45 loc) · 1.75 KB
/
homebrew_bottle_pullrequest.bash
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
#!/bin/bash -x
# Knowing Script dir beware of symlink
[[ -L ${0} ]] && SCRIPT_LIBDIR=$(readlink ${0}) || SCRIPT_LIBDIR=${0}
SCRIPT_LIBDIR="${SCRIPT_LIBDIR%/*}"
set -e
# directory to find the .json file generated by brew-bot with the hash
# TODO: send the directory from the DSL
BOTTLE_JSON_DIR=${WORKSPACE}/pkgs
echo '# BEGIN SECTION: check variables'
if [ -z "${ghprbCommentBody}" ]; then
echo ghprbCommentBody not specified
exit -1
fi
if [ -z "${PULL_REQUEST_URL}" ]; then
echo PULL_REQUEST_URL not specified
exit -1
fi
PULL_REQUEST_API_URL=$(echo ${PULL_REQUEST_URL} \
| sed -e 's@^https://github\.com/@https://api.github.com/repos/@' \
-e 's@/pull/\([0-9]\+\)/*$@/pulls/\1@')
PULL_REQUEST_HEAD_REPO=$(curl ${PULL_REQUEST_API_URL} \
| python3 -c 'import json, sys; print(json.loads(sys.stdin.read())["head"]["repo"]["ssh_url"])')
PULL_REQUEST_BRANCH=$(curl ${PULL_REQUEST_API_URL} \
| python3 -c 'import json, sys; print(json.loads(sys.stdin.read())["head"]["ref"])')
if [[ "${ghprbCommentBody}" =~ 'brew-bot-tag:' ]]; then
if [[ "${ghprbCommentBody}" =~ 'build-for-new-distro-' ]]; then
export KEEP_OLD=--keep-old
fi
fi
echo '# END SECTION'
# note that matrix projects use subdirectories on pkgs/ with the label of different configurations
FILES_WITH_NEW_HASH="$(find ${BOTTLE_JSON_DIR} -name '*.json')"
# call to github setup
. ${SCRIPT_LIBDIR}/_homebrew_github_setup.bash
if [ -z "${TAP_PREFIX}" ]; then
echo TAP_PREFIX not specified
exit -1
fi
echo "# BEGIN SECTION: update bottle hashes"
${BREW} bottle --merge --write --no-commit ${KEEP_OLD} ${FILES_WITH_NEW_HASH}
# ensure that all modified files are committed
export FORMULA_PATH='-a'
echo '# END SECTION'
COMMIT_MESSAGE_SUFFIX=" bottle."
. ${SCRIPT_LIBDIR}/_homebrew_github_commit.bash