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

Merge update-data-schema-changelog-11582824944 into master #525

Closed
wants to merge 15 commits into from
80 changes: 80 additions & 0 deletions .github/workflows/update_dbt_marts_schema_changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Update changelog for DBT marts

on:
push:
branches:
- patch/add-data-changelog
schedule:
- cron: "0 23 * * 1-5" # This will run at 11 PM UTC, which is 5 PM CST

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}-{{ github.event_name }}
cancel-in-progress: true

env:
IS_RECENCY_AIRFLOW_TASK: "false"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Authenticate to crypto-stellar GCP
uses: "google-github-actions/auth@v2"
with:
project_id: hubble-261722
credentials_json: "${{ secrets.CREDS_PROD_HUBBLE }}"

- name: Set up Google Cloud SDK
run: |
echo "Installing Google Cloud SDK..."
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt-get update && sudo apt-get install -y google-cloud-sdk

- name: Create new branch
id: create_branch
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
BRANCH_NAME="update-data-schema-changelog-${{ github.run_id }}"
git checkout -b $BRANCH_NAME
echo "::set-output name=branch::$BRANCH_NAME"

- name: Run Bash Script
run: |
cd $GITHUB_WORKSPACE
output=$(. scripts/update_dbt_marts_schema_changelog.sh)
echo "$output" > changelog/dbt_marts.md

- name: Commit changes
id: commit_changes
run: |
git add changelog/dbt_marts.md
if git commit --no-verify -m "Update changelog for DBT marts"; then
echo "Changes committed."
echo "changes_committed=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit."
echo "changes_committed=false" >> $GITHUB_OUTPUT
fi

- name: Use that secret output (protected by a mask)
run: |
echo "the secret number is ${{ steps.commit_changes.outputs.changes_committed }}"

- name: Push branch
if: steps.commit_changes.outputs.changes_committed == 'true'
run: |
git push origin ${{ steps.create_branch.outputs.branch }}

- name: Create Pull Request
if: steps.commit_changes.outputs.changes_committed == 'true'
run: |
gh pr create -B master -H ${{ steps.create_branch.outputs.branch }} \
--title 'Merge ${{ steps.create_branch.outputs.branch }} into master' \
--body 'Created by GitHub action'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .sqlfluffignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dags/ddls/queries
changelog/dbt_marts.md
4 changes: 4 additions & 0 deletions changelog/dbt_marts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changes in DBT marts schema

| Date | Table Name | Operation | Columns |
|------------|---------------------------------|---------------|--------------------------|
24 changes: 24 additions & 0 deletions scripts/update_dbt_marts_schema_changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

result=$(bq query --format=prettyjson --nouse_legacy_sql \
'SELECT
date(detected_at) as date
, table_name
, sub_type as operation
, ARRAY_AGG(column_name) as columns
FROM
`hubble-261722`.elementary.alerts_schema_changes
GROUP BY
1, 2, 3
ORDER BY 1 DESC, 2 ASC
')

echo "# Changes in DBT marts schema"

echo ""

echo "| Date | Table Name | Operation | Columns |"
echo "|------------|---------------------------------|---------------|--------------------------|"

echo "$result" | jq -r '.[] | "| \(.date) | \(.table_name | ljust(50)) | \(.sub_type) | \(.columns | join(", ")) |"'
echo ""