Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yaml format checking with yq #45

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit-hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ jobs:
- name: Install packages
run: |
sudo apt-get -y install git
- name: Set up yq
uses: frenck/action-setup-yq@v1
- name: Run pre-commit checks script
run: make hooks-pre-commit-run
16 changes: 14 additions & 2 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fi

PROM_VERSION="v2.28.1"

function is_yaml() {
function is_yaml_extension() {
local file=$1
if [[ "${file}" == *yaml || "${file}" == *yml || "${file}" == *yaml.tmpl || "${file}" == *yml.tmpl ]]; then
return 0
Expand All @@ -24,12 +24,24 @@ function is_yaml() {
return 1
}

function is_valid_yaml() {
local file=$1
if is_yaml_extension "${file}"; then
if yq -v "${file}" ; then
return 0
fi
exit_code=1
fi

return 1
}

# Check alerts
function check_alerts() {
local files=$(${GIT_CMD})
for f in ${files}
do
if is_yaml "${f}"; then
if is_valid_yaml "${f}"; then
if [[ $(head -1 "${f}") =~ "PROMETHEUS RULES" ]]; then
docker run -i --entrypoint promtool -v $PWD/${f}:$PWD/${f} docker.io/prom/prometheus:${PROM_VERSION} check rules $PWD/${f} &> /dev/null
if [ $? -ne 0 ]; then
Expand Down