From 41ba1d6ccfe72717db5147f332660ad62b111852 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Wed, 26 Jun 2024 00:50:52 +0300 Subject: [PATCH] chore(ci): fail if a lint fail (#23798) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes # **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** **📃 Notes:** **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning - [ ] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):` or `chore(chart-name):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- .github/scripts/tc-lint.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/scripts/tc-lint.sh b/.github/scripts/tc-lint.sh index 6dfaab0f952..6fb8bfa3f5a 100755 --- a/.github/scripts/tc-lint.sh +++ b/.github/scripts/tc-lint.sh @@ -40,7 +40,7 @@ function check_version() { } export -f check_version -function check_chart_schema(){ +function check_chart_schema() { chart_path=${1:?"No chart path provided to [Chart.yaml lint]"} yamale_output=$(yamale --schema .github/chart_schema.yaml "$chart_path/Chart.yaml") @@ -49,7 +49,7 @@ function check_chart_schema(){ if [[ -n $line ]]; then echo -e "\t$line" fi - done <<< "$yamale_output" + done <<<"$yamale_output" if [ $yamale_exit_code -ne 0 ]; then echo -e "\t❌ Chart Schema: Failed" @@ -61,17 +61,21 @@ function check_chart_schema(){ } export -f check_chart_schema -function helm_lint(){ +function helm_lint() { chart_path=${1:?"No chart path provided to [Helm lint]"} # Print only errors and warnings - helm_lint_output=$(helm lint --quiet "$chart_path") + helm_lint_output=$(helm lint --strict --quiet "$chart_path" 2>&1) helm_lint_exit_code=$? while IFS= read -r line; do if [[ -n $line ]]; then echo -e "\t$line" fi - done <<< "$helm_lint_output" + done <<<"$helm_lint_output" + + if echo "$helm_lint_output" | grep -q "Fail:"; then + helm_lint_exit_code=1 + fi if [ $helm_lint_exit_code -ne 0 ]; then echo -e "\t❌ Helm Lint: Failed" @@ -83,7 +87,7 @@ function helm_lint(){ } export -f helm_lint -function helm_template(){ +function helm_template() { chart_path=${1:?"No chart path provided to [Helm template]"} values=${2:-} @@ -98,7 +102,7 @@ function helm_template(){ if [[ -n $line ]]; then echo -e "\t$line" fi - done <<< "$helm_template_output" + done <<<"$helm_template_output" if [ $helm_template_exit_code -ne 0 ]; then echo -e "\t❌ Helm template: Failed" @@ -110,7 +114,7 @@ function helm_template(){ } export -f helm_template -function yaml_lint(){ +function yaml_lint() { file_path=${1:?"No file path provided to [YAML lint]"} yaml_lint_output=$(yamllint --config-file .github/yaml-lint-conf.yaml "$file_path") @@ -119,7 +123,7 @@ function yaml_lint(){ if [[ -n $line ]]; then echo -e "\t$line" fi - done <<< "$yaml_lint_output" + done <<<"$yaml_lint_output" if [ $yaml_lint_exit_code -ne 0 ]; then echo -e "\t❌ YAML Lint: Failed [$file_path]" @@ -131,7 +135,7 @@ function yaml_lint(){ } export -f yaml_lint -function lint_chart(){ +function lint_chart() { chart_path=${1:?"No chart path provided to [Lint Chart]"} target_branch=${2:?"No target branch provided to [Lint Chart]"} status_file=${3:?"No status file provided to [Lint Chart]"} @@ -190,10 +194,10 @@ function lint_chart(){ fi echo '---------------------------------------------------------------------------------------' echo '' - } > "$curr_result_file" + } >"$curr_result_file" cat "$curr_result_file" # $curr_result starts with 0, and it gets set to 1 only when a linting step fails - echo $curr_result >> "$status_file" + echo $curr_result >>"$status_file" } export -f lint_chart