Skip to content

Commit b655ef0

Browse files
Work on a bump blob version with concourse resource
1 parent a34ad7d commit b655ef0

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

ci/pipeline.yml

Lines changed: 41 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,40 @@ 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: node_exporter_release
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+
DRY_RUN: ((dry_run))
189+
AWS_SECRET_ACCESS_KEY: ((s3.secret_access_key))
190+
AWS_ACCESS_KEY: ((s3.access_key_id))
191+
GITHUB_COM_TOKEN: ((github.token))
192+
BOT_USER_NAME: ((github.bot_user))
193+
BOT_USER_MAIL: ((github.bot_mail))
194+
160195
resource_types:
161196
- name: slack-notification
162197
type: docker-image
@@ -199,3 +234,9 @@ resources:
199234
type: bosh-io-stemcell
200235
source:
201236
name: bosh-warden-boshlite-ubuntu-noble
237+
238+
- name: node_exporter_release
239+
type: github-release
240+
source:
241+
owner: prometheus
242+
repository: node_exporter
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)