1.2.0.1 gb3 #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |