Created
May 27, 2022 09:02
-
-
Save DylanBaker/b4c499afa936fc6d44feffaa048e4728 to your computer and use it in GitHub Desktop.
GitHub Actions script for Spectacles dbt integration
This file contains 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
import time | |
import requests | |
import os | |
import sys | |
# Define API key and IDs | |
api_key = os.getenv("SPECTACLES_API_KEY") # <- Set this as a GitHub Actions environment variable | |
schema_name = f"dbt_ci_{os.getenv('GITHUB_SHA')[:6]}" # <- This is the name of the schema your CI jobs gets built in. | |
org_id = "" # <- Get this from the URL of the suite | |
project_id = "" # <- Get this from the URL of the suite | |
suite_id = "" # <- Get this from the URL of the suite | |
user_attribute_name = "" # <- This is the user attribute that controls schema in Looker | |
# Set the API key in header | |
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} | |
# Create a run | |
create_run_url = "https://app.spectacles.dev/api/v1/runs" | |
payload = { | |
"org_id": org_id, | |
"suite_id": suite_id, | |
"project_id": project_id, | |
"user_attributes": {user_attribute_name: schema_name}, | |
"webhooks": { | |
"type": "github", | |
"commit": os.getenv("GITHUB_SHA"), | |
"repo": os.getenv("GITHUB_REPOSITORY"), | |
}, | |
} | |
create_run_response = requests.post(url=create_run_url, headers=headers, json=payload) | |
create_run_response.raise_for_status() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment