|
| 1 | +# /bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +sudo mkdir -p -m 755 /etc/apt/keyrings \ |
| 5 | +&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \ |
| 6 | +&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ |
| 7 | +&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ |
| 8 | +&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ |
| 9 | + |
| 10 | +sudo apt update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC sudo apt install git sed gh -y |
| 11 | +mkdir /tmp/cache /tmp/prometheus-blobs |
| 12 | + |
| 13 | +export LATEST_NODE_EXPORTER_VERSION=$(cat ../node_exporter_release/tag | tr -d 'v') |
| 14 | + |
| 15 | +export BOSH_VERSION=7.6.1 |
| 16 | + |
| 17 | +pushd /tmp/cache && curl -sL https://github.com/cloudfoundry/bosh-cli/releases/download/v${BOSH_VERSION}/bosh-cli-${BOSH_VERSION}-linux-amd64 > bosh && chmod 777 bosh |
| 18 | + |
| 19 | +popd |
| 20 | + |
| 21 | +export USED_NODE_EXPORTER_VERSION=$(cat config/blobs.yml | egrep -o "node_exporter-[[:digit:]]+.[[:digit:]]+.[[:digit:]]+" | cut -d "-" -f 2) |
| 22 | + |
| 23 | +if [[ $LATEST_NODE_EXPORTER_VERSION != $USED_NODE_EXPORTER_VERSION ]]; then |
| 24 | + /tmp/cache/bosh add-blob ../node_exporter_release/node_exporter-$LATEST_NODE_EXPORTER_VERSION.linux-amd64.tar.gz node_exporter/node_exporter-$LATEST_NODE_EXPORTER_VERSION.linux-amd64.tar.gz |
| 25 | + /tmp/cache/bosh remove-blob node_exporter/node_exporter-$USED_NODE_EXPORTER_VERSION.linux-amd64.tar.gz |
| 26 | +fi |
| 27 | + |
| 28 | +/tmp/cache/bosh blobs |
| 29 | + |
| 30 | +sed -i -e "s/node_exporter-$USED_NODE_EXPORTER_VERSION\.linux-amd64/node_exporter-$LATEST_NODE_EXPORTER_VERSION\.linux-amd64/g" packages/node_exporter/* |
| 31 | + |
| 32 | +echo $DRY_RUN |
| 33 | +echo -e "---\nblobstore:\n options:\n access_key_id: ${AWS_ACCESS_KEY}\n secret_access_key: ${AWS_SECRET_ACCESS_KEY}" > config/private.yml |
| 34 | + |
| 35 | +branch_name="node_exporter-auto-bump-master" |
| 36 | +if [ -z "$DRY_RUN" ]; then |
| 37 | + export GH_TOKEN=${GITHUB_COM_TOKEN} |
| 38 | + cd git |
| 39 | + existing_prs="$(gh pr list --head $branch_name --json)" |
| 40 | + if [ ${#key[@]} == 0 ]; then |
| 41 | + git checkout -b $branch_name |
| 42 | + git config user.name "$BOT_USER_NAME" |
| 43 | + git config user.email "$BOT_USER_MAIL" |
| 44 | + bosh upload-blobs --sha2 |
| 45 | + git add config/blobs.yml |
| 46 | + git commit --author="${BOT_USER_NAME} <${BOT_USER_MAIL}>" -m "Bump node_exporter version to ${LATEST_NODE_EXPORTER_VERSION}" |
| 47 | + git add packages/node_exporter |
| 48 | + git commit --author="${BOT_USER_NAME} <${BOT_USER_MAIL}>" -m "Update blob reference for node_exporter to version ${LATEST_NODE_EXPORTER_VERSION}" |
| 49 | + git push origin -u $branch_name |
| 50 | + gh pr create --base $PR_BASE --head $branch_name --title "Bump node_exporter version to ${LATEST_NODE_EXPORTER_VERSION}" --body "Automatic bump from version ${USED_NODE_EXPORTER_VERSION} to version ${LATEST_NODE_EXPORTER_VERSION}, downloaded from ${LATEST_NODE_EXPORTER_DOWNLOAD_URL}.\nAfter merge, consider releasing a new version of node-exporter-boshrelease." --label $PR_LABEL |
| 51 | + else |
| 52 | + echo "A PR already exists" |
| 53 | + fi |
| 54 | +else |
| 55 | + git checkout -b $branch_name |
| 56 | + git config user.name "$BOT_USER_NAME" |
| 57 | + git config user.email "$BOT_USER_MAIL" |
| 58 | + echo "DRY_RUN: bosh upload-blobs --sha2" |
| 59 | + git add config/blobs.yml |
| 60 | + git commit --author="${BOT_USER_NAME} <${BOT_USER_MAIL}>" -m "Bump node_exporter version to ${LATEST_NODE_EXPORTER_VERSION}" |
| 61 | + git add packages/node_exporter |
| 62 | + git commit --author="${BOT_USER_NAME} <${BOT_USER_MAIL}>" -m "Update blob reference for node_exporter to version ${LATEST_NODE_EXPORTER_VERSION}" |
| 63 | + echo "branch not pushed, no PR created" |
| 64 | +fi |
| 65 | + |
| 66 | +rm -rf /tmp/cache/ /tmp/prometheus-blobs/ |
0 commit comments