mirror of
https://github.com/prometheus-community/ansible
synced 2024-11-22 03:43:09 +00:00
skip-release: Add workflow to auto-update versions (#48)
Add a script and workflow to automatically check for upstream releases and create PRs to update the associated role. Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
parent
9419091dcc
commit
a09941b753
8 changed files with 170 additions and 11 deletions
46
.github/workflows/version_bumper.yml
vendored
Normal file
46
.github/workflows/version_bumper.yml
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
---
|
||||||
|
name: Sync repo files
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '21 14 * * *'
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
role-repos:
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
jobs:
|
||||||
|
discover-role-repos:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
role-repos: ${{ steps.discovered-role-repos.outputs.result }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Get repos for each role
|
||||||
|
id: discovered-role-repos
|
||||||
|
uses: mikefarah/yq@master
|
||||||
|
with:
|
||||||
|
cmd: |
|
||||||
|
for defaults_file in roles/*/defaults/main.yml ; do
|
||||||
|
role="$(echo "${defaults_file}" | cut -f2 -d'/')"
|
||||||
|
yq eval "[{\"repo\": .${role}_repo, \"role\": \"${role}\"}]" "${defaults_file}"
|
||||||
|
done | yq -o json -I=0
|
||||||
|
|
||||||
|
repo_sync:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: discover-role-repos
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
container:
|
||||||
|
image: quay.io/prometheus/golang-builder:base
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include: ${{ fromJson(needs.discover-role-repos.outputs.role-repos) }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- run: ./version_bumper.sh ${{ matrix.repo }} ${{ matrix.role }}
|
|
@ -1,9 +1,10 @@
|
||||||
---
|
---
|
||||||
alertmanager_version: 0.21.0
|
alertmanager_version: 0.21.0
|
||||||
alertmanager_binary_local_dir: ''
|
alertmanager_binary_local_dir: ''
|
||||||
alertmanager_binary_url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/\
|
alertmanager_repo: "prometheus/alertmanager"
|
||||||
|
alertmanager_binary_url: "https://github.com/{{ alertmanager_repo }}/releases/download/v{{ alertmanager_version }}/\
|
||||||
alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
|
alertmanager-{{ alertmanager_version }}.linux-{{ go_arch }}.tar.gz"
|
||||||
alertmanager_checksums_url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version }}/sha256sums.txt"
|
alertmanager_checksums_url: "https://github.com/{{ alertmanager_repo }}/releases/download/v{{ alertmanager_version }}/sha256sums.txt"
|
||||||
|
|
||||||
alertmanager_config_dir: /etc/alertmanager
|
alertmanager_config_dir: /etc/alertmanager
|
||||||
alertmanager_db_dir: /var/lib/alertmanager
|
alertmanager_db_dir: /var/lib/alertmanager
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
---
|
---
|
||||||
blackbox_exporter_version: 0.18.0
|
blackbox_exporter_version: 0.18.0
|
||||||
blackbox_exporter_binary_url: "https://github.com/prometheus/blackbox_exporter/releases/download/v{{ blackbox_exporter_version }}/\
|
blackbox_exporter_repo: "prometheus/blackbox_exporter"
|
||||||
|
blackbox_exporter_binary_url: "https://github.com/{{ blackbox_exporter_repo }}/releases/download/v{{ blackbox_exporter_version }}/\
|
||||||
blackbox_exporter-{{ blackbox_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] |
|
blackbox_exporter-{{ blackbox_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] |
|
||||||
default(ansible_architecture) }}.tar.gz"
|
default(ansible_architecture) }}.tar.gz"
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
---
|
---
|
||||||
node_exporter_version: 1.1.2
|
node_exporter_version: 1.1.2
|
||||||
node_exporter_binary_local_dir: ""
|
node_exporter_binary_local_dir: ""
|
||||||
node_exporter_binary_url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/\
|
node_exporter_repo: "prometheus/node_exporter"
|
||||||
|
node_exporter_binary_url: "https://github.com/{{ node_exporter_repo }}/releases/download/v{{ node_exporter_version }}/\
|
||||||
node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
|
node_exporter-{{ node_exporter_version }}.linux-{{ go_arch }}.tar.gz"
|
||||||
node_exporter_checksums_url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/sha256sums.txt"
|
node_exporter_checksums_url: "https://github.com/{{ node_exporter_repo }}/releases/download/v{{ node_exporter_version }}/sha256sums.txt"
|
||||||
|
|
||||||
node_exporter_web_listen_address: "0.0.0.0:9100"
|
node_exporter_web_listen_address: "0.0.0.0:9100"
|
||||||
node_exporter_web_telemetry_path: "/metrics"
|
node_exporter_web_telemetry_path: "/metrics"
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
---
|
---
|
||||||
prometheus_version: 2.27.0
|
prometheus_version: 2.27.0
|
||||||
prometheus_binary_local_dir: ''
|
prometheus_binary_local_dir: ''
|
||||||
prometheus_binary_url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/\
|
prometheus_repo: "prometheus/prometheus"
|
||||||
|
prometheus_binary_url: "https://github.com/{{ prometheus_repo }}/releases/download/v{{ prometheus_version }}/\
|
||||||
prometheus-{{ prometheus_version }}.linux-{{ go_arch }}.tar.gz"
|
prometheus-{{ prometheus_version }}.linux-{{ go_arch }}.tar.gz"
|
||||||
prometheus_checksums_url: "https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/sha256sums.txt"
|
prometheus_checksums_url: "https://github.com/{{ prometheus_repo }}/releases/download/v{{ prometheus_version }}/sha256sums.txt"
|
||||||
prometheus_skip_install: false
|
prometheus_skip_install: false
|
||||||
|
|
||||||
prometheus_config_dir: /etc/prometheus
|
prometheus_config_dir: /etc/prometheus
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
---
|
---
|
||||||
snmp_exporter_version: 0.19.0
|
snmp_exporter_version: 0.19.0
|
||||||
snmp_exporter_binary_url: "https://github.com/prometheus/snmp_exporter/releases/download/v{{ snmp_exporter_version }}/\
|
snmp_exporter_repo: "prometheus/snmp_exporter"
|
||||||
|
snmp_exporter_binary_url: "https://github.com/{{ snmp_exporter_repo }}/releases/download/v{{ snmp_exporter_version }}/\
|
||||||
snmp_exporter-{{ snmp_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz"
|
snmp_exporter-{{ snmp_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz"
|
||||||
snmp_exporter_checksums_url: "https://github.com/prometheus/snmp_exporter/releases/download/v{{ snmp_exporter_version }}/sha256sums.txt"
|
snmp_exporter_checksums_url: "https://github.com/{{ snmp_exporter_repo }}/releases/download/v{{ snmp_exporter_version }}/sha256sums.txt"
|
||||||
snmp_exporter_web_listen_address: "0.0.0.0:9116"
|
snmp_exporter_web_listen_address: "0.0.0.0:9116"
|
||||||
snmp_exporter_log_level: info
|
snmp_exporter_log_level: info
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
---
|
---
|
||||||
systemd_exporter_version: 0.4.0
|
systemd_exporter_version: 0.4.0
|
||||||
systemd_exporter_binary_local_dir: ""
|
systemd_exporter_binary_local_dir: ""
|
||||||
systemd_exporter_binary_url: "https://github.com/prometheus-community/systemd_exporter/releases/download/v{{ systemd_exporter_version }}/\
|
systemd_exporter_repo: "prometheus-community/systemd_exporter"
|
||||||
|
systemd_exporter_binary_url: "https://github.com/{{ systemd_exporter_repo }}/releases/download/v{{ systemd_exporter_version }}/\
|
||||||
systemd_exporter-{{ systemd_exporter_version }}.linux-{{ go_arch }}.tar.gz"
|
systemd_exporter-{{ systemd_exporter_version }}.linux-{{ go_arch }}.tar.gz"
|
||||||
systemd_exporter_checksums_url: "https://github.com/prometheus-community/systemd_exporter/releases/download/v{{ systemd_exporter_version }}/sha256sums.txt"
|
systemd_exporter_checksums_url: "https://github.com/{{ systemd_exporter_repo }}/releases/download/v{{ systemd_exporter_version }}/sha256sums.txt"
|
||||||
systemd_exporter_web_listen_address: "0.0.0.0:9558"
|
systemd_exporter_web_listen_address: "0.0.0.0:9558"
|
||||||
|
|
||||||
systemd_exporter_enable_restart_count: false
|
systemd_exporter_enable_restart_count: false
|
||||||
|
|
107
version_updater.sh
Executable file
107
version_updater.sh
Executable file
|
@ -0,0 +1,107 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -uo pipefail
|
||||||
|
|
||||||
|
GIT_MAIL="prometheus-team@googlegroups.com"
|
||||||
|
GIT_USER="prombot"
|
||||||
|
GIT_REPO="prometheus-community/ansible"
|
||||||
|
|
||||||
|
if [[ $# -ne 2 ]]; then
|
||||||
|
echo "usage: $(basename "$0") <source repo> <role>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
source_repo="$1"
|
||||||
|
role="$2"
|
||||||
|
|
||||||
|
color_red='\e[31m'
|
||||||
|
color_green='\e[32m'
|
||||||
|
color_yellow='\e[33m'
|
||||||
|
color_none='\e[0m'
|
||||||
|
|
||||||
|
echo_red() {
|
||||||
|
echo -e "${color_red}$*${color_none}" 1>&2
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_green() {
|
||||||
|
echo -e "${color_green}$*${color_none}" 1>&2
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_yellow() {
|
||||||
|
echo -e "${color_yellow}$*${color_none}" 1>&2
|
||||||
|
}
|
||||||
|
|
||||||
|
github_api() {
|
||||||
|
local url
|
||||||
|
url="https://api.github.com/${1}"
|
||||||
|
shift 1
|
||||||
|
curl --retry 5 --silent --fail -u "${GIT_USER}:${GITHUB_TOKEN}" "${url}" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
post_pull_request() {
|
||||||
|
local pr_title="$1"
|
||||||
|
local default_branch="$2"
|
||||||
|
local branch="$3"
|
||||||
|
local pr_msg="$4"
|
||||||
|
local post_json
|
||||||
|
post_json="$(printf '{"title":"%s","base":"%s","head":"%s","body":"%s"}' "${pr_title}" "${default_branch}" "${branch}" "${pr_msg}")"
|
||||||
|
echo "Posting PR to ${default_branch}"
|
||||||
|
github_api "repos/${GIT_REPO}/pulls" --data "${post_json}" --show-error |
|
||||||
|
jq -r '"PR URL " + .html_url'
|
||||||
|
}
|
||||||
|
|
||||||
|
GITHUB_TOKEN="${GITHUB_TOKEN:-}"
|
||||||
|
if [[ -z "${GITHUB_TOKEN}" ]]; then
|
||||||
|
echo_red 'GitHub token (GITHUB_TOKEN) not set. Terminating.'
|
||||||
|
exit 128
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${source_repo}" ]]; then
|
||||||
|
echo_red 'No source repository set. Terminating.'
|
||||||
|
exit 128
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${role}" ]]; then
|
||||||
|
echo_red 'No destination repository set. Terminating.'
|
||||||
|
exit 128
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get latest version.
|
||||||
|
version="$(github_api "repos/${source_repo}/releases/latest" | jq '.tag_name' | tr -d '"v')"
|
||||||
|
echo_green "New ${source_repo} version is: ${version}"
|
||||||
|
|
||||||
|
# Download destination repository
|
||||||
|
if grep "_version: ${version}" "roles/${role}/defaults/main.yml"; then
|
||||||
|
echo_green "Newest version is used."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sed -i "s/_version:.*$/_version: ${version}/" "roles/${role}/defaults/main.yml"
|
||||||
|
sed -i -r "s/_version.*[0-9]+\.[0-9]+\.[0-9]+/_version\` | ${version}/" "roles/${role}/README.md"
|
||||||
|
yq eval -i ".argument_specs.main.options.${role}_version.default = \"${version}\"" "roles/${role}/meta/argument_specs.yml"
|
||||||
|
|
||||||
|
update_branch="autoupdate/${role}/${version}"
|
||||||
|
|
||||||
|
# Push new version
|
||||||
|
git config user.email "${GIT_MAIL}"
|
||||||
|
git config user.name "${GIT_USER}"
|
||||||
|
git checkout -b "${update_branch}"
|
||||||
|
git add \
|
||||||
|
"roles/${role}/defaults/main.yml" \
|
||||||
|
"roles/${role}/meta/argument_specs.yml" \
|
||||||
|
"roles/${role}/README.md"
|
||||||
|
git commit -m 'patch: :tada: automated upstream release update'
|
||||||
|
echo_green "Pushing to ${update_branch} branch in ${role}"
|
||||||
|
if ! git push "https://${GITHUB_TOKEN}:@github.com/${GIT_REPO}" --set-upstream "${update_branch}"; then
|
||||||
|
echo_yellow "Branch is already on remote."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! post_pull_request \
|
||||||
|
"patch: New ${source_repo} upstream release!" \
|
||||||
|
"main" \
|
||||||
|
"${update_branch}" \
|
||||||
|
"The upstream [${source_repo}](https://github.com/${source_repo}/releases) released new software version - **${version}**!\n\nThis automated PR updates code to bring new version into repository." ; then
|
||||||
|
echo_red "Pull request failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo_green "Pull Request with new version is ready"
|
Loading…
Reference in a new issue