|
| 1 | +# Extract references to models in Metabase to dbt documentation |
| 2 | +name: Metabase Exposures |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - .github/workflows/dbt-exposures.yml |
| 11 | + |
| 12 | +env: |
| 13 | + PYTHON_VERSION: '3.11' |
| 14 | + POETRY_VERSION: '2.0.1' |
| 15 | + SERVICE_ACCOUNT: ${{ github.ref == 'refs/heads/main' && 'github-actions-service-account@cal-itp-data-infra.iam.gserviceaccount.com' || 'github-actions-service-account@cal-itp-data-infra-staging.iam.gserviceaccount.com' }} |
| 16 | + WORKLOAD_IDENTITY_PROVIDER: ${{ github.ref == 'refs/heads/main' && 'projects/1005246706141/locations/global/workloadIdentityPools/github-actions/providers/data-infra' || 'projects/473674835135/locations/global/workloadIdentityPools/github-actions/providers/data-infra' }} |
| 17 | + PROJECT_ID: ${{ github.ref == 'refs/heads/main' && 'cal-itp-data-infra' || 'cal-itp-data-infra-staging' }} |
| 18 | + DBT_TARGET: ${{ github.ref == 'refs/heads/main' && 'prod' || 'staging' }} |
| 19 | + DBT_ARTIFACTS_BUCKET: ${{ github.ref == 'refs/heads/main' && 'calitp-dbt-artifacts' || 'calitp-staging-dbt-artifacts' }} |
| 20 | + |
| 21 | +jobs: |
| 22 | + extract: |
| 23 | + name: Extract Exposures |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + id-token: write |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Authenticate Google Service Account |
| 35 | + uses: google-github-actions/auth@v2 |
| 36 | + with: |
| 37 | + create_credentials_file: 'true' |
| 38 | + project_id: ${{ env.PROJECT_ID }} |
| 39 | + workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }} |
| 40 | + service_account: ${{ env.SERVICE_ACCOUNT }} |
| 41 | + |
| 42 | + - name: Setup GCloud utilities |
| 43 | + uses: google-github-actions/setup-gcloud@v2 |
| 44 | + |
| 45 | + - name: Setup Graphviz |
| 46 | + uses: ts-graphviz/setup-graphviz@v2 |
| 47 | + |
| 48 | + - name: Setup Python |
| 49 | + uses: actions/setup-python@v5 |
| 50 | + with: |
| 51 | + python-version: ${{ env.PYTHON_VERSION }} |
| 52 | + |
| 53 | + - name: Cache Poetry |
| 54 | + uses: actions/cache@v3 |
| 55 | + with: |
| 56 | + path: ~/.cache/pypoetry |
| 57 | + key: poetry-cache-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-poetry-${{ env.POETRY_VERSION }} |
| 58 | + |
| 59 | + - name: Setup Poetry |
| 60 | + uses: abatilo/actions-poetry@v3 |
| 61 | + with: |
| 62 | + poetry-version: ${{ env.POETRY_VERSION }} |
| 63 | + |
| 64 | + - name: Cache Python packages |
| 65 | + uses: actions/cache@v3 |
| 66 | + with: |
| 67 | + path: ~/.local |
| 68 | + key: python-cache-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-lock-${{ hashFiles('warehouse/poetry.lock') }}-${{ hashFiles('.github/workflows/*.yml') }} |
| 69 | + |
| 70 | + - name: Install dependencies |
| 71 | + working-directory: warehouse |
| 72 | + run: poetry install |
| 73 | + |
| 74 | + - name: Cache dbt packages |
| 75 | + uses: actions/cache@v3 |
| 76 | + with: |
| 77 | + path: warehouse/dbt_packages |
| 78 | + key: python-cache-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-lock-${{ hashFiles('warehouse/poetry.lock') }}-dbt-packages-${{ hashFiles('warehouse/packages.yml') }} |
| 79 | + |
| 80 | + - name: Install dbt dependencies |
| 81 | + working-directory: warehouse |
| 82 | + run: poetry run dbt deps |
| 83 | + |
| 84 | + - name: Print dbt environment |
| 85 | + working-directory: warehouse |
| 86 | + run: poetry run dbt debug --target ${{ env.DBT_TARGET }} |
| 87 | + |
| 88 | + - name: Download latest artifacts from GCS |
| 89 | + working-directory: warehouse |
| 90 | + run: | |
| 91 | + mkdir target |
| 92 | + gsutil cp -r gs://${{ env.DBT_ARTIFACTS_BUCKET }}/latest/ ./target/ |
| 93 | +
|
| 94 | + - name: Extract Metabase Exposures |
| 95 | + working-directory: warehouse |
| 96 | + run: | |
| 97 | + mkdir metabase |
| 98 | + poetry run dbt-metabase exposures -v --output-grouping="type" --output-path=metabase/ --manifest-path=target/manifest.json --metabase-url="https://dashboards.calitp.org" --metabase-api-key="${{ secrets.METABASE_API_KEY }}" |
| 99 | +
|
| 100 | + - name: Update exposure files |
| 101 | + uses: test-room-7/action-update-file@v1 |
| 102 | + with: |
| 103 | + file-path: warehouse/metabase/ |
| 104 | + commit-msg: Update Metabase Exposures |
| 105 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments