|
1 | 1 | #!/bin/bash |
2 | 2 | set -euo pipefail |
3 | | - |
| 3 | +set -x |
4 | 4 | SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" |
5 | 5 | BUILD_DIR="${SCRIPTPATH}/../build" |
| 6 | +BUILD_ID=$(uuidgen | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]') |
6 | 7 |
|
7 | 8 | TAP_REPO="aws/homebrew-tap" |
8 | 9 | TAP_NAME=$(echo ${TAP_REPO} | cut -d'/' -f2) |
@@ -70,13 +71,17 @@ while getopts "p:b:r:v:d" opt; do |
70 | 71 | done |
71 | 72 |
|
72 | 73 | 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 |
75 | 76 | fi |
76 | 77 |
|
77 | 78 | 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" |
80 | 85 | fi |
81 | 86 |
|
82 | 87 | if [[ -z $(command -v gh) ]] || [[ ! $(gh --version) =~ $GH_CLI_VERSION ]]; then |
@@ -182,20 +187,42 @@ if [[ "${DRY_RUN}" -eq 0 ]]; then |
182 | 187 | exit 4 |
183 | 188 | fi |
184 | 189 | cd "${SYNC_DIR}" |
185 | | - gh repo fork $TAP_REPO --clone --remote |
| 190 | + gh repo fork $TAP_REPO --clone=false --remote=false |
186 | 191 | cd "${FORK_DIR}" |
187 | 192 | git remote set-url origin https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/${GITHUB_USERNAME}/${TAP_NAME}.git |
188 | 193 | DEFAULT_BRANCH=$(git rev-parse --abbrev-ref HEAD | tr -d '\n') |
189 | 194 |
|
190 | 195 | cp "${BREW_CONFIG_DIR}/${BINARY_BASE}.json" "${FORK_DIR}/bottle-configs/${BINARY_BASE}.json" |
191 | 196 |
|
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} |
193 | 203 | git add "bottle-configs/${BINARY_BASE}.json" |
194 | 204 | git commit -m "${BINARY_BASE} update to version ${VERSION_NUM}" |
195 | 205 |
|
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}" |
197 | 224 | gh pr create --title "🥳 ${BINARY_BASE} ${VERSION} Automated Release! 🥑" \ |
198 | | - --body "## ${BINARY_BASE} ${VERSION} Automated Release! 🤖🤖" |
| 225 | + --body "${PR_BODY}" |
199 | 226 | fi |
200 | 227 |
|
201 | 228 | echo "✅ Homebrew sync complete" |
0 commit comments