Skip to content

Commit d9529c4

Browse files
amelhusicaiharos
authored andcommitted
MINOR: CI: added func to check if name is Pascal case
1 parent c826ec9 commit d9529c4

File tree

4 files changed

+71
-40
lines changed

4 files changed

+71
-40
lines changed

.github/workflows/compare_build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
cd build
1313
./build -file ../haproxy-spec.yaml > haproxy_spec_to_compare.yaml
1414
diff -u haproxy_spec.yaml haproxy_spec_to_compare.yaml
15-
- name: Ensure single tags
15+
- name: YAML script validation
1616
run: |
17-
chmod +x ./scripts/single-tag.sh
18-
./scripts/single-tag.sh
17+
chmod +x ./scripts/lint-yaml.sh
18+
./scripts/lint-yaml.sh

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ yamllint:
2424
script:
2525
# to test locally, run: docker run --rm -v $(pwd):/data cytopia/yamllint .
2626
- /bin/sh -c "yamllint -f colored ."
27-
- chmod +x ./scripts/single-tag.sh
28-
- /bin/sh -c ./scripts/single-tag.sh
27+
- chmod +x ./scripts/lint-yaml.sh
28+
- /bin/sh -c ./scripts/lint-yaml.sh
2929
lint-commit-msg:
3030
stage: lint
3131
image:

scripts/lint-yaml.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
3+
# - Ensure single `tags` are used(openapi-generator doesn't work well with multiple tags)
4+
# - Ensure Pascal case is used for `name` field
5+
6+
set -e pipefail
7+
8+
haproxy_spec="./build/haproxy_spec.yaml"
9+
found="false"
10+
countTags=0
11+
lineNo=0
12+
13+
# checkCamelCaseInNameField checks if usage of camel case name is supported
14+
# and if not, it exit with error code 1
15+
checkCamelCaseInNameField()
16+
{
17+
local name="$(echo $@ | grep '^name: ')"
18+
if [ -n "$name" ]; then
19+
local upperCased="$(echo "$name" | cut -d ":" -f 2 | grep -e '[[:upper:]]')"
20+
21+
if [ -n "$upperCased" ]; then
22+
# Add camel case names we want to support
23+
local allowedCamelCaseNameFields=" HAProxy Support X-Runtime-Actions forceDelete forceSync"
24+
25+
local allowed="$(echo "$allowedCamelCaseNameFields" | grep "$upperCased")"
26+
if [ -z "$allowed" ] ; then
27+
echo "Camel case \"$trimLine\" used at line no: $lineNo. Use Pascal case instead."
28+
exit 1
29+
fi
30+
fi
31+
fi
32+
}
33+
34+
while IFS= read -r line
35+
do
36+
lineNo=$((lineNo+1))
37+
# skip root tags
38+
if [ "$line" = "tags:" ]; then
39+
continue
40+
fi
41+
42+
trimLine="${line#"${line%%[![:space:]]*}"}"
43+
44+
# ensure camel case is not used in name fields
45+
checkCamelCaseInNameField $trimLine
46+
47+
if [ "$found" = "true" ] && [ -n "$trimLine" ] && [ -z "$(echo "$trimLine" | cut -d "-" -f 1)" ]; then
48+
countTags=$((countTags+1))
49+
else
50+
found="false"
51+
countTags=0
52+
fi
53+
54+
if [ "$countTags" -gt 1 ]; then
55+
echo "Multiple tags are not supported. Additional tag: $line at line no: $lineNo"
56+
exit 1
57+
fi
58+
59+
# handle only tags from path
60+
if [ "$trimLine" = "tags:" ]; then
61+
found="true"
62+
fi
63+
done < "$haproxy_spec"
64+
65+
echo "Linting YAML PASSED"
66+
exit 0

scripts/single-tag.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)