Skip to content

feat: add a reusable workflow to sync Grafana dashboards - #94

Merged
kayibal merged 1 commit into
mainfrom
feat/sync-grafana-dashboards
Oct 13, 2026
Merged

kayibal merged 1 commit into
mainfrom
feat/sync-grafana-dashboards

Conversation

@kayibal

@kayibal kayibal commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Adds sync-grafana-dashboards.yaml, a reusable workflow that pushes Grafana dashboard JSON files from the calling repository to Grafana through the dashboards API.

  • On a push, it sends only the .json files under dashboards_path that the push added or changed. If nothing under the path changed, the push step is skipped, so the job can sit in an existing main workflow without a paths: filter.
  • On workflow_dispatch, or on a push with no previous commit, it sends every dashboard under the path.
  • Each file must have a fixed uid. A file without one fails the job, because Grafana would otherwise create a new copy on each push.
  • Deleting a file does not delete the dashboard. Edits made in the Grafana UI are overwritten the next time the file changes.
  • The job summary links to each dashboard it updated.

Usage

Call it once per dashboard directory. Each call can target its own Grafana folder.

  sync-grafana-dashboards:
    uses: propeller-heads/ci-cd-templates/.github/workflows/sync-grafana-dashboards.yaml@main
    with:
      dashboards_path: ops/grafana/dashboards
      folder_uid: <grafana-folder-uid>   # optional, empty = General
    secrets:
      grafana_token: ${{ secrets.GRAFANA_SA_TOKEN }}

The token is a Grafana service account token with dashboards:write on the target folder. grafana_url defaults to https://grafana.propellerheads.xyz.

Testing

actionlint, zizmor and shellcheck report nothing. I ran both steps locally against a scratch repository and against grafana.propellerheads.xyz, using a separate test dashboard (tycho-router-trades-ci-test in the tmp folder):

Case Result
Dashboards added, one of them in a subdirectory both selected
Push that changed only other files count=0, push step skipped
Zero before SHA, or workflow_dispatch all dashboards selected
dashboards_path does not exist fails with an error
File without uid fails and names the file
Invalid token fails and shows Grafana's 401 message
Real push test dashboard updated in place

🤖 Generated with Claude Code

WHY:
A repository can keep Grafana dashboard JSON files, but no workflow sends
them to Grafana. Each dashboard change needs a manual step in the Grafana UI
or a manual Terraform apply. If a person forgets that step, the dashboard in
Grafana and the file in git do not agree.

HOW:
- Add `sync-grafana-dashboards.yaml`. The caller gives the directory of the
  dashboard files (`dashboards_path`), the Grafana folder (`folder_uid`) and
  a service account token.
- On a push, find the JSON files under `dashboards_path` that the push added
  or changed. If there are no such files, skip the push step. Thus a caller
  can add the job to a main workflow that runs on each push.
- On a manual run, or on a push that has no previous commit, send all the
  dashboards under the path.
- Send each file to `POST /api/dashboards/db` with `overwrite: true`. Each
  dashboard must have a fixed `uid`. The workflow then updates the dashboard
  and does not make a copy. A file without a `uid` causes the job to fail.
- Check out with `fetch-depth: 0` and `filter: blob:none`. The diff against
  the previous push commit needs the history, but not the file contents.
- To sync dashboards from more than one directory, call the workflow one
  time for each directory.

ADDITIONAL NOTES:
A deleted file does not delete the dashboard in Grafana. The workflow does
not keep edits from the Grafana UI. The next push of the file replaces them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@michcio1234 michcio1234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👌🏻

@kayibal
kayibal merged commit 4ca1951 into main Oct 13, 2026
3 checks passed
@kayibal
kayibal deleted the feat/sync-grafana-dashboards branch October 13, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants