PMM-15308 Trim whitespace from dashboard titles #952
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Dashboards | |
| on: | |
| pull_request: | |
| paths: | |
| - "dashboards/**" | |
| # So a PR that only fixes this workflow still exercises it. | |
| - ".github/workflows/dashboards.yml" | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: Install NodeJS | |
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | |
| with: | |
| node-version: "22" | |
| cache: "yarn" | |
| cache-dependency-path: dashboards/pmm-app/yarn.lock | |
| - name: Verify plugin.json dashboard paths exist | |
| run: | | |
| missing=$(jq -r '.includes[] | select(.path) | .path' dashboards/pmm-app/src/plugin.json \ | |
| | while read -r p; do [ -f "dashboards/$p" ] || echo "$p"; done) | |
| if [ -n "$missing" ]; then | |
| echo "::error::plugin.json references dashboard files that do not exist:" | |
| echo "$missing" | sed 's/^/ - /' | |
| exit 1 | |
| fi | |
| - name: Install deps | |
| run: make -C dashboards install | |
| - name: Build Grafana Dashboards | |
| run: make -C dashboards build | |
| - name: Upload the build artefacts | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: build-dist | |
| path: dashboards/pmm-app/dist/ | |
| if-no-files-found: error | |
| tests: | |
| name: Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: Install NodeJS | |
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | |
| with: | |
| node-version: "22" | |
| cache: "yarn" | |
| cache-dependency-path: dashboards/pmm-app/yarn.lock | |
| - name: Install deps | |
| run: make -C dashboards install | |
| - name: Run lint | |
| run: cd dashboards/pmm-app && yarn lint:check | |
| - name: Run unit tests | |
| run: cd dashboards/pmm-app && yarn test:ci | |
| - name: Upload unit test coverage | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 | |
| with: | |
| fail_ci_if_error: true | |
| flags: unittests # optional | |
| name: codecov-umbrella | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| verbose: true | |
| check: | |
| name: Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get changed dashboard files | |
| id: changed | |
| run: | | |
| set -o pipefail | |
| if ! git diff --name-only ${{ github.event.pull_request.base.sha }} HEAD \ | |
| | sort -u > changed_files.txt; then | |
| echo "::error::git diff against ${{ github.event.pull_request.base.sha }} failed" | |
| exit 1 | |
| fi | |
| # A failed diff is handled above, so an empty file here means the PR | |
| # has no net changes against its base (already merged, or the head | |
| # branch was reset). Fail rather than silently skipping every check | |
| # below and reporting success on an unchecked dashboard. | |
| if [ ! -s changed_files.txt ]; then | |
| echo "::error::PR has no net changes against ${{ github.event.pull_request.base.sha }}; nothing could be checked" | |
| exit 1 | |
| fi | |
| grep -E '^dashboards/dashboards/.*\.json$' changed_files.txt \ | |
| > changed_dashboards.txt || true | |
| count=$(wc -l < changed_dashboards.txt | tr -d ' ') | |
| echo "count=$count" >> $GITHUB_OUTPUT | |
| # The cleanup script's tests include a whole-tree gate over every | |
| # dashboard, so only run them when the PR changes a dashboard, the | |
| # scripts under test, or this workflow -- whoever edits the gate needs | |
| # to see it run. Nothing else may be gated on the state of the tree. | |
| # The pattern must cover every module `discover -p 'test_*.py'` would | |
| # pick up, or a PR adding one never runs it. | |
| if [ "$count" -ne 0 ] \ | |
| || grep -qE '^(dashboards/misc/(cleanup-dash\.py|test_.*\.py)|\.github/workflows/dashboards\.yml)$' changed_files.txt; then | |
| echo "tooling=1" >> $GITHUB_OUTPUT | |
| else | |
| echo "tooling=0" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Run cleanup check per dashboard | |
| if: steps.changed.outputs.count != '0' | |
| run: | | |
| # Ensure we don't exit immediately on the python check | |
| echo "## 📊 Dashboard cleanup results" >> $GITHUB_STEP_SUMMARY | |
| echo "| Dashboard | Status | Action |" >> $GITHUB_STEP_SUMMARY | |
| echo "|-----------|--------|--------|" >> $GITHUB_STEP_SUMMARY | |
| has_failed=0 | |
| # The [ -n "$f" ] ensures the last line is read even if it lacks a newline | |
| while IFS= read -r f || [ -n "$f" ]; do | |
| [ -z "$f" ] && continue | |
| # Deleted dashboards still appear in git diff; skip missing files. | |
| [ ! -f "$f" ] && continue | |
| if python3 dashboards/misc/cleanup-dash.py --check-only "$f"; then | |
| echo "| \`$f\` | ✅ OK | - |" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "| \`$f\` | ❌ Requires cleanup | \`python3 dashboards/misc/cleanup-dash.py $f\` |" >> $GITHUB_STEP_SUMMARY | |
| echo "::error file=$f,title=Cleanup required::Dashboard needs cleanup. Run: python3 dashboards/misc/cleanup-dash.py $f" | |
| has_failed=1 | |
| fi | |
| done < changed_dashboards.txt | |
| if [ "$has_failed" -ne 0 ]; then | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "> [!CAUTION]" >> $GITHUB_STEP_SUMMARY | |
| echo "> Some dashboards require cleanup. See table above." >> $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| fi | |
| # After the per-dashboard check, so a whole-tree failure never hides the | |
| # step summary and the file annotations for the PR's own dashboards. | |
| - name: Test the cleanup script | |
| if: ${{ !cancelled() && steps.changed.outputs.tooling == '1' }} | |
| run: python3 -m unittest discover -s dashboards/misc -p 'test_*.py' -v | |
| workflow_success: | |
| needs: [tests, build] | |
| name: Slack Notification success | |
| runs-on: ubuntu-latest | |
| env: | |
| SLACK_WEBHOOK: ${{ secrets.SLACK_TOKEN }} | |
| SLACK_CHANNEL: "pmm-ci" | |
| SLACK_USERNAME: "PR bot" | |
| SLACK_ICON_EMOJI: ":octocat:" | |
| SLACK_COLOR: "#00FF00" | |
| SLACK_MESSAGE: "Workflow succeded: ${{ github.event.inputs.repo || github.repository }}:${{ github.event.inputs.branch || github.head_ref }}" | |
| SLACK_FOOTER: "Please check the Actions URL ^" | |
| steps: | |
| - name: Slack Notification | |
| uses: rtCamp/action-slack-notify@33ca3be66c6f378fe1610fd1d5258632dbed5e58 # v2.4.0 | |
| workflow_failure: | |
| if: ${{ failure() }} | |
| needs: [tests, build] | |
| name: Slack Notification failure | |
| runs-on: ubuntu-latest | |
| env: | |
| SLACK_WEBHOOK: ${{ secrets.SLACK_TOKEN }} | |
| SLACK_CHANNEL: "pmm-ci" | |
| SLACK_USERNAME: "PR bot" | |
| SLACK_ICON_EMOJI: ":octocat:" | |
| SLACK_COLOR: "#FF0000" | |
| SLACK_MESSAGE: "Workflow failed: ${{ github.event.inputs.repo || github.repository }}:${{ github.event.inputs.branch || github.head_ref }}" | |
| SLACK_FOOTER: "Please check the Actions URL ^" | |
| steps: | |
| - name: Slack Notification | |
| uses: rtCamp/action-slack-notify@33ca3be66c6f378fe1610fd1d5258632dbed5e58 # v2.4.0 |