Skip to content
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Require review from the analytics data platform reviewers for all changes
* @oppia/analytics-data-platform-reviewers
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/02_new_feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body:
id: feature_name
attributes:
label: Feature Name & Ticket Link
placeholder: e.g., Auto-Renewal Checkout (Jira #PROD-1234)
placeholder: "e.g., New Learner Dashboard (ProdOps GitHub tracker #1234)"
validations:
required: true

Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/04_new_cuj.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ body:
id: cuj_name
attributes:
label: CUJ Name
placeholder: e.g., LO.1. Find a topic to learn
placeholder: e.g., LO.1. Find a topic to learn
validations:
required: true

Expand Down
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
target-branch: "develop"
schedule:
interval: "monthly"
reviewers:
- "oppia/analytics-data-platform-reviewers"
open-pull-requests-limit: 5

- package-ecosystem: "github-actions"
directory: "/"
target-branch: "develop"
schedule:
interval: "monthly"
reviewers:
- "oppia/analytics-data-platform-reviewers"
open-pull-requests-limit: 5
109 changes: 94 additions & 15 deletions .github/workflows/pr_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ name: Pull Request Data Validation

on:
pull_request:
branches: [ develop ]
branches: [develop]

permissions:
contents: read

jobs:
validate_sql:
static_checks:
name: Static Checks (Lint & dbt Parse)
runs-on: ubuntu-latest
steps:
- name: Checkout Code
Expand All @@ -15,42 +19,117 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-dev.txt

- name: Install Dependencies
run: |
pip install dbt-bigquery sqlfluff-templater-dbt
python -m pip install --upgrade pip
pip install -r requirements-dev.txt

- name: Lint YAML Files
run: yamllint --strict .

- name: Lint SQL Models
run: |
sqlfluff lint models/
if [ -d tests ]; then
sqlfluff lint tests/
fi

- name: Parse dbt Project Offline
run: |
cat << 'EOF' > profiles.yml
oppia_analytics:
target: dev
outputs:
dev:
type: bigquery
method: oauth
project: oppia-analytics-test
dataset: dev_github_actions
threads: 4
timeout_seconds: 300
location: US
EOF

- name: Authenticate to GCP Natively
dbt deps --profiles-dir .
dbt parse --profiles-dir .

bigquery_build:
name: BigQuery Build & Test
needs: static_checks
# Dependabot PRs cannot mint GitHub OIDC tokens, so skip BigQuery build for Dependabot
# (Static Checks still verifies installs, linting, and dbt parse). Fork PRs still enter
# this job and fail cleanly at the first step so unvalidated fork PRs cannot be merged.
if: github.actor != 'dependabot[bot]' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
concurrency:
# Serialize PR runs against the shared dev_github_actions dataset without canceling queued PRs
group: pr-bigquery-test
cancel-in-progress: false
steps:
- name: Check PR Source Branch
if: github.event.pull_request.head.repo.full_name != github.repository
run: |
# Write the secret JSON token safely as a raw literal string
cat << 'EOF' > ${HOME}/gcp_key.json
${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
cat << 'EOF' >> "$GITHUB_STEP_SUMMARY"
### BigQuery Build Blocked (Fork PR)

GitHub withholds cloud credentials from pull requests opened from forks, so **BigQuery Build & Test** cannot run here.

Please push your feature branch directly to `oppia/analytics-data-platform` and reopen the pull request from that branch (see `CONTRIBUTING.md`).
EOF
echo "::error::Pull requests from forks cannot run BigQuery CI. Push your branch directly to oppia/analytics-data-platform and reopen the PR from there (see CONTRIBUTING.md)."
exit 1

# Activate the service account using the pre-installed gcloud CLI
gcloud auth activate-service-account --key-file=${HOME}/gcp_key.json
- name: Checkout Code
uses: actions/checkout@v4

# Set the application default credentials environment variable for dbt
echo "GOOGLE_APPLICATION_CREDENTIALS=${HOME}/gcp_key.json" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: requirements.txt

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

# Authenticate via GCP Workload Identity Federation (no static JSON keys).
# Sets GOOGLE_APPLICATION_CREDENTIALS, which dbt's 'method: oauth' picks up via ADC.
- name: Authenticate to Google Cloud (WIF)
uses: google-github-actions/auth@v3
with:
project_id: oppia-analytics-test
workload_identity_provider: ${{ secrets.GCP_TEST_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_TEST_SERVICE_ACCOUNT }}

# Generate a local connection profile using service-account credentials
- name: Create dynamic profiles.yml for dbt
run: |
cat << EOF > profiles.yml
cat << 'EOF' > profiles.yml
oppia_analytics:
target: dev
outputs:
dev:
type: bigquery
method: service-account
keyfile: ${{ env.GOOGLE_APPLICATION_CREDENTIALS }}
method: oauth
project: oppia-analytics-test
dataset: dev_github_actions
threads: 4
timeout_seconds: 300
location: US
EOF

- name: Verify dbt Connection
run: dbt debug --profiles-dir .

- name: Install dbt Packages (if any)
run: dbt deps --profiles-dir .

Expand Down
52 changes: 24 additions & 28 deletions .github/workflows/weekly_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,77 @@ name: Weekly Production Analytics Run
#
# Environment Target: Production (oppia-analytics-prod)
# Key Operations:
# 1. Authenticates to GCP using an automated service account.
# 2. Dynamically isolates database credentials to prevent local Git leaks.
# 1. Authenticates to GCP via Workload Identity Federation (short-lived OIDC).
# 2. Dynamically generates a BigQuery profile using ADC (method: oauth).
# 3. Runs data quality assertions and transforms fresh production analytics logs.
# ==============================================================================

on:
schedule:
# Runs at 00:00 UTC every Sunday (Adjust cron expression for your preferred timezone)
# Runs at 00:00 UTC every Sunday
- cron: '0 0 * * 0'
workflow_dispatch:
# Allows the analytics team to trigger a one-off run manually from the GitHub UI

concurrency:
group: weekly-production-run
cancel-in-progress: false

jobs:
dbt_run:
name: Execute dbt Production Pipeline
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write

steps:
# Clone the repository codebase onto the temporary GitHub virtual runner
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
# Use caching to decrease run times for subsequent runs
cache: 'pip'
cache-dependency-path: requirements.txt

- name: Install dbt and BigQuery Dependencies
run: |
pip install --upgrade pip
pip install dbt-bigquery

# Exchange GitHub secret tokens for active, authenticated Google Cloud sessions
- name: Authenticate to GCP Natively
run: |
# Write the secret JSON token safely as a raw literal string
cat << 'EOF' > ${HOME}/gcp_key.json
${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
EOF

# Activate the service account using the pre-installed gcloud CLI
gcloud auth activate-service-account --key-file=${HOME}/gcp_key.json
python -m pip install --upgrade pip
pip install -r requirements.txt

# Set the application default credentials environment variable for dbt
echo "GOOGLE_APPLICATION_CREDENTIALS=${HOME}/gcp_key.json" >> $GITHUB_ENV
# Authenticate via GCP Workload Identity Federation (scoped in GCP IAM to refs/heads/develop).
# Sets GOOGLE_APPLICATION_CREDENTIALS, which dbt's 'method: oauth' picks up via ADC.
- name: Authenticate to Google Cloud (WIF)
uses: google-github-actions/auth@v3
with:
project_id: oppia-analytics-prod
workload_identity_provider: ${{ secrets.GCP_PROD_WIF_PROVIDER }}
service_account: ${{ secrets.GCP_PROD_SERVICE_ACCOUNT }}

# Generate a production connection profile using service-account credentials
- name: Create dynamic profiles.yml for dbt
run: |
cat << EOF > profiles.yml
cat << 'EOF' > profiles.yml
oppia_analytics:
target: prod
outputs:
prod:
type: bigquery
method: service-account
keyfile: ${{ env.GOOGLE_APPLICATION_CREDENTIALS }}
method: oauth
project: oppia-analytics-prod
dataset: analytics_production
threads: 4
timeout_seconds: 300
location: US
EOF

# Validate infrastructure paths and check that BigQuery is responding
- name: Verify dbt Connection
run: dbt debug --profiles-dir .
run: dbt debug --target prod --profiles-dir .

# Pull down any third-party open-source dbt packages listed in packages.yml
- name: Install dbt Packages (if any)
run: dbt deps --profiles-dir .

# Perform a comprehensive build (Compile, Model materialization, and Data testing)
- name: Execute and Test Pipeline
# 'dbt build' compiles, runs, and tests every staging, dim, fct, and agg table sequentially.
# If an upstream table fails a test, downstream tables are skipped to preserve data integrity.
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ profiles.yml
# Service account keys (Safety net to prevent credential leaks)
*.json
*.pem

# Python virtual environments
.venv/
venv/
47 changes: 47 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[sqlfluff]
dialect = bigquery
templater = jinja
max_line_length = 120
# Exclude rules that conflict with common dbt + BigQuery/GA4 idioms:
# AM04: SELECT * in upstream source CTEs
# AM09: LIMIT 1 without ORDER BY in GA4 UNNEST(event_params) lookups
# AL09: Explicit aliases when flattening BigQuery STRUCT fields (e.g., geo.country AS country)
# LT14: Single-line inline UNNEST scalar subqueries
# ST05: Inline scalar subqueries (GA4 UNNEST pattern)
# ST06: Logical column ordering over strict simple-before-calculated ordering
exclude_rules = AM04, AM09, AL09, LT14, ST05, ST06

[sqlfluff:indentation]
indent_unit = space
tab_space_size = 4

[sqlfluff:templater:jinja]
apply_dbt_builtins = True
load_macros_from_path = macros/

[sqlfluff:templater:jinja:macros]
# Backtick-quote source identifiers (matching dbt-bigquery) so GA4 wildcard tables (events_*) parse cleanly
dbt_source = {% macro source(source_name, table_name) %}`{{ source_name }}`.`{{ table_name }}`{% endmacro %}

[sqlfluff:layout:type:comma]
line_position = trailing

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower
# BigQuery pseudo-columns (_TABLE_SUFFIX, _PARTITIONDATE, _PARTITIONTIME) are conventionally uppercase
ignore_words = _TABLE_SUFFIX, _PARTITIONDATE, _PARTITIONTIME

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper

[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = upper

[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = upper

[sqlfluff:rules:capitalisation.types]
extended_capitalisation_policy = upper

[sqlfluff:rules:layout.long_lines]
ignore_comment_lines = True
5 changes: 5 additions & 0 deletions .sqlfluffignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target/
dbt_packages/
dbt_modules/
logs/
macros/
22 changes: 22 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extends: default

ignore: |
target/
dbt_packages/
dbt_modules/
logs/
.venv/
venv/

rules:
document-start: disable
line-length: disable
truthy:
# GitHub Actions workflows use top-level 'on:' keys
check-keys: false
comments:
min-spaces-from-content: 1
comments-indentation: disable
indentation:
spaces: 2
indent-sequences: whatever
Loading
Loading