Skip to content

Commit 540741a

Browse files
committed
add verbose output to homebrew sync script
make pr body nice add build-id so we can redrive failed syncs
1 parent 5df83d2 commit 540741a

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

scripts/sync-to-aws-homebrew-tap

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22
set -euo pipefail
3-
3+
set -x
44
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
55
BUILD_DIR="${SCRIPTPATH}/../build"
6+
BUILD_ID=$(uuidgen | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]')
67

78
TAP_REPO="aws/homebrew-tap"
89
TAP_NAME=$(echo ${TAP_REPO} | cut -d'/' -f2)
@@ -70,13 +71,17 @@ while getopts "p:b:r:v:d" opt; do
7071
done
7172

7273
if [[ -z "${BINARY_BASE}" ]]; then
73-
echo "Binary Basename (-b) must be specified"
74-
exit 3
74+
echo "Binary Basename (-b) must be specified"
75+
exit 3
7576
fi
7677

7778
if [[ ! "${VERSION}" =~ $VERSION_REGEX ]]; then
78-
echo "🙈 Not on a current release, so not syncing with tap $TAP_REPO"
79-
exit 3
79+
echo "🙈 Not on a current release, so not syncing with tap $TAP_REPO"
80+
exit 3
81+
fi
82+
83+
if [[ -z "${REPO}" ]]; then
84+
echo "Repo (-r) must be specified if no \"make repo-full-name\" target exists"
8085
fi
8186

8287
if [[ -z $(command -v gh) ]] || [[ ! $(gh --version) =~ $GH_CLI_VERSION ]]; then
@@ -182,20 +187,42 @@ if [[ "${DRY_RUN}" -eq 0 ]]; then
182187
exit 4
183188
fi
184189
cd "${SYNC_DIR}"
185-
gh repo fork $TAP_REPO --clone --remote
190+
gh repo fork $TAP_REPO --clone=false --remote=false
186191
cd "${FORK_DIR}"
187192
git remote set-url origin https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${GITHUB_USERNAME}/${TAP_NAME}.git
188193
DEFAULT_BRANCH=$(git rev-parse --abbrev-ref HEAD | tr -d '\n')
189194

190195
cp "${BREW_CONFIG_DIR}/${BINARY_BASE}.json" "${FORK_DIR}/bottle-configs/${BINARY_BASE}.json"
191196

192-
git checkout -b "${BINARY_BASE}-${VERSION}" upstream/${DEFAULT_BRANCH}
197+
FORK_RELEASE_BRANCH="${BINARY_BASE}-${VERSION}-${BUILD_DIR}"
198+
199+
git config user.name "ec2-bot 🤖"
200+
git config user.email "ec2-bot@users.noreply.github.com"
201+
202+
git checkout -b "${FORK_RELEASE_BRANCH}" upstream/${DEFAULT_BRANCH}
193203
git add "bottle-configs/${BINARY_BASE}.json"
194204
git commit -m "${BINARY_BASE} update to version ${VERSION_NUM}"
195205

196-
git push -u origin "${BINARY_BASE}-${VERSION}"
206+
RELEASE_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
207+
https://api.github.com/repos/${REPO}/releases | \
208+
jq --arg VERSION "$VERSION" '.[] | select(.tag_name==$VERSION) | .id')
209+
210+
RELEASE_NOTES=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
211+
https://api.github.com/repos/${REPO}/releases/${RELEASE_ID} | \
212+
jq -r '.body')
213+
214+
PR_BODY=$(cat << EOM
215+
## ${BINARY_BASE} ${VERSION} Automated Release! 🤖🤖
216+
217+
### Release Notes 📝:
218+
219+
${RELEASE_NOTES}
220+
EOM
221+
)
222+
223+
git push -u origin "${FORK_RELEASE_BRANCH}"
197224
gh pr create --title "🥳 ${BINARY_BASE} ${VERSION} Automated Release! 🥑" \
198-
--body "## ${BINARY_BASE} ${VERSION} Automated Release! 🤖🤖"
225+
--body "${PR_BODY}"
199226
fi
200227

201228
echo "✅ Homebrew sync complete"

0 commit comments

Comments
 (0)