Skip to content

Commit

Permalink
Merge pull request #45 from utilitywarehouse/dl/yaml-check
Browse files Browse the repository at this point in the history
Add yaml format checking with yq
  • Loading branch information
DTLP authored Oct 4, 2023
2 parents 9dcd585 + da05262 commit fe71f97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit fe71f97

Please sign in to comment.