From dc2331134e6d09816ce9189d6c38e5d6529911eb Mon Sep 17 00:00:00 2001 From: Martin Dimitrov Date: Sat, 10 Jan 2026 09:44:37 -0800 Subject: [PATCH] add push dashboard action --- .gitea/workflows/push-grafana-dashboard.yaml | 59 ++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .gitea/workflows/push-grafana-dashboard.yaml diff --git a/.gitea/workflows/push-grafana-dashboard.yaml b/.gitea/workflows/push-grafana-dashboard.yaml new file mode 100644 index 0000000..d477f13 --- /dev/null +++ b/.gitea/workflows/push-grafana-dashboard.yaml @@ -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 .