generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
77 lines (68 loc) · 3.4 KB
/
helm-chart-dependency.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Check for Helm Chart Updates
on:
schedule:
- cron: '0 0 * * *'
pull_request:
types: [opened, edited, reopened, synchronize]
workflow_dispatch:
jobs:
check-helm-chart-update:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Helm
uses: yokawasa/[email protected]
with:
setup-tools: |
helm
helm: '3.14.3'
- name: Add Prometheus Community Repo and Update
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
- name: Get Latest Helm Chart Version
id: latest_version
run: |
version=$(helm search repo prometheus-community/kube-prometheus-stack -o json | jq -r '.[0].version')
echo "LATEST_VERSION=$version" >> $GITHUB_ENV
- name: Check Current Version
id: current_version
run: |
# Extract the entire block of lines related to the helm upgrade command
block=$(awk '/helm upgrade --install kube-prometheus-stack prometheus-community\/kube-prometheus-stack/{flag=1; next} flag && /--version/{print; exit}' scripts/deploy.sh)
# Print the extracted block for debugging
echo "Extracted block: $block"
current_version=$(echo "$block" | awk '{print $2}')
echo "CURRENT_VERSION=$current_version" >> $GITHUB_ENV
- name: Compare Versions and Update
run: |
echo "LATEST_VERSION=${{ env.LATEST_VERSION }}"
echo "CURRENT_VERSION=${{ env.CURRENT_VERSION }}"
if [ "${{ env.LATEST_VERSION }}" != "${{ env.CURRENT_VERSION }}" ]; then
echo "Updating to version ${{ env.LATEST_VERSION }}"
sed -i '/helm upgrade --install kube-prometheus-stack prometheus-community\/kube-prometheus-stack/{n; s/\(--version \)[^ ]*/\1${{ env.LATEST_VERSION }}/}' scripts/deploy.sh
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git checkout -b update-helm-chart
git status
git add scripts/deploy.sh
git commit -m "Update kube-prometheus-stack to version ${{ env.LATEST_VERSION }}"
git push origin update-helm-chart --force
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
pr_url=$(gh pr list --base main --head update-helm-chart --json url -q '.[0].url')
if [ -n "$pr_url" ]; then
echo "Pull request already exists: $pr_url"
gh pr edit "$pr_url" --title "Update kube-prometheus-stack to version ${{ env.LATEST_VERSION }}" --body "This PR updates the kube-prometheus-stack Helm chart to the latest version."
else
gh pr create --title "Update kube-prometheus-stack to version ${{ env.LATEST_VERSION }}" --body "This PR updates the kube-prometheus-stack Helm chart to the latest version."
fi
else
echo "No updates available."
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
pr_url=$(gh pr list --base main --head update-helm-chart --json url -q '.[0].url')
if [ -n "$pr_url" ]; then
echo "Closing existing PR: $pr_url"
gh pr close "$pr_url" --comment "Closing PR as the current version matches the latest version."
fi
fi