[P1BIGROCKS-2660] Enhance renovate updates with additional MR automation
[P1BIGROCKS-2660](https://jira.il2.dso.mil/browse/P1BIGROCKS-2660)
Renovate is limited in what it can create/update. As a package maintainer, I'd like to have additional automation added to complete package maintenance chores. These are all items that renovate cannot do
- Bump the Chart.yaml chart `version`
- Regenerate the README.md using helm-docs
- Create an entry in CHANGELOG indicating the images updated
- If a chart/KptFile exists, identify the upstream chart tag that corresponds to the app version. In the open MR, add a comment that the chart is up-to-date or needs updating to version x.x.x. Renovate.json would need to update the appVersion in Chart.yaml so the value is correct when searching. See script below for a starter.
> I thought about automatically updating the chart using Kpt and alpha merge. But, I'm not confident that automation would catch everything a human would.
The acceptance criteria for this epic is that MRs created by renovate will be updated so that:
- The package pipeline passes (assuming the image upgrade is seamless)
- If there are no changes in the upstream chart, the MR could be approved/merged as-is by a package owner.
Here is the script I used in a proof-of-concept for finding the upstream chart tag. Use as a starting point (its not been thoroughly tested):
```shell
#!/bin/bash
set -e
IFS=""
# Configuration
temp=/tmp/$$ # Directory to temporarily git clone
verkey="appversion:" # Key that matches app version
# Help
help()
{
echo "Search a Git repository for the latest release tag containing a Chart.yaml with a matching appVersion."
echo
echo "Syntax: $0 -f file -r repo -v version"
echo "Options:"
echo "f Path to 'Chart.yaml' file in the repository"
echo "r Repository URL to search"
echo "v Application version to match"
echo "Returns: the Git release tag"
exit 1
}
# Get options
while getopts f:hr:v: flag
do
case "${flag}" in
f) file=${OPTARG};;
h) help;;
r) repo=${OPTARG};;
v) ver=${OPTARG};;
\?) help;;
esac
done
# Verify options exist
if [ -z "$file" ] || [ -z "$repo" ] || [ -z "$ver" ]; then
echo "ERROR: The following options are required - 'f', 'r', 'v'" >&2
help
exit 1
fi
# Cleanup temporary git repository
cleanup()
{
if [ -d $temp ]; then
rm -rf $temp
fi
}
trap cleanup EXIT
# Clone repo into temporary directory
git clone -q --bare $repo $temp
cd $temp
# Check for file and get contents
contents=`git show HEAD:$file`
if [ $? -gt 0 ]; then
echo "ERROR: $file could not be found in the repository!"
exit 1
fi
# Check if contents contain key
latestver=`echo $contents | grep -n $verkey | cut -d " " -f 2`
if [ $? -gt 0 ]; then
echo "ERROR: Could not find '$verkey' in $file."
exit 1
fi
# Use logs to get changes to version
# Logs will contain commits and when version was updated (below the commit)
logs=`git log -L1:$file | grep "$verkey $ver\|commit "`
# First commit without version (line above -version)
firstCommitWithout=`echo $logs | sed -n '/\-version/{x;p;d;}; x' | cut -d ' ' -f 2`
# First commit with version (line above +version)
firstCommitWith=`echo $logs | sed -n '/+version/{x;p;d;}; x' | cut -d ' ' -f 2`
if [ -z $firstCommitWith ]; then
echo "ERROR: Could not find commit for version '$ver'"
exit 1
fi
# Array of tags (newest to oldest) with and without version
IFS=$'\r\n'
arrWithout=(`git tag --sort=-version:refname --contains $firstCommitWithout | sed /.*-.*/d`)
arrWith=(`git tag --sort=-version:refname --contains $firstCommitWith | sed /.*-.*/d`)
# The "without" tags should be a subset of the "with" tags.
# To find the latest tag containing the version we want,
# use the length of the without array as an index into the with
if [ -z $firstCommitWithout ]; then
tag=${arrWith[0]}
else
tag=${arrWith[${#arrWithout[@]}]}
fi
# Cleanup repository
cleanup
echo $tag
```
- clone upstream repo into temporary directory using `--bare`
- Git a list of commits and changes to `appVersion` on `Chart.yaml (`git log -L1:Chart.yaml | grep "appversion: $ver\|commit "`. Result will be a list of commits and changes to appVersion in timeline order.
- Find the first commit without the new version (`echo $logs | sed -n '/\-version/{x;p;d;}; x' | cut -d ' ' -f 2`)
- Find the first commit with the new version (`echo $logs | sed -n '/+version/{x;p;d;}; x' | cut -d ' ' -f 2`)
- Create
epic