Skip to content

Commit

Permalink
Add version scan GitHub action
Browse files Browse the repository at this point in the history
  • Loading branch information
pvannierop committed Mar 26, 2024
1 parent e9ae623 commit 0b2a277
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/versions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Update versions.md

on:
push:
branches:
- version_scan

jobs:
update_versions:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: setup-helmfile
uses: mamezou-tech/setup-helmfile@v1.2.0
with:
install-helm-plugins: no
install-kubectl: no

- name: Update versions.md
run: bin/version_scan

- name: Commit and push if versions.md changed
run: |
git diff
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Action"
git commit -am "Update versions.md" || exit 0
git push
72 changes: 72 additions & 0 deletions bin/version_scan
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

cd "$(dirname "${BASH_SOURCE[0]}")/.."

# Initialize a RADAR-base deployment where all components are installed.
yes | ./bin/init
sed -i '/_install: /s/false/true/' etc/production.yaml

helmfile template | grep -E "helm.sh/chart:|image:|containers:|initContainers:" | uniq | sed -r "s/\s+//g" | sed "s/\"//g" | sed -r "s/^-//g" > /tmp/helmfile.txt

declare -A container
declare -A init

for line in $(cat /tmp/helmfile.txt); do
if [[ $line == *"chart:"* ]]; then
chart=$(echo $line | sed -r "s/helm.*chart://g")
elif [[ $line == *"containers:"* ]]; then
containerType=container
elif [[ $line == *"initContainers:"* ]]; then
containerType=init
elif [[ $line == *"image:"* ]]; then
image=$(echo $line | sed "s/image://g")
if [ $containerType == "container" ]; then
if [ -z "${container[$image]}" ]; then
container[$image]=$chart
else
container[$image]=${container[$image]},$chart
fi
elif [ -z "${init[$image]}" ]; then
init[$image]=$chart
else
init[$image]=${init[$image]},$chart
fi
fi
done

touch versions.md
echo "# Versions" > versions.md
echo >> versions.md
echo " This file is automatically generated (by the [version_scan](bin/version_scan) script). Do not edit manually." >> versions.md
echo >> versions.md

echo "## Helm Charts" >> versions.md
echo "| Chart | Version |" >> versions.md
echo "| :----- | :----- |" >> versions.md
charts=$(echo ${container[@]} | tr "," " " | tr " " "\n" | sort -u)
for chart in $charts; do
chartName=${chart%-*}
chartVersion=${chart##*-}
echo "| $chartName | $chartVersion |" >> versions.md
done

echo >> versions.md

echo "## Containers" >> versions.md
echo "| Image | Helm Charts |" >> versions.md
echo "| :----- | :----- |" >> versions.md
images=$(echo ${!container[@]} | tr " " "\n" | sort -u)
for key in $images; do
charts=$(echo ${container[$key]} | tr "," "\n" | sort -u | tr "\n" "," | sed "s/,/<br>/g" | sed "s/<br>$//g")
echo "| $key | $charts |" >> versions.md
done

echo >> versions.md

echo "## Init Containers" >> versions.md
echo "| Image | Helm Charts |" >> versions.md
echo "| :----- | :----- |" >> versions.md
for key in "${!init[@]}"; do
charts=$(echo ${init[$key]} | tr "," "\n" | sort -u | tr "\n" "," | sed "s/,/<br>/g" | sed "s/<br>$//g")
echo "| $key | $charts |" >> versions.md
done

0 comments on commit 0b2a277

Please sign in to comment.