From aab8d8eb88ef4b1d3f7c354ec06ff0b3990e3325 Mon Sep 17 00:00:00 2001
From: Damien Grisonnet <dgrisonn@redhat.com>
Date: Thu, 30 Sep 2021 09:45:56 +0200
Subject: [PATCH] ci: add changelogs to automated version updates

Add the links to the changelogs of the freshly updated components to the
automated PR that does the update. This allow verifying that we are not
missing any important changes before merging the update. This happened
recently with node-exporter 1.2 which changed some flag names that we
took 3 months to update.

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>
---
 .github/workflows/versions.yaml | 11 +++++-
 scripts/get-new-changelogs.sh   | 64 +++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100755 scripts/get-new-changelogs.sh

diff --git a/.github/workflows/versions.yaml b/.github/workflows/versions.yaml
index 0230d441..654ac335 100644
--- a/.github/workflows/versions.yaml
+++ b/.github/workflows/versions.yaml
@@ -23,11 +23,15 @@ jobs:
       with:
         go-version: 1.16
     - name: Upgrade versions
+      id: versions
       run: |
         export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
         # Write to temporary file to make update atomic
         scripts/generate-versions.sh > /tmp/versions.json
         mv /tmp/versions.json jsonnet/kube-prometheus/versions.json
+        # Get the links to the changelogs of the updated versions and make them
+        # available to the reviewers
+        echo ::set-output name=new_changelogs::$(scripts/get-new-changelogs.sh)
       if: matrix.branch == 'main'
     - name: Update jsonnet dependencies
       run: |
@@ -49,7 +53,12 @@ jobs:
 
           This is an automated version and jsonnet dependencies update performed from CI.
 
-          Configuration of the workflow is located in `.github/workflows/versions.yaml`
+          Please review the following changelogs to make sure that we don't miss any important
+          changes before merging this PR.
+
+          ${{ steps.versions.outputs.new_changelogs }}
+
+          Configuration of the workflow is located in `.github/workflows/versions.yaml`.
 
           ## Type of change
 
diff --git a/scripts/get-new-changelogs.sh b/scripts/get-new-changelogs.sh
new file mode 100755
index 00000000..a37adee7
--- /dev/null
+++ b/scripts/get-new-changelogs.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+set -euo pipefail
+
+# Get the freshly updated components versions.
+# Should be only used after running ./scripts/generate-versions and before
+# committing any changes.
+get_updated_versions() {
+  # Get only the newly updated versions from the versions file.
+  echo "$(git diff -U0 -- "${VERSION_FILE}" | grep '^[+]' | grep -Ev '^(--- a/|\+\+\+ b/)' | tr -d '",:+' | awk -F'"' '{print $1}')"
+}
+
+# Returns github changelog url based on a given repository url and tag.
+get_changelog_url() {
+  echo "https://github.com/${1}/releases/tag/v${2}"
+}
+
+# Gets all the new changelogs from the updated components version.
+get_changelog_urls() {
+  while IFS= read -r updated_version; do
+    read -r component version <<< "${updated_version}"
+    case "${component}" in
+      alertmanager)
+        get_changelog_url "prometheus/alertmanager" "${version}"
+        ;;
+      blackboxExporter)
+        get_changelog_url "prometheus/blackbox_exporter" "${version}"
+        ;;
+      grafana)
+        get_changelog_url "grafana/grafana" "${version}"
+        ;;
+      kubeStateMetrics)
+        get_changelog_url "kubernetes/kube-state-metrics" "${version}"
+        ;;
+      nodeExporter)
+        get_changelog_url "prometheus/node_exporter" "${version}"
+        ;;
+      prometheus)
+        get_changelog_url "prometheus/prometheus" "${version}"
+        ;;
+      prometheusAdapter)
+        get_changelog_url "kubernetes-sigs/prometheus-adapter" "${version}"
+        ;;
+      prometheusOperator)
+        get_changelog_url "prometheus-operator/prometheus-operator" "${version}"
+        ;;
+      kubeRbacProxy)
+        get_changelog_url "brancz/kube-rbac-proxy" "${version}"
+        ;;
+      configmapReload)
+        get_changelog_url "jimmidyson/configmap-reload" "${version}"
+        ;;
+      *)
+        echo "Unknown component ${component} updated"
+        exit 1
+        ;;
+    esac
+  done <<< "$(get_updated_versions)"
+}
+
+# File is used to read current versions
+VERSION_FILE="$(pwd)/jsonnet/kube-prometheus/versions.json"
+
+get_changelog_urls
-- 
GitLab