-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (88 loc) · 3.65 KB
/
helm-package.yaml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: helm lint
on:
push:
branches:
- main
paths-ignore:
- 'charts/*/Chart.yaml'
- .github
- .gitignore
- README.md
jobs:
packing:
permissions:
contents: write
runs-on: ubuntu-latest
env:
HELM_EXPERIMENTAL_OCI: 1
GCR_IMAGE: ghcr.io/${{ github.repository_owner }}/charts
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
- uses: azure/setup-helm@v3
with:
token: ${{ secrets.GITHUB_TOKEN }} # only needed if version is 'latest'
- name: check linting
run: |
helm lint charts/*
for dir in $(ls charts)
do
helm template charts/$dir
done
- name: Check Path Change
run: |
git config --global user.email "[email protected]"
git config --global user.name "Service Account"
echo "Changes in these directories trigger the build:"
changed_dirs=$(git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}" diff --name-only HEAD HEAD~1 | grep 'charts/' | awk -F/ '{print $2}' | uniq)
echo $changed_dirs > /tmp/change_dir.txt
- name: Helm repo login
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin
- name: 'Auto Increase Helm Version'
run: |
cd charts
for dir in $(cat /tmp/change_dir.txt)
do
echo "$dir"
# Extract current version
current_version=$(cat $dir/Chart.yaml | grep "version: " | cut -d " " -f 2)
# Break the version into its components
major_version=$(echo $current_version | cut -d "." -f 1)
minor_version=$(echo $current_version | cut -d "." -f 2)
patch_version=$(echo $current_version | cut -d "." -f 3)
# Increment the patch version by one
new_patch_version=$((patch_version+1))
# Construct the new version
new_version="$major_version.$minor_version.$new_patch_version"
# Replace the old version with the new version in $dir/Chart.yaml
sed -i "s/version: .*/version: $new_version/" $dir/Chart.yaml
# Print the new version
echo "Updated Helm chart version to: $new_version"
done
- name: Packing chart
run: |
cd charts
for dir in $(cat /tmp/change_dir.txt)
do
echo "$dir"
version=$(cat $dir/Chart.yaml | grep "version: " | cut -d " " -f 2)
helm chart save $dir ${{ env.GCR_IMAGE }}:$version
helm chart push ${{ env.GCR_IMAGE }}:$version
done
- name: 'Commit new version to main and create tag'
run: |
for dir in $(cat /tmp/change_dir.txt)
do
echo "$dir"
version=$(cat charts/$dir/Chart.yaml | grep "version: " | cut -d " " -f 2)
git config --global user.email "[email protected]"
git config --global user.name "Service Account"
git add charts/$dir/Chart.yaml
git commit -m "${GITHUB_REPOSITORY}: Update tag build $version"
git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin HEAD:main
git tag -a $dir-$version -m "${GITHUB_REPOSITORY}: Update tag build $version for $dir"
git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin $dir-$version
done