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