3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 # Do NOT set -x here, since that will expose a secret API token!
12 if [[ "$(uname)" != "Linux" ]]; then
13 echo "Error: this script must be run on Linux due to readlink semantics"
17 # GECKO_PATH should definitely be set
18 if [[ -z "${GECKO_PATH}" ]]; then
19 echo "Error: GECKO_PATH must point to a hg clone of mozilla-central"
23 # Internal variables, don't fiddle with these
24 MYSELF
=$
(readlink
-f ${0})
25 MYDIR
=$
(dirname "${MYSELF}")
26 WORKDIR
="${HOME}/.ghsync"
27 TMPDIR
="${WORKDIR}/tmp"
37 # Bring the project clone to a known good up-to-date state
38 if [[ ! -d "${WORKDIR}/${NAME}" ]]; then
39 echo "Setting up ${NAME} repo..."
40 git clone
"https://github.com/${DOWNSTREAM_REPO}" "${WORKDIR}/${NAME}"
41 pushd "${WORKDIR}/${NAME}"
42 git remote add moz-gfx https
://github.com
/moz-gfx
/${NAME}
45 echo "Updating ${NAME} repo..."
46 pushd "${WORKDIR}/${NAME}"
52 if [[ -n "${GITHUB_SECRET:-}" ]]; then
53 echo "Obtaining github API token..."
54 # Be careful, GITHUB_TOKEN is secret, so don't log it (or any variables
57 curl
-sSfL "$TASKCLUSTER_PROXY_URL/secrets/v1/secret/${GITHUB_SECRET}" |
58 ${MYDIR}/read-json.py
"secret/token"
60 AUTH
="moz-gfx:${GITHUB_TOKEN}"
61 CURL_AUTH
="Authorization: bearer ${GITHUB_TOKEN}"
64 echo "Pushing base ${BRANCH} branch..."
65 pushd "${WORKDIR}/${NAME}"
67 git checkout
-B ${BRANCH} moz-gfx/${BRANCH} || git checkout -B ${BRANCH} master
69 if [[ -n "${GITHUB_SECRET:-}" ]]; then
70 # git may emit error messages that contain the URL, so let's sanitize them
71 # or we might leak the auth token to the task log.
72 git push
"https://${AUTH}@github.com/moz-gfx/${NAME}" \
73 "${BRANCH}:${BRANCH}" 2>&1 | sed -e "s/${AUTH}/_SANITIZED_/g"
74 # Re-fetch to update the remote moz-gfx/$BRANCH branch in the local repo;
75 # normally the push does this but we use a fully-qualified URL for
76 # pushing so it doesn't happen.
82 echo "Running converter..."
84 "${MYDIR}/converter.py" "${WORKDIR}/${NAME}" "${RELATIVE_PATH}"
87 # Check to see if we have changes that need pushing
88 echo "Checking for new changes..."
89 pushd "${WORKDIR}/${NAME}"
90 PATCHCOUNT
=$
(git log
--oneline moz-gfx
/${BRANCH}..
${BRANCH}|
wc -l)
91 if [[ ${PATCHCOUNT} -eq 0 ]]; then
92 echo "No new patches found, aborting..."
96 # Log the new changes, just for logging purposes
97 echo "Here are the new changes:"
98 git log
--graph --stat moz-gfx
/${BRANCH}..
${BRANCH}
100 # Collect PR numbers of PRs opened on Github and merged to m-c
103 git log master..
${BRANCH} |
104 grep "\[import_pr\] From https://github.com/${DOWNSTREAM_REPO}/pull" |
105 sed -e "s%.*pull/% Fixes #%" |
112 if [[ -z "${GITHUB_SECRET:-}" ]]; then
113 echo "Running in try push, exiting now"
117 echo "Pushing new changes to moz-gfx..."
118 # git may emit error messages that contain the URL, so let's sanitize them
119 # or we might leak the auth token to the task log.
120 git push
"https://${AUTH}@github.com/moz-gfx/${NAME}" +${BRANCH}:${BRANCH} \
121 2>&1 | sed -e "s
/${AUTH}/_SANITIZED_
/g
"
123 CURL_HEADER="Accept
: application
/vnd.github.v3
+json
"
124 CURL=(curl -sSfL -H "${CURL_HEADER}" -H "${CURL_AUTH}")
125 # URL extracted here mostly to make servo-tidy happy with line lengths
126 API_URL="https
://api.github.com
/repos
/${DOWNSTREAM_REPO}"
128 # Check if there's an existing PR open
129 echo "Listing pre-existing pull requests...
"
130 "${CURL[@]}" "${API_URL}/pulls?head=moz-gfx:${BRANCH}" |
131 tee "${TMPDIR}/pr.get
"
133 COMMENT_URL=$(cat "${TMPDIR}/pr.get
" | ${MYDIR}/read-json.py "0/comments_url
")
134 HAS_COMMENT_URL="${?}"
137 if [[ ${HAS_COMMENT_URL} -ne 0 ]]; then
138 echo "Pull request not found
, creating...
"
139 # The PR doesn't exist yet, so let's create it
140 ( echo -n '{ "title
": "Sync changes from mozilla-central
'"${RELATIVE_PATH}"'"'
141 echo -n ', "body
": "'"${FIXES}"'"'
142 echo -n ', "head": "moz-gfx
:'"${BRANCH}"'"'
143 echo -n ', "base
": "master
" }'
144 ) > "${TMPDIR}/pr.create
"
145 "${CURL[@]}" -d "@${TMPDIR}/pr.create" "${API_URL}/pulls
" |
146 tee "${TMPDIR}/pr.response
"
148 cat "${TMPDIR}/pr.response
" |
149 ${MYDIR}/read-json.py "comments_url
"
153 # At this point COMMENTS_URL should be set, so leave a comment to tell bors
155 echo "Posting r
+ comment to
${COMMENT_URL}...
"
156 echo '{ "body
": "'"$BORS"' r
=auto
" }' > "${TMPDIR}/bors_rplus
"
157 "${CURL[@]}" -d "@${TMPDIR}/bors_rplus" "${COMMENT_URL}"