-
Notifications
You must be signed in to change notification settings - Fork 9.2k
48 lines (47 loc) · 1.75 KB
/
values-ascii-check.yml
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
# 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@11bd71901bbe5b1630ceea73d27597364c9af683
- 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