From 629da67d75ddb59be6eee8913faaf85a56efc903 Mon Sep 17 00:00:00 2001 From: Fran Mulero Date: Tue, 4 Jun 2024 12:32:49 +0200 Subject: [PATCH] [bitnami/*] Add ASCII validator (#26676) * [bitnami/*] Add ASCII validator Signed-off-by: Fran Mulero * Remove preivous validation Signed-off-by: Fran Mulero * Fix grep expression Signed-off-by: Fran Mulero --------- Signed-off-by: Fran Mulero --- .github/workflows/ci-pipeline.yml | 6 --- .github/workflows/values-ascii-check.yml | 48 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/values-ascii-check.yml diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml index 512ef4b014..8606eb30db 100644 --- a/.github/workflows/ci-pipeline.yml +++ b/.github/workflows/ci-pipeline.yml @@ -195,12 +195,6 @@ jobs: echo "error=Please ensure all *.tag params are skipped (@skip) in the bitnami/${CHART}/values.yaml file" exit "$exit_code" fi - # Ensuring no unprintable characters are present in values.yaml - ! grep --quiet "[^[:print:]]" "bitnami/${CHART}/values.yaml" || exit_code=$? - if [[ $exit_code -ne 0 ]]; then - echo "error=Please ensure there are no unprintable characters in the bitnami/${CHART}/values.yaml file" - exit "$exit_code" - fi echo "Updating README.md for bitnami/${CHART}" readme-generator --values "bitnami/${CHART}/values.yaml" --readme "bitnami/${CHART}/README.md" --schema "/tmp/schema.json" # Commit all changes, if any diff --git a/.github/workflows/values-ascii-check.yml b/.github/workflows/values-ascii-check.yml new file mode 100644 index 0000000000..4184c9dd66 --- /dev/null +++ b/.github/workflows/values-ascii-check.yml @@ -0,0 +1,48 @@ +# Copyright Broadcom, Inc. All Rights Reserved. +# SPDX-License-Identifier: APACHE-2.0 + +name: '[CI/CD] Values ASCII validator' +on: + pull_request: + branches: + - main + paths: + - '**/values.yaml' +# Remove all permissions by default +permissions: {} +jobs: + values-ascii: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout project + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 + - name: Values ASCII validator + env: + DIFF_URL: "${{github.event.pull_request.diff_url}}" + TEMP_FILE: "${{runner.temp}}/pr-${{github.event.number}}.diff" + TEMP_OUTPUT: "${{runner.temp}}/output" + run: | + # This request doesn't consume API calls. + curl -Lkso $TEMP_FILE $DIFF_URL + files_changed="$(sed -nr 's/[\-\+]{3} [ab]\/(.*)/\1/p' $TEMP_FILE | sort | uniq)" + values_files="$(echo "$files_changed" | grep -o ".*values\.yaml$" | sort | uniq || true)" + # Create an empty file, useful when the PR changes ignored files + touch "${TEMP_OUTPUT}" + grep -nHP "[\x80-\xFF]" "${values_files[@]}" | sort -u > ${TEMP_OUTPUT} || true + while read -r line; do + # line format: + # file:row:message + # Split by ':' + readarray -d : -t strarr < <(printf '%s' "$line") + if [[ "${#strarr[@]}" -ge 3 ]]; then + echo "::warning file=${strarr[0]},line=${strarr[1]}:: Non ASCII character in '${strarr[@]:2}'" + else + echo "::warning:: Error processing: ${line}" + fi + done < "${TEMP_OUTPUT}" + if [[ -s ${TEMP_OUTPUT} ]]; then + echo "::error:: Please review warning messages" + exit 1 + fi