Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#142): adds reusable github action that creates backup of superset dashboard export #154

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/actions/superset-backup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# superset-backup Shared GitHub action


The `superset-backup` is a parameterised reusable GitHub action that exports dashboard config from a Superset instance and saves it as a zip file in the repository that uses the action.

This action uses the Superset API to authenticate and export dashboard config.
Backups are saved in `/superset/backups` folder, as zip files named based on the date and time when the backups ware generated. eg. `/superset/backups/20240918082215.zip`.
The format of the export is controlled by Superset and no additional transformation is done within this action.

Requires the following variables:
- `gh_token`: GitHub token that has access to push to the main branch of the repository.
- `superset_link`: Http link to the superset instance. Eg: https://superset.app.com
- `superset_user`: Superset username that has access to the superset API
- `superset_password`: Password of the Superset user

## Example GitHub Step

```
name: Example GitHub Workflow yml

on: ['push']

jobs:
deployment:
runs-on: ubuntu-latest
steps:
- name: Make backup
uses: 'medic/cht-sync/.github/actions/superset-backup@main'
with:
gh_token: ${{ secrets.GH_TOKEN }}
superset_link: ${{ secrets.SUPERSET_LINK }}
superset_user: ${{ secrets.SUPERSET_USER }}
superset_password: ${{ secrets.SUPERSET_PASSWORD }}
```
36 changes: 36 additions & 0 deletions .github/actions/superset-backup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'superset-backup'
description: 'Download and save Superset dashboard export in a GH repository'
inputs:
gh_token:
description: 'The token to use to access the GitHub API'
required: true
superset_link:
description: 'The link to the superset server'
required: true
superset_user:
description: 'The user to use to access the Superset API'
required: true
superset_password:
description: 'The password to use to access the Superset API'
required: true

runs:
using: 'composite'
steps:
- uses: actions/checkout@master
- name: Download superset export
shell: bash
run: |
NOW=$(date +%Y%m%d%H%M%S)
mkdir -p ./superset/backups
LOGIN=$(curl -X POST -d '{"username":"${{ inputs.superset_user }}","password":"${{ inputs.superset_password }}","provider":"db"}' -H "Content-Type: application/json" ${{ inputs.superset_link }}/api/v1/security/login)
ACCESS_TOKEN=$(echo $LOGIN | sed "s/{.*\"access_token\":\"\([^\"]*\).*}/\1/g")
CSRF=$(curl "${{ inputs.superset_link }}/api/v1/security/csrf_token/" -H "Authorization: Bearer $ACCESS_TOKEN")
CSRF_TOKEN=$(echo $CSRF | sed "s/{.*\"result\":\"\([^\"]*\).*}/\1/g")
curl -X GET -0 ${{ inputs.superset_link }}/api/v1/assets/export/ -H "Authorization: Bearer $ACCESS_TOKEN" -H "X-CSRFToken: $CSRF_TOKEN" -o ./superset/backups/$NOW.zip
- name: Upload superset export
uses: actions-js/push@master
with:
github_token: ${{ inputs.gh_token }}
message: 'chore: Superset autobackup'

Loading