add push dashboard action
Some checks failed
Reload Act Runner Stack to clear cache for workflows / diff (push) Successful in 26s
Reload Act Runner Stack to clear cache for workflows / deploy-gitainer (push) Failing after 3s
Reload Act Runner Stack to clear cache for workflows / notify (push) Has been skipped

This commit is contained in:
Martin Dimitrov 2026-01-10 09:44:37 -08:00
parent 804d17cea5
commit dc2331134e

View File

@ -0,0 +1,59 @@
name: Push Grafana Dashboard
on:
workflow_call:
inputs:
dashboard_file:
description: 'Path to the dashboard JSON file in the repository'
required: true
type: string
folder_uid:
description: 'The UID of the folder where the dashboard should be placed'
required: false
type: string
default: ''
overwrite:
description: 'Whether to overwrite an existing dashboard'
required: false
type: boolean
default: true
secrets:
grafana_token:
description: 'Grafana API Token or Service Account token'
required: true
jobs:
push-dashboard:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate dashboard file exists
run: |
if [ ! -f "${{ inputs.dashboard_file }}" ]; then
echo "Error: Dashboard file '${{ inputs.dashboard_file }}' not found."
exit 1
fi
- name: Push dashboard to Grafana
run: |
DASHBOARD_JSON=$(cat "${{ inputs.dashboard_file }}")
# Construct the payload using jq
PAYLOAD=$(echo "$DASHBOARD_JSON" | jq -n \
--argjson dash "$DASHBOARD_JSON" \
--arg folder_uid "${{ inputs.folder_uid }}" \
--argjson overwrite "${{ inputs.overwrite }}" \
'{
dashboard: $dash,
folderUid: $folder_uid,
overwrite: $overwrite
}')
# Push to Grafana API
curl -s -X POST \
-H "Authorization: Bearer ${{ secrets.grafana_token }}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"http://grafana.local.chromart.cc/api/dashboards/db" | jq .