forked from mosip/mosip-helm
-
Notifications
You must be signed in to change notification settings - Fork 2
135 lines (110 loc) · 4.63 KB
/
helm-lint.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Lint and Test Charts
on:
pull_request:
paths:
- 'charts/**'
jobs:
lint-chart:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
# ct needs history to compare
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.10.0
- name: Install python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
check-latest: true
- name: Install yamllint via pip3
run: |
pip3 install yamllint
- name: Set environment variables
run: |
# echo "TARGET BRANCH : ${{ github.event.pull_request.base.ref }}"
echo "TARGET_BRANCH=$(echo ${{ github.base_ref }})" >> $GITHUB_ENV
echo "COMMIT_ID=${GITHUB_SHA}" >> $GITHUB_ENV
echo "TARGET_REPO=$( echo ${{ github.event.pull_request.base.repo.html_url }} )" >> $GITHUB_ENV
- name: Add Target repo to git remotes
run: |
git remote add target_repo $TARGET_REPO
git fetch target_repo
- name: Set up chart-testing
uses: helm/[email protected]
- name: Run chart-testing (list-changed)
id: list-changed
run: |
ignore_charts="charts/reporting|charts/reporting-init|charts/activemq-artemis"
echo "Ignore charts: $ignore_charts"
ct list-changed --remote=target_repo --since=HEAD --target-branch=$TARGET_BRANCH --chart-dirs=charts |grep -Ev "$ignore_charts" |tee -a list.txt
- name: Run chart-testing (lint)
run: |
while read -r chart; do
echo "CHART: $chart";
ct lint --config=.github/chart-testing-config.yaml --charts=$chart/ --remote=target_repo;
done < ./list.txt
- name: Create yaml files for helm charts
run: |
while read -r chart; do
echo -e "\nCHART: $chart\n";
yaml_file='./chart-template.yaml'
chart_name=$( echo $chart | awk -F / '{print $2}' );
mkdir "$chart_name-yaml";
helm template $chart > $yaml_file
last_line=$( cat -n $yaml_file| tail -n 1 | awk '{print $1}' )
line_nos="$( awk '/^---/{print NR}' $yaml_file ) $last_line"
start_of_file=0
for line in $line_nos; do
if [[ $line -eq 1 ]]; then
start_of_file=$line;
continue;
fi
head_line=$(( line-1 ));
tail_line=$(( line-start_of_file ));
if [[ $line -eq $last_line ]]; then
head_line=$line;
tail_line=$(( line-start_of_file+1 ));
fi
start_of_file=$line;
# echo "HEAD LINE: $head_line, TAIL LINE: $tail_line";
yaml_type=$( head -n +$head_line $yaml_file | tail -n $tail_line | grep -c -E "kind\:\ Deployment|kind\:\ StatefulSet" || true ); # used "true" to return exit code as 0
# echo "YAML TYPE: $yaml_type";
if [[ "$yaml_type" -eq 0 ]]; then
# echo "if YAML TYPE: $yaml_type";
continue;
fi
filename=$( head -n +$head_line $yaml_file | tail -n $tail_line | awk -F '/' '/# Source/{print $3}' );
echo "$filename";
head -n +$head_line $yaml_file | tail -n $tail_line > "$chart_name-yaml/$filename";
done
done < ./list.txt
- name: Run Health Check Test
run: |
while read -r chart; do
echo -e "\n\nCHART: $chart\n";
chart_name=$( echo $chart | awk -F / '{print $2}' );
list=$( ls $chart_name-yaml || true );
echo -e "YAML LIST :";
echo -e "$list\n"
for yaml in $list; do
echo -e "YAML : $yaml";
yamale -s .github/health-check-schema.yaml "$chart_name-yaml/$yaml" --no-strict
done
done < ./list.txt
# Commented below tasks as it cannot test MOSIP helm/charts deployment due to dependencies issues
#- name: Create kind v1.21.1 cluster
# uses: helm/[email protected]
# with:
# node_image: kindest/node:v1.21.1
#
#- name: Run chart-testing (install)
# run: |
# while read -r chart; do
# echo -e "\nCHART: $chart\n";
# ct install --config=.github/chart-testing-config.yaml --charts=$chart --remote=target_repo --target-branch=$TARGET_BRANCH;
# done < ./list.txt