Skip to content

Add test to render and lint dashboards #133

Add test to render and lint dashboards

Add test to render and lint dashboards #133

Workflow file for this run

# This is a GitHub workflow defining a set of jobs with a set of steps.
# ref: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
#
name: Tests
on:
pull_request:
paths-ignore:
- "docs/**"
- ".github/workflows/*.yaml"
- "!.github/workflows/test.yaml"
push:
paths-ignore:
- "docs/**"
- ".github/workflows/*.yaml"
- "!.github/workflows/test.yaml"
branches-ignore:
- "dependabot/**"
- "pre-commit-ci-update-config"
tags: ["**"]
workflow_dispatch:
jobs:
render-lint-dashboards:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
jsonnet-version: ["0.20.0"]
steps:
- uses: actions/checkout@v4
- name: Add ~/.local/bin to PATH
run: |
mkdir -p "$HOME/.local/bin"
echo "$HOME/.local/bin" >> $GITHUB_PATH
# Based on https://github.com/grafana/grafonnet/blob/6ac1593ca787638da223380ff4a3fd0f96e953e1/.github/workflows/ci.yaml#L22-L28
- name: Download jsonnet (go-jsonnet)
run: |
JSONNET_VERSION=${{ matrix.jsonnet-version }}
wget -qO- https://github.com/google/go-jsonnet/releases/download/v${JSONNET_VERSION}/go-jsonnet_${JSONNET_VERSION}_Linux_x86_64.tar.gz \
| tar -xvz -C $HOME/.local/bin
echo $PATH
- run: jsonnet --version
- name: Render dashboards
run: |
mkdir rendered-dashboards
dashboard_folders="dashboards global-dashboards"
for file in `find $dashboard_folders -name '*.jsonnet'`
do
jsonnet -J vendor --tla-code 'datasources=["prometheus-test"]' --output-file rendered-dashboards/`basename $file` $file
done
- name: Upload rendered dashboards
uses: actions/upload-artifact@v4
with:
name: rendered-dashboards-${{ github.run_attempt }}
path: ./rendered-dashboards
lint-dashboards:
runs-on: ubuntu-22.04
needs: [render-dashboards]

Check failure on line 69 in .github/workflows/test.yaml

View workflow run for this annotation

GitHub Actions / Tests

Invalid workflow file

The workflow is not valid. .github/workflows/test.yaml (Line: 69, Col: 13): Job 'lint-dashboards' depends on unknown job 'render-dashboards'.
steps:
- name: Download rendered dashboards
uses: actions/download-artifact@v4
with:
name: rendered-dashboards-${{ github.run_attempt }}
path: ./rendered-dashboards
- name: Install dashboard-linter
run: |
go install github.com/grafana/dashboard-linter@latest
echo "$HOME/go/bin" >> "$GITHUB_PATH"
- name: dashboard-linter rules
run: |
echo "Available rules are documented in https://github.com/grafana/dashboard-linter/blob/main/docs/index.md#rules"
echo ""
dashboard-linter rules
- name: dashboard-linter lint
run: |
lint_failures=""
dashboard_folders=rendered-dashboards
for file in `find $dashboard_folders -name '*.jsonnet'`
do
lint_fail=""
echo "::group::$file"
dashboard-linter lint --strict $file || lint_fail=1
echo "::endgroup::"
if [ -n "$lint_fail" ]; then
lint_failures="$lint_failures $file";
fi
done
if [ -n "$lint_failures" ]; then
echo "dashboard-linter errored for the following rendered dashboards:"
for file in $lint_failures
do
echo basename $file
done
exit 1
fi