Skip to content

Commit 3fd02ed

Browse files
[ci] Add Autobump dependencies
1 parent 99227da commit 3fd02ed

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

ci/pipeline.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ groups:
77
- unit-tests-pr
88
- acceptance-tests
99
- acceptance-tests-pr
10+
- autobump-dependencies
1011

1112
jobs:
1213
- name: unit-tests
@@ -157,6 +158,41 @@ jobs:
157158
status: failure
158159
context: acceptance-tests
159160

161+
- name: autobump-dependencies
162+
public: true
163+
serial: true
164+
plan:
165+
- do:
166+
- get: daily
167+
trigger: true
168+
- get: git
169+
- task: autobump-dependencies
170+
config:
171+
image_resource:
172+
type: docker-image
173+
source:
174+
repository: bguttmannavtq/pipeline-image
175+
tag: latest
176+
inputs:
177+
- name: git
178+
platform: linux
179+
run:
180+
dir: git
181+
path: bash
182+
args: ["ci/scripts/autobump-dependencies.sh"]
183+
params:
184+
REPO_ROOT: git
185+
PR_BASE: master
186+
PR_ORG: cloudfoundry
187+
PR_LABEL: run-ci
188+
# TODO: Remove DRY_RUN
189+
DRY_RUN: true
190+
AWS_SECRET_ACCESS_KEY: ((s3.secret_access_key))
191+
AWS_ACCESS_KEY: ((s3.access_key_id))
192+
GITHUB_COM_TOKEN: ((github.token))
193+
BOT_USER_NAME: ((github.bot_user))
194+
BOT_USER_MAIL: ((github.bot_mail))
195+
160196
resource_types:
161197
- name: slack-notification
162198
type: docker-image
@@ -199,3 +235,11 @@ resources:
199235
type: bosh-io-stemcell
200236
source:
201237
name: bosh-warden-boshlite-ubuntu-noble
238+
239+
- name: daily
240+
type: time
241+
source:
242+
start: 7:00 AM
243+
stop: 8:00 AM
244+
location: Europe/Berlin
245+
interval: 24h
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)