forked from mosip/mosip-helm
-
Notifications
You must be signed in to change notification settings - Fork 2
152 lines (128 loc) · 5.29 KB
/
helm-lint-manual.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Run Lint and Test Charts manually
on:
workflow_dispatch:
inputs:
target_repo:
description: 'target repo'
required: true
default: 'https://github.com/mosip/mosip-helm'
type: string
target_branch:
description: 'target branch'
required: true
default: 'gh-pages'
type: string
ignore_charts:
description: 'Ignore linting for list of charts separated by pipe(|)'
required: true
default: 'reporting|reporting-init|activemq-artemis'
type: string
lint_all_charts:
description: 'Run chart linting for all charts (yes|no)'
required: true
default: 'no'
type: string
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.inputs.target_branch }}"
echo "TARGET_BRANCH=$(echo ${{ github.event.inputs.target_branch }} )" >> $GITHUB_ENV
echo "COMMIT_ID=${GITHUB_SHA}" >> $GITHUB_ENV
echo "TARGET_REPO=$( echo ${{ github.event.inputs.target_repo }} )" >> $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 (lint)
run: |
if [ ${{ github.event.inputs.lint_all_charts }} = "yes" ]; then
ct lint --config=.github/chart-testing-config.yaml --chart-dirs=charts --remote=target_repo --target-branch=$TARGET_BRANCH;
else
find charts -maxdepth 1 -type d |grep -Ev "^charts$|${{ github.event.inputs.ignore_charts }}" > list.txt;
while read -r chart; do
echo -e "\nCHART: $chart\n";
ct lint --config=.github/chart-testing-config.yaml --charts=$chart --remote=target_repo --target-branch=$TARGET_BRANCH;
done < ./list.txt
fi
- 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